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 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/mdt/mdt_handler.c
41 * Lustre Metadata Target (mdt) request handler
43 * Author: Peter Braam <braam@clusterfs.com>
44 * Author: Andreas Dilger <adilger@clusterfs.com>
45 * Author: Phil Schwan <phil@clusterfs.com>
46 * Author: Mike Shaver <shaver@clusterfs.com>
47 * Author: Nikita Danilov <nikita@clusterfs.com>
48 * Author: Huang Hua <huanghua@clusterfs.com>
49 * Author: Yury Umanets <umka@clusterfs.com>
53 # define EXPORT_SYMTAB
55 #define DEBUG_SUBSYSTEM S_MDS
57 #include <linux/module.h>
59 * struct OBD_{ALLOC,FREE}*()
61 #include <obd_support.h>
62 /* struct ptlrpc_request */
63 #include <lustre_net.h>
64 /* struct obd_export */
65 #include <lustre_export.h>
66 /* struct obd_device */
69 #include <dt_object.h>
70 #include <lustre_mds.h>
71 #include <lustre_mdt.h>
72 #include "mdt_internal.h"
73 #ifdef HAVE_QUOTA_SUPPORT
74 # include <lustre_quota.h>
76 #include <lustre_acl.h>
77 #include <lustre_param.h>
78 #include <lustre_fsfilt.h>
80 mdl_mode_t mdt_mdl_lock_modes[] = {
81 [LCK_MINMODE] = MDL_MINMODE,
88 [LCK_GROUP] = MDL_GROUP
91 ldlm_mode_t mdt_dlm_lock_modes[] = {
92 [MDL_MINMODE] = LCK_MINMODE,
99 [MDL_GROUP] = LCK_GROUP
103 * Initialized in mdt_mod_init().
105 static unsigned long mdt_num_threads;
106 static unsigned long mdt_min_threads;
107 static unsigned long mdt_max_threads;
109 /* ptlrpc request handler for MDT. All handlers are
110 * grouped into several slices - struct mdt_opc_slice,
111 * and stored in an array - mdt_handlers[].
114 /* The name of this handler. */
116 /* Fail id for this handler, checked at the beginning of this handler*/
118 /* Operation code for this handler */
120 /* flags are listed in enum mdt_handler_flags below. */
122 /* The actual handler function to execute. */
123 int (*mh_act)(struct mdt_thread_info *info);
124 /* Request format for this request. */
125 const struct req_format *mh_fmt;
128 enum mdt_handler_flags {
130 * struct mdt_body is passed in the incoming message, and object
131 * identified by this fid exists on disk.
133 * "habeo corpus" == "I have a body"
135 HABEO_CORPUS = (1 << 0),
137 * struct ldlm_request is passed in the incoming message.
139 * "habeo clavis" == "I have a key"
141 HABEO_CLAVIS = (1 << 1),
143 * this request has fixed reply format, so that reply message can be
144 * packed by generic code.
146 * "habeo refero" == "I have a reply"
148 HABEO_REFERO = (1 << 2),
150 * this request will modify something, so check whether the filesystem
151 * is readonly or not, then return -EROFS to client asap if necessary.
153 * "mutabor" == "I shall modify"
158 struct mdt_opc_slice {
161 struct mdt_handler *mos_hs;
164 static struct mdt_opc_slice mdt_regular_handlers[];
165 static struct mdt_opc_slice mdt_readpage_handlers[];
166 static struct mdt_opc_slice mdt_xmds_handlers[];
167 static struct mdt_opc_slice mdt_seq_handlers[];
168 static struct mdt_opc_slice mdt_fld_handlers[];
170 static struct mdt_device *mdt_dev(struct lu_device *d);
171 static int mdt_regular_handle(struct ptlrpc_request *req);
172 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
173 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
174 struct getinfo_fid2path *fp);
176 static const struct lu_object_operations mdt_obj_ops;
178 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
182 return (rep->lock_policy_res1 & flag);
185 void mdt_clear_disposition(struct mdt_thread_info *info,
186 struct ldlm_reply *rep, int flag)
189 info->mti_opdata &= ~flag;
191 rep->lock_policy_res1 &= ~flag;
194 void mdt_set_disposition(struct mdt_thread_info *info,
195 struct ldlm_reply *rep, int flag)
198 info->mti_opdata |= flag;
200 rep->lock_policy_res1 |= flag;
203 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
205 lh->mlh_pdo_hash = 0;
206 lh->mlh_reg_mode = lm;
207 lh->mlh_type = MDT_REG_LOCK;
210 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
211 const char *name, int namelen)
213 lh->mlh_reg_mode = lm;
214 lh->mlh_type = MDT_PDO_LOCK;
216 if (name != NULL && (name[0] != '\0')) {
217 LASSERT(namelen > 0);
218 lh->mlh_pdo_hash = full_name_hash(name, namelen);
220 LASSERT(namelen == 0);
221 lh->mlh_pdo_hash = 0ull;
225 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
226 struct mdt_lock_handle *lh)
232 * Any dir access needs couple of locks:
234 * 1) on part of dir we gonna take lookup/modify;
236 * 2) on whole dir to protect it from concurrent splitting and/or to
237 * flush client's cache for readdir().
239 * so, for a given mode and object this routine decides what lock mode
240 * to use for lock #2:
242 * 1) if caller's gonna lookup in dir then we need to protect dir from
243 * being splitted only - LCK_CR
245 * 2) if caller's gonna modify dir then we need to protect dir from
246 * being splitted and to flush cache - LCK_CW
248 * 3) if caller's gonna modify dir and that dir seems ready for
249 * splitting then we need to protect it from any type of access
250 * (lookup/modify/split) - LCK_EX --bzzz
253 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
254 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
257 * Ask underlaying level its opinion about preferable PDO lock mode
258 * having access type passed as regular lock mode:
260 * - MDL_MINMODE means that lower layer does not want to specify lock
263 * - MDL_NL means that no PDO lock should be taken. This is used in some
264 * cases. Say, for non-splittable directories no need to use PDO locks
267 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
268 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
270 if (mode != MDL_MINMODE) {
271 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
274 * Lower layer does not want to specify locking mode. We do it
275 * our selves. No special protection is needed, just flush
276 * client's cache on modification and allow concurrent
279 switch (lh->mlh_reg_mode) {
281 lh->mlh_pdo_mode = LCK_EX;
284 lh->mlh_pdo_mode = LCK_CR;
287 lh->mlh_pdo_mode = LCK_CW;
290 CERROR("Not expected lock type (0x%x)\n",
291 (int)lh->mlh_reg_mode);
296 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
300 static int mdt_getstatus(struct mdt_thread_info *info)
302 struct mdt_device *mdt = info->mti_mdt;
303 struct md_device *next = mdt->mdt_child;
304 struct mdt_body *repbody;
309 rc = mdt_check_ucred(info);
311 RETURN(err_serious(rc));
313 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
314 RETURN(err_serious(-ENOMEM));
316 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
317 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
321 repbody->valid |= OBD_MD_FLID;
323 if (mdt->mdt_opts.mo_mds_capa &&
324 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
325 struct mdt_object *root;
326 struct lustre_capa *capa;
328 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
330 RETURN(PTR_ERR(root));
332 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
334 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
335 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
337 mdt_object_put(info->mti_env, root);
339 repbody->valid |= OBD_MD_FLMDSCAPA;
345 static int mdt_statfs(struct mdt_thread_info *info)
347 struct ptlrpc_request *req = mdt_info_req(info);
348 struct md_device *next = info->mti_mdt->mdt_child;
349 struct ptlrpc_service *svc;
350 struct obd_statfs *osfs;
355 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
357 /* This will trigger a watchdog timeout */
358 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
359 (MDT_SERVICE_WATCHDOG_FACTOR *
360 at_get(&svc->srv_at_estimate)) + 1);
362 rc = mdt_check_ucred(info);
364 RETURN(err_serious(rc));
366 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
367 rc = err_serious(-ENOMEM);
369 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
370 rc = next->md_ops->mdo_statfs(info->mti_env, next,
372 statfs_pack(osfs, &info->mti_u.ksfs);
376 mdt_counter_incr(req->rq_export, LPROC_MDT_STATFS);
382 * Pack SOM attributes into the reply.
383 * Call under a DLM UPDATE lock.
385 static void mdt_pack_size2body(struct mdt_thread_info *info,
386 struct mdt_object *mo)
389 struct md_attr *ma = &info->mti_attr;
391 LASSERT(ma->ma_attr.la_valid & LA_MODE);
392 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
394 /* Check if Size-on-MDS is supported, if this is a regular file,
395 * if SOM is enabled on the object and if SOM cache exists and valid.
396 * Otherwise do not pack Size-on-MDS attributes to the reply. */
397 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
398 !S_ISREG(ma->ma_attr.la_mode) ||
399 !mdt_object_is_som_enabled(mo) ||
400 !(ma->ma_valid & MA_SOM))
403 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
404 b->size = ma->ma_som->msd_size;
405 b->blocks = ma->ma_som->msd_blocks;
408 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
409 const struct lu_attr *attr, const struct lu_fid *fid)
411 struct md_attr *ma = &info->mti_attr;
413 LASSERT(ma->ma_valid & MA_INODE);
415 b->atime = attr->la_atime;
416 b->mtime = attr->la_mtime;
417 b->ctime = attr->la_ctime;
418 b->mode = attr->la_mode;
419 b->size = attr->la_size;
420 b->blocks = attr->la_blocks;
421 b->uid = attr->la_uid;
422 b->gid = attr->la_gid;
423 b->flags = attr->la_flags;
424 b->nlink = attr->la_nlink;
425 b->rdev = attr->la_rdev;
427 /*XXX should pack the reply body according to lu_valid*/
428 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
429 OBD_MD_FLGID | OBD_MD_FLTYPE |
430 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
431 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
433 if (!S_ISREG(attr->la_mode)) {
434 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
435 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
436 /* means no objects are allocated on osts. */
437 LASSERT(!(ma->ma_valid & MA_LOV));
438 /* just ignore blocks occupied by extend attributes on MDS */
440 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
441 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
446 b->valid |= OBD_MD_FLID;
448 /* FIXME: these should be fixed when new igif ready.*/
449 b->ino = fid_oid(fid); /* 1.6 compatibility */
450 b->generation = fid_ver(fid); /* 1.6 compatibility */
451 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
453 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
454 PFID(fid), b->nlink, b->mode, b->size);
458 mdt_body_reverse_idmap(info, b);
460 if (b->valid & OBD_MD_FLSIZE)
461 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
462 PFID(fid), (unsigned long long)b->size);
465 static inline int mdt_body_has_lov(const struct lu_attr *la,
466 const struct mdt_body *body)
468 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
469 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
472 void mdt_client_compatibility(struct mdt_thread_info *info)
474 struct mdt_body *body;
475 struct ptlrpc_request *req = mdt_info_req(info);
476 struct obd_export *exp = req->rq_export;
477 struct md_attr *ma = &info->mti_attr;
478 struct lu_attr *la = &ma->ma_attr;
481 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
482 /* the client can deal with 16-bit lmm_stripe_count */
485 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
487 if (!mdt_body_has_lov(la, body))
490 /* now we have a reply with a lov for a client not compatible with the
491 * layout lock so we have to clean the layout generation number */
492 if (S_ISREG(la->la_mode))
493 ma->ma_lmm->lmm_layout_gen = 0;
498 static int mdt_getattr_internal(struct mdt_thread_info *info,
499 struct mdt_object *o, int ma_need)
501 struct md_object *next = mdt_object_child(o);
502 const struct mdt_body *reqbody = info->mti_body;
503 struct ptlrpc_request *req = mdt_info_req(info);
504 struct md_attr *ma = &info->mti_attr;
505 struct lu_attr *la = &ma->ma_attr;
506 struct req_capsule *pill = info->mti_pill;
507 const struct lu_env *env = info->mti_env;
508 struct mdt_body *repbody;
509 struct lu_buf *buffer = &info->mti_buf;
513 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
514 RETURN(err_serious(-ENOMEM));
516 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
520 rc = mdt_object_exists(o);
522 /* This object is located on remote node.*/
523 repbody->fid1 = *mdt_object_fid(o);
524 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
528 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
529 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
531 /* If it is dir object and client require MEA, then we got MEA */
532 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
533 reqbody->valid & OBD_MD_MEA) {
534 /* Assumption: MDT_MD size is enough for lmv size. */
535 ma->ma_lmv = buffer->lb_buf;
536 ma->ma_lmv_size = buffer->lb_len;
537 ma->ma_need = MA_LMV | MA_INODE;
539 ma->ma_lmm = buffer->lb_buf;
540 ma->ma_lmm_size = buffer->lb_len;
541 ma->ma_need = MA_LOV | MA_INODE;
544 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
545 reqbody->valid & OBD_MD_FLDIREA &&
546 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
547 /* get default stripe info for this dir. */
548 ma->ma_need |= MA_LOV_DEF;
550 ma->ma_need |= ma_need;
551 if (ma->ma_need & MA_SOM)
552 ma->ma_som = &info->mti_u.som.data;
554 rc = mo_attr_get(env, next, ma);
556 CERROR("getattr error for "DFID": %d\n",
557 PFID(mdt_object_fid(o)), rc);
561 if (likely(ma->ma_valid & MA_INODE))
562 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
566 if (mdt_body_has_lov(la, reqbody)) {
567 if (ma->ma_valid & MA_LOV) {
568 LASSERT(ma->ma_lmm_size);
569 mdt_dump_lmm(D_INFO, ma->ma_lmm);
570 repbody->eadatasize = ma->ma_lmm_size;
571 if (S_ISDIR(la->la_mode))
572 repbody->valid |= OBD_MD_FLDIREA;
574 repbody->valid |= OBD_MD_FLEASIZE;
576 if (ma->ma_valid & MA_LMV) {
577 LASSERT(S_ISDIR(la->la_mode));
578 repbody->eadatasize = ma->ma_lmv_size;
579 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
581 } else if (S_ISLNK(la->la_mode) &&
582 reqbody->valid & OBD_MD_LINKNAME) {
583 buffer->lb_buf = ma->ma_lmm;
584 buffer->lb_len = reqbody->eadatasize;
585 rc = mo_readlink(env, next, buffer);
586 if (unlikely(rc <= 0)) {
587 CERROR("readlink failed: %d\n", rc);
590 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
592 repbody->valid |= OBD_MD_LINKNAME;
593 repbody->eadatasize = rc;
595 ((char*)ma->ma_lmm)[rc - 1] = 0;
596 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
597 (char*)ma->ma_lmm, rc);
602 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
603 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
604 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
605 repbody->valid |= OBD_MD_FLMODEASIZE;
606 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
607 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
608 repbody->max_cookiesize);
611 if (exp_connect_rmtclient(info->mti_exp) &&
612 reqbody->valid & OBD_MD_FLRMTPERM) {
613 void *buf = req_capsule_server_get(pill, &RMF_ACL);
615 /* mdt_getattr_lock only */
616 rc = mdt_pack_remote_perm(info, o, buf);
618 repbody->valid &= ~OBD_MD_FLRMTPERM;
619 repbody->aclsize = 0;
622 repbody->valid |= OBD_MD_FLRMTPERM;
623 repbody->aclsize = sizeof(struct mdt_remote_perm);
626 #ifdef CONFIG_FS_POSIX_ACL
627 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
628 (reqbody->valid & OBD_MD_FLACL)) {
629 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
630 buffer->lb_len = req_capsule_get_size(pill,
631 &RMF_ACL, RCL_SERVER);
632 if (buffer->lb_len > 0) {
633 rc = mo_xattr_get(env, next, buffer,
634 XATTR_NAME_ACL_ACCESS);
636 if (rc == -ENODATA) {
637 repbody->aclsize = 0;
638 repbody->valid |= OBD_MD_FLACL;
640 } else if (rc == -EOPNOTSUPP) {
643 CERROR("got acl size: %d\n", rc);
646 repbody->aclsize = rc;
647 repbody->valid |= OBD_MD_FLACL;
654 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
655 info->mti_mdt->mdt_opts.mo_mds_capa &&
656 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
657 struct lustre_capa *capa;
659 capa = req_capsule_server_get(pill, &RMF_CAPA1);
661 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
662 rc = mo_capa_get(env, next, capa, 0);
665 repbody->valid |= OBD_MD_FLMDSCAPA;
670 static int mdt_renew_capa(struct mdt_thread_info *info)
672 struct mdt_object *obj = info->mti_object;
673 struct mdt_body *body;
674 struct lustre_capa *capa, *c;
678 /* if object doesn't exist, or server has disabled capability,
679 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
682 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
683 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
686 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
687 LASSERT(body != NULL);
689 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
692 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
696 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
698 body->valid |= OBD_MD_FLOSSCAPA;
702 static int mdt_getattr(struct mdt_thread_info *info)
704 struct ptlrpc_request *req = mdt_info_req(info);
705 struct mdt_object *obj = info->mti_object;
706 struct req_capsule *pill = info->mti_pill;
707 struct mdt_body *reqbody;
708 struct mdt_body *repbody;
714 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
717 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
718 rc = req_capsule_server_pack(pill);
720 RETURN(err_serious(rc));
721 rc = mdt_renew_capa(info);
722 GOTO(out_shrink, rc);
725 LASSERT(obj != NULL);
726 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
728 mode = lu_object_attr(&obj->mot_obj.mo_lu);
729 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
730 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
731 md_size = reqbody->eadatasize;
733 md_size = info->mti_mdt->mdt_max_mdsize;
735 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
737 rc = req_capsule_server_pack(pill);
738 if (unlikely(rc != 0))
739 RETURN(err_serious(rc));
741 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
742 LASSERT(repbody != NULL);
743 repbody->eadatasize = 0;
744 repbody->aclsize = 0;
746 if (reqbody->valid & OBD_MD_FLRMTPERM)
747 rc = mdt_init_ucred(info, reqbody);
749 rc = mdt_check_ucred(info);
751 GOTO(out_shrink, rc);
753 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
754 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
757 * Don't check capability at all, because rename might getattr for
758 * remote obj, and at that time no capability is available.
760 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
761 rc = mdt_getattr_internal(info, obj, 0);
762 if (reqbody->valid & OBD_MD_FLRMTPERM)
763 mdt_exit_ucred(info);
767 mdt_counter_incr(req->rq_export, LPROC_MDT_GETATTR);
769 mdt_client_compatibility(info);
770 mdt_shrink_reply(info);
774 static int mdt_is_subdir(struct mdt_thread_info *info)
776 struct mdt_object *o = info->mti_object;
777 struct req_capsule *pill = info->mti_pill;
778 const struct mdt_body *body = info->mti_body;
779 struct mdt_body *repbody;
785 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
788 * We save last checked parent fid to @repbody->fid1 for remote
791 LASSERT(fid_is_sane(&body->fid2));
792 LASSERT(mdt_object_exists(o) > 0);
793 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
794 &body->fid2, &repbody->fid1);
795 if (rc == 0 || rc == -EREMOTE)
796 repbody->valid |= OBD_MD_FLID;
801 static int mdt_raw_lookup(struct mdt_thread_info *info,
802 struct mdt_object *parent,
803 const struct lu_name *lname,
804 struct ldlm_reply *ldlm_rep)
806 struct md_object *next = mdt_object_child(info->mti_object);
807 const struct mdt_body *reqbody = info->mti_body;
808 struct lu_fid *child_fid = &info->mti_tmp_fid1;
809 struct mdt_body *repbody;
813 if (reqbody->valid != OBD_MD_FLID)
816 LASSERT(!info->mti_cross_ref);
818 /* Only got the fid of this obj by name */
819 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
822 /* XXX is raw_lookup possible as intent operation? */
825 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
828 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
830 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
833 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
834 repbody->fid1 = *child_fid;
835 repbody->valid = OBD_MD_FLID;
841 * UPDATE lock should be taken against parent, and be release before exit;
842 * child_bits lock should be taken against child, and be returned back:
843 * (1)normal request should release the child lock;
844 * (2)intent request will grant the lock to client.
846 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
847 struct mdt_lock_handle *lhc,
849 struct ldlm_reply *ldlm_rep)
851 struct ptlrpc_request *req = mdt_info_req(info);
852 struct mdt_body *reqbody = NULL;
853 struct mdt_object *parent = info->mti_object;
854 struct mdt_object *child;
855 struct md_object *next = mdt_object_child(parent);
856 struct lu_fid *child_fid = &info->mti_tmp_fid1;
857 struct lu_name *lname = NULL;
858 const char *name = NULL;
860 struct mdt_lock_handle *lhp = NULL;
861 struct ldlm_lock *lock;
862 struct ldlm_res_id *res_id;
869 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
870 LASSERT(ergo(is_resent,
871 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
873 LASSERT(parent != NULL);
874 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
876 RETURN(err_serious(-EFAULT));
878 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
880 if (!info->mti_cross_ref) {
882 * XXX: Check for "namelen == 0" is for getattr by fid
883 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
884 * that is the name must contain at least one character and
885 * the terminating '\0'
888 reqbody = req_capsule_client_get(info->mti_pill,
890 if (unlikely(reqbody == NULL))
891 RETURN(err_serious(-EFAULT));
893 if (unlikely(!fid_is_sane(&reqbody->fid2)))
894 RETURN(err_serious(-EINVAL));
897 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
899 PFID(mdt_object_fid(parent)),
900 PFID(&reqbody->fid2), ldlm_rep);
902 lname = mdt_name(info->mti_env, (char *)name, namelen);
903 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
904 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
908 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
910 rc = mdt_object_exists(parent);
911 if (unlikely(rc == 0)) {
912 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
913 &parent->mot_obj.mo_lu,
914 "Parent doesn't exist!\n");
916 } else if (!info->mti_cross_ref) {
917 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
918 PFID(mdt_object_fid(parent)));
921 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
929 if (info->mti_cross_ref) {
930 /* Only getattr on the child. Parent is on another node. */
931 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
933 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
934 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
937 /* Do not take lock for resent case. */
938 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
939 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
940 lhc->mlh_reg_lh.cookie);
941 LASSERT(fid_res_name_eq(mdt_object_fid(child),
942 &lock->l_resource->lr_name));
946 mdt_lock_handle_init(lhc);
947 mdt_lock_reg_init(lhc, LCK_PR);
950 * Object's name is on another MDS, no lookup lock is
951 * needed here but update is.
953 child_bits &= ~MDS_INODELOCK_LOOKUP;
954 child_bits |= MDS_INODELOCK_UPDATE;
956 rc = mdt_object_lock(info, child, lhc, child_bits,
960 /* Finally, we can get attr for child. */
961 mdt_set_capainfo(info, 0, mdt_object_fid(child),
963 rc = mdt_getattr_internal(info, child, 0);
964 if (unlikely(rc != 0))
965 mdt_object_unlock(info, child, lhc, 1);
971 /* step 1: lock parent only if parent is a directory */
972 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
973 lhp = &info->mti_lh[MDT_LH_PARENT];
974 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
975 rc = mdt_object_lock(info, parent, lhp,
976 MDS_INODELOCK_UPDATE,
978 if (unlikely(rc != 0))
982 /* step 2: lookup child's fid by name */
983 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
988 mdt_set_disposition(info, ldlm_rep,
990 GOTO(out_parent, rc);
992 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
994 *child_fid = reqbody->fid2;
995 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
999 *step 3: find the child object by fid & lock it.
1000 * regardless if it is local or remote.
1002 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1004 if (unlikely(IS_ERR(child)))
1005 GOTO(out_parent, rc = PTR_ERR(child));
1007 /* Do not take lock for resent case. */
1008 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1009 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1010 lhc->mlh_reg_lh.cookie);
1012 res_id = &lock->l_resource->lr_name;
1013 if (!fid_res_name_eq(mdt_object_fid(child),
1014 &lock->l_resource->lr_name)) {
1015 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1016 &lock->l_resource->lr_name),
1017 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1018 (unsigned long)res_id->name[0],
1019 (unsigned long)res_id->name[1],
1020 (unsigned long)res_id->name[2],
1021 PFID(mdt_object_fid(parent)));
1022 CWARN("Although resent, but still not get child lock"
1023 "parent:"DFID" child:"DFID"\n",
1024 PFID(mdt_object_fid(parent)),
1025 PFID(mdt_object_fid(child)));
1026 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1027 LDLM_LOCK_PUT(lock);
1030 LDLM_LOCK_PUT(lock);
1034 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1035 mdt_lock_handle_init(lhc);
1036 if (child_bits == MDS_INODELOCK_LAYOUT)
1037 mdt_lock_reg_init(lhc, LCK_CR);
1039 mdt_lock_reg_init(lhc, LCK_PR);
1041 if (mdt_object_exists(child) == 0) {
1042 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1043 &child->mot_obj.mo_lu,
1044 "Object doesn't exist!\n");
1045 GOTO(out_child, rc = -ENOENT);
1048 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1049 struct md_attr *ma = &info->mti_attr;
1052 ma->ma_need = MA_INODE;
1053 rc = mo_attr_get(info->mti_env,
1054 mdt_object_child(child), ma);
1055 if (unlikely(rc != 0))
1056 GOTO(out_child, rc);
1058 /* layout lock is used only on regular files */
1059 if ((ma->ma_valid & MA_INODE) &&
1060 (ma->ma_attr.la_valid & LA_MODE) &&
1061 !S_ISREG(ma->ma_attr.la_mode))
1062 child_bits &= ~MDS_INODELOCK_LAYOUT;
1064 /* If the file has not been changed for some time, we
1065 * return not only a LOOKUP lock, but also an UPDATE
1066 * lock and this might save us RPC on later STAT. For
1067 * directories, it also let negative dentry starts
1068 * working for this dir. */
1069 if (ma->ma_valid & MA_INODE &&
1070 ma->ma_attr.la_valid & LA_CTIME &&
1071 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1072 ma->ma_attr.la_ctime < cfs_time_current_sec())
1073 child_bits |= MDS_INODELOCK_UPDATE;
1076 rc = mdt_object_lock(info, child, lhc, child_bits,
1079 if (unlikely(rc != 0))
1080 GOTO(out_child, rc);
1083 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1084 /* Get MA_SOM attributes if update lock is given. */
1086 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1087 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1090 /* finally, we can get attr for child. */
1091 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1092 rc = mdt_getattr_internal(info, child, ma_need);
1093 if (unlikely(rc != 0)) {
1094 mdt_object_unlock(info, child, lhc, 1);
1096 /* Debugging code. */
1097 res_id = &lock->l_resource->lr_name;
1098 LDLM_DEBUG(lock, "Returning lock to client");
1099 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1100 &lock->l_resource->lr_name),
1101 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1102 (unsigned long)res_id->name[0],
1103 (unsigned long)res_id->name[1],
1104 (unsigned long)res_id->name[2],
1105 PFID(mdt_object_fid(child)));
1106 mdt_pack_size2body(info, child);
1109 LDLM_LOCK_PUT(lock);
1113 mdt_object_put(info->mti_env, child);
1116 mdt_object_unlock(info, parent, lhp, 1);
1120 /* normal handler: should release the child lock */
1121 static int mdt_getattr_name(struct mdt_thread_info *info)
1123 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1124 struct mdt_body *reqbody;
1125 struct mdt_body *repbody;
1129 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1130 LASSERT(reqbody != NULL);
1131 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1132 LASSERT(repbody != NULL);
1134 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1135 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1136 repbody->eadatasize = 0;
1137 repbody->aclsize = 0;
1139 rc = mdt_init_ucred(info, reqbody);
1141 GOTO(out_shrink, rc);
1143 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1144 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1145 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1146 lhc->mlh_reg_lh.cookie = 0;
1148 mdt_exit_ucred(info);
1151 mdt_client_compatibility(info);
1152 mdt_shrink_reply(info);
1156 static const struct lu_device_operations mdt_lu_ops;
1158 static int lu_device_is_mdt(struct lu_device *d)
1160 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1163 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1164 void *karg, void *uarg);
1166 static int mdt_set_info(struct mdt_thread_info *info)
1168 struct ptlrpc_request *req = mdt_info_req(info);
1171 int keylen, vallen, rc = 0;
1174 rc = req_capsule_server_pack(info->mti_pill);
1178 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1180 DEBUG_REQ(D_HA, req, "no set_info key");
1184 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1187 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1189 DEBUG_REQ(D_HA, req, "no set_info val");
1193 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1196 /* Swab any part of val you need to here */
1197 if (KEY_IS(KEY_READ_ONLY)) {
1199 lustre_msg_set_status(req->rq_repmsg, 0);
1201 cfs_spin_lock(&req->rq_export->exp_lock);
1203 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1205 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1206 cfs_spin_unlock(&req->rq_export->exp_lock);
1208 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1209 struct changelog_setinfo *cs =
1210 (struct changelog_setinfo *)val;
1211 if (vallen != sizeof(*cs)) {
1212 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1215 if (ptlrpc_req_need_swab(req)) {
1216 __swab64s(&cs->cs_recno);
1217 __swab32s(&cs->cs_id);
1220 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1222 lustre_msg_set_status(req->rq_repmsg, rc);
1230 static int mdt_connect(struct mdt_thread_info *info)
1233 struct ptlrpc_request *req;
1235 req = mdt_info_req(info);
1236 rc = target_handle_connect(req);
1238 LASSERT(req->rq_export != NULL);
1239 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1240 rc = mdt_init_sec_level(info);
1242 rc = mdt_init_idmap(info);
1244 obd_disconnect(class_export_get(req->rq_export));
1246 rc = err_serious(rc);
1251 static int mdt_disconnect(struct mdt_thread_info *info)
1256 rc = target_handle_disconnect(mdt_info_req(info));
1258 rc = err_serious(rc);
1262 static int mdt_sendpage(struct mdt_thread_info *info,
1263 struct lu_rdpg *rdpg, int nob)
1265 struct ptlrpc_request *req = mdt_info_req(info);
1266 struct obd_export *exp = req->rq_export;
1267 struct ptlrpc_bulk_desc *desc;
1268 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1275 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1280 for (i = 0, tmpcount = nob;
1281 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1282 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1283 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1286 LASSERT(desc->bd_nob == nob);
1287 rc = target_bulk_io(exp, desc, lwi);
1288 ptlrpc_free_bulk(desc);
1292 #ifdef HAVE_SPLIT_SUPPORT
1294 * Retrieve dir entry from the page and insert it to the slave object, actually,
1295 * this should be in osd layer, but since it will not in the final product, so
1296 * just do it here and do not define more moo api anymore for this.
1298 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1301 struct mdt_object *object = info->mti_object;
1302 struct lu_fid *lf = &info->mti_tmp_fid2;
1303 struct md_attr *ma = &info->mti_attr;
1304 struct lu_dirpage *dp;
1305 struct lu_dirent *ent;
1306 int rc = 0, offset = 0;
1309 /* Make sure we have at least one entry. */
1314 * Disable trans for this name insert, since it will include many trans
1317 info->mti_no_need_trans = 1;
1319 * When write_dir_page, no need update parent's ctime,
1320 * and no permission check for name_insert.
1322 ma->ma_attr.la_ctime = 0;
1323 ma->ma_attr.la_valid = LA_MODE;
1324 ma->ma_valid = MA_INODE;
1327 dp = page_address(page);
1328 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1330 for (ent = lu_dirent_start(dp); ent != NULL;
1331 ent = lu_dirent_next(ent)) {
1332 struct lu_name *lname;
1335 if (le16_to_cpu(ent->lde_namelen) == 0)
1338 fid_le_to_cpu(lf, &ent->lde_fid);
1339 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1340 ma->ma_attr.la_mode = S_IFDIR;
1342 ma->ma_attr.la_mode = 0;
1343 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1345 GOTO(out, rc = -ENOMEM);
1347 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1348 lname = mdt_name(info->mti_env, name,
1349 le16_to_cpu(ent->lde_namelen));
1350 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1351 rc = mdo_name_insert(info->mti_env,
1352 md_object_next(&object->mot_obj),
1354 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1356 CERROR("Can't insert %*.*s, rc %d\n",
1357 le16_to_cpu(ent->lde_namelen),
1358 le16_to_cpu(ent->lde_namelen),
1363 offset += lu_dirent_size(ent);
1373 static int mdt_bulk_timeout(void *data)
1377 CERROR("mdt bulk transfer timeout \n");
1382 static int mdt_writepage(struct mdt_thread_info *info)
1384 struct ptlrpc_request *req = mdt_info_req(info);
1385 struct mdt_body *reqbody;
1386 struct l_wait_info *lwi;
1387 struct ptlrpc_bulk_desc *desc;
1393 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1394 if (reqbody == NULL)
1395 RETURN(err_serious(-EFAULT));
1397 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1399 RETURN(err_serious(-ENOMEM));
1401 /* allocate the page for the desc */
1402 page = cfs_alloc_page(CFS_ALLOC_STD);
1404 GOTO(desc_cleanup, rc = -ENOMEM);
1406 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1407 (int)reqbody->size, (int)reqbody->nlink);
1409 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1410 (int)reqbody->nlink);
1412 rc = sptlrpc_svc_prep_bulk(req, desc);
1414 GOTO(cleanup_page, rc);
1416 * Check if client was evicted while we were doing i/o before touching
1421 GOTO(cleanup_page, rc = -ENOMEM);
1423 if (desc->bd_export->exp_failed)
1426 rc = ptlrpc_start_bulk_transfer (desc);
1428 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1429 mdt_bulk_timeout, desc);
1430 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1431 desc->bd_export->exp_failed, lwi);
1432 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1433 if (rc == -ETIMEDOUT) {
1434 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1435 ptlrpc_abort_bulk(desc);
1436 } else if (desc->bd_export->exp_failed) {
1437 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1439 ptlrpc_abort_bulk(desc);
1440 } else if (!desc->bd_success ||
1441 desc->bd_nob_transferred != desc->bd_nob) {
1442 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1444 "truncated" : "network error on",
1445 desc->bd_nob_transferred, desc->bd_nob);
1446 /* XXX should this be a different errno? */
1450 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1453 GOTO(cleanup_lwi, rc);
1454 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1459 cfs_free_page(page);
1461 ptlrpc_free_bulk(desc);
1466 static int mdt_readpage(struct mdt_thread_info *info)
1468 struct mdt_object *object = info->mti_object;
1469 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1470 struct mdt_body *reqbody;
1471 struct mdt_body *repbody;
1476 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1477 RETURN(err_serious(-ENOMEM));
1479 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1480 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1481 if (reqbody == NULL || repbody == NULL)
1482 RETURN(err_serious(-EFAULT));
1485 * prepare @rdpg before calling lower layers and transfer itself. Here
1486 * reqbody->size contains offset of where to start to read and
1487 * reqbody->nlink contains number bytes to read.
1489 rdpg->rp_hash = reqbody->size;
1490 if (rdpg->rp_hash != reqbody->size) {
1491 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1492 rdpg->rp_hash, reqbody->size);
1496 rdpg->rp_attrs = reqbody->mode;
1497 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1498 rdpg->rp_attrs |= LUDA_64BITHASH;
1499 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1500 PTLRPC_MAX_BRW_SIZE);
1501 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1503 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1504 if (rdpg->rp_pages == NULL)
1507 for (i = 0; i < rdpg->rp_npages; ++i) {
1508 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1509 if (rdpg->rp_pages[i] == NULL)
1510 GOTO(free_rdpg, rc = -ENOMEM);
1513 /* call lower layers to fill allocated pages with directory data */
1514 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1516 GOTO(free_rdpg, rc);
1518 /* send pages to client */
1519 rc = mdt_sendpage(info, rdpg, rc);
1524 for (i = 0; i < rdpg->rp_npages; i++)
1525 if (rdpg->rp_pages[i] != NULL)
1526 cfs_free_page(rdpg->rp_pages[i]);
1527 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1529 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1535 static int mdt_reint_internal(struct mdt_thread_info *info,
1536 struct mdt_lock_handle *lhc,
1539 struct req_capsule *pill = info->mti_pill;
1540 struct mdt_device *mdt = info->mti_mdt;
1541 struct md_quota *mq = md_quota(info->mti_env);
1542 struct mdt_body *repbody;
1547 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1548 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1549 mdt->mdt_max_mdsize);
1550 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1551 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1552 mdt->mdt_max_cookiesize);
1554 rc = req_capsule_server_pack(pill);
1556 CERROR("Can't pack response, rc %d\n", rc);
1557 RETURN(err_serious(rc));
1560 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1561 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1563 repbody->eadatasize = 0;
1564 repbody->aclsize = 0;
1567 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1568 GOTO(out_shrink, rc = err_serious(-EFAULT));
1570 rc = mdt_reint_unpack(info, op);
1572 CERROR("Can't unpack reint, rc %d\n", rc);
1573 GOTO(out_shrink, rc = err_serious(rc));
1576 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1578 /* for replay no cookkie / lmm need, because client have this already */
1579 if (info->mti_spec.no_create == 1) {
1580 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1581 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1583 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1584 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1588 rc = mdt_init_ucred_reint(info);
1590 GOTO(out_shrink, rc);
1592 rc = mdt_fix_attr_ucred(info, op);
1594 GOTO(out_ucred, rc = err_serious(rc));
1596 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1597 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1598 GOTO(out_ucred, rc);
1600 mq->mq_exp = info->mti_exp;
1601 rc = mdt_reint_rec(info, lhc);
1604 mdt_exit_ucred(info);
1606 mdt_client_compatibility(info);
1607 mdt_shrink_reply(info);
1611 static long mdt_reint_opcode(struct mdt_thread_info *info,
1612 const struct req_format **fmt)
1614 struct mdt_rec_reint *rec;
1617 opc = err_serious(-EFAULT);
1618 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1620 opc = rec->rr_opcode;
1621 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1622 if (opc < REINT_MAX && fmt[opc] != NULL)
1623 req_capsule_extend(info->mti_pill, fmt[opc]);
1625 CERROR("Unsupported opc: %ld\n", opc);
1626 opc = err_serious(opc);
1632 static int mdt_reint(struct mdt_thread_info *info)
1637 static const struct req_format *reint_fmts[REINT_MAX] = {
1638 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1639 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1640 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1641 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1642 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1643 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1644 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1649 opc = mdt_reint_opcode(info, reint_fmts);
1652 * No lock possible here from client to pass it to reint code
1655 rc = mdt_reint_internal(info, NULL, opc);
1660 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1664 /* this should sync the whole device */
1665 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1667 struct dt_device *dt = mdt->mdt_bottom;
1671 rc = dt->dd_ops->dt_sync(env, dt);
1675 /* this should sync this object */
1676 static int mdt_object_sync(struct mdt_thread_info *info)
1678 struct md_object *next;
1682 if (!mdt_object_exists(info->mti_object)) {
1683 CWARN("Non existing object "DFID"!\n",
1684 PFID(mdt_object_fid(info->mti_object)));
1687 next = mdt_object_child(info->mti_object);
1688 rc = mo_object_sync(info->mti_env, next);
1693 static int mdt_sync(struct mdt_thread_info *info)
1695 struct ptlrpc_request *req = mdt_info_req(info);
1696 struct req_capsule *pill = info->mti_pill;
1697 struct mdt_body *body;
1701 /* The fid may be zero, so we req_capsule_set manually */
1702 req_capsule_set(pill, &RQF_MDS_SYNC);
1704 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1706 RETURN(err_serious(-EINVAL));
1708 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1709 RETURN(err_serious(-ENOMEM));
1711 if (fid_seq(&body->fid1) == 0) {
1712 /* sync the whole device */
1713 rc = req_capsule_server_pack(pill);
1715 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1717 rc = err_serious(rc);
1719 /* sync an object */
1720 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1722 rc = mdt_object_sync(info);
1724 struct md_object *next;
1725 const struct lu_fid *fid;
1726 struct lu_attr *la = &info->mti_attr.ma_attr;
1728 next = mdt_object_child(info->mti_object);
1729 info->mti_attr.ma_need = MA_INODE;
1730 info->mti_attr.ma_valid = 0;
1731 rc = mo_attr_get(info->mti_env, next,
1734 body = req_capsule_server_get(pill,
1736 fid = mdt_object_fid(info->mti_object);
1737 mdt_pack_attr2body(info, body, la, fid);
1741 rc = err_serious(rc);
1744 mdt_counter_incr(req->rq_export, LPROC_MDT_SYNC);
1749 #ifdef HAVE_QUOTA_SUPPORT
1750 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1752 struct obd_quotactl *oqctl;
1753 struct req_capsule *pill = info->mti_pill;
1754 struct obd_export *exp = info->mti_exp;
1755 struct md_quota *mq = md_quota(info->mti_env);
1756 struct md_device *next = info->mti_mdt->mdt_child;
1760 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1764 /* remote client has no permission for quotacheck */
1765 if (unlikely(exp_connect_rmtclient(exp)))
1768 rc = req_capsule_server_pack(pill);
1773 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1778 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1780 struct obd_quotactl *oqctl, *repoqc;
1781 struct req_capsule *pill = info->mti_pill;
1782 struct obd_export *exp = info->mti_exp;
1783 struct md_quota *mq = md_quota(info->mti_env);
1784 struct md_device *next = info->mti_mdt->mdt_child;
1785 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1789 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1794 if (exp_connect_rmtclient(exp)) {
1795 struct ptlrpc_request *req = mdt_info_req(info);
1796 struct mdt_export_data *med = mdt_req2med(req);
1797 struct lustre_idmap_table *idmap = med->med_idmap;
1799 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1800 oqctl->qc_cmd != Q_GETINFO))
1804 if (oqctl->qc_type == USRQUOTA)
1805 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1807 else if (oqctl->qc_type == GRPQUOTA)
1808 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1813 if (id == CFS_IDMAP_NOTFOUND) {
1814 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1820 rc = req_capsule_server_pack(pill);
1824 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1825 LASSERT(repoqc != NULL);
1828 switch (oqctl->qc_cmd) {
1830 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1833 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1836 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1840 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1844 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1848 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1852 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1856 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1859 case LUSTRE_Q_INVALIDATE:
1860 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1862 case LUSTRE_Q_FINVALIDATE:
1863 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1866 CERROR("unsupported mdt_quotactl command: %d\n",
1878 * OBD PING and other handlers.
1880 static int mdt_obd_ping(struct mdt_thread_info *info)
1885 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1887 rc = target_handle_ping(mdt_info_req(info));
1889 rc = err_serious(rc);
1893 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1895 return err_serious(-EOPNOTSUPP);
1898 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1900 return err_serious(-EOPNOTSUPP);
1908 /** clone llog ctxt from child (mdd)
1909 * This allows remote llog (replicator) access.
1910 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1911 * context was originally set up, or we can handle them directly.
1912 * I choose the latter, but that means I need any llog
1913 * contexts set up by child to be accessable by the mdt. So we clone the
1914 * context into our context list here.
1916 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1919 struct md_device *next = mdt->mdt_child;
1920 struct llog_ctxt *ctxt;
1923 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1926 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1927 if (rc || ctxt == NULL) {
1928 CERROR("Can't get mdd ctxt %d\n", rc);
1932 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1934 CERROR("Can't set mdt ctxt %d\n", rc);
1939 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1940 struct mdt_device *mdt, int idx)
1942 struct llog_ctxt *ctxt;
1944 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1947 /* Put once for the get we just did, and once for the clone */
1948 llog_ctxt_put(ctxt);
1949 llog_ctxt_put(ctxt);
1953 static int mdt_llog_create(struct mdt_thread_info *info)
1957 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1958 rc = llog_origin_handle_create(mdt_info_req(info));
1959 return (rc < 0 ? err_serious(rc) : rc);
1962 static int mdt_llog_destroy(struct mdt_thread_info *info)
1966 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1967 rc = llog_origin_handle_destroy(mdt_info_req(info));
1968 return (rc < 0 ? err_serious(rc) : rc);
1971 static int mdt_llog_read_header(struct mdt_thread_info *info)
1975 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1976 rc = llog_origin_handle_read_header(mdt_info_req(info));
1977 return (rc < 0 ? err_serious(rc) : rc);
1980 static int mdt_llog_next_block(struct mdt_thread_info *info)
1984 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1985 rc = llog_origin_handle_next_block(mdt_info_req(info));
1986 return (rc < 0 ? err_serious(rc) : rc);
1989 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1993 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1994 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1995 return (rc < 0 ? err_serious(rc) : rc);
2002 static struct ldlm_callback_suite cbs = {
2003 .lcs_completion = ldlm_server_completion_ast,
2004 .lcs_blocking = ldlm_server_blocking_ast,
2008 static int mdt_enqueue(struct mdt_thread_info *info)
2010 struct ptlrpc_request *req;
2014 * info->mti_dlm_req already contains swapped and (if necessary)
2015 * converted dlm request.
2017 LASSERT(info->mti_dlm_req != NULL);
2019 req = mdt_info_req(info);
2020 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2021 req, info->mti_dlm_req, &cbs);
2022 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2023 return rc ? err_serious(rc) : req->rq_status;
2026 static int mdt_convert(struct mdt_thread_info *info)
2029 struct ptlrpc_request *req;
2031 LASSERT(info->mti_dlm_req);
2032 req = mdt_info_req(info);
2033 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2034 return rc ? err_serious(rc) : req->rq_status;
2037 static int mdt_bl_callback(struct mdt_thread_info *info)
2039 CERROR("bl callbacks should not happen on MDS\n");
2041 return err_serious(-EOPNOTSUPP);
2044 static int mdt_cp_callback(struct mdt_thread_info *info)
2046 CERROR("cp callbacks should not happen on MDS\n");
2048 return err_serious(-EOPNOTSUPP);
2052 * sec context handlers
2054 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2058 rc = mdt_handle_idmap(info);
2061 struct ptlrpc_request *req = mdt_info_req(info);
2064 opc = lustre_msg_get_opc(req->rq_reqmsg);
2065 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2066 sptlrpc_svc_ctx_invalidate(req);
2069 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2074 static struct mdt_object *mdt_obj(struct lu_object *o)
2076 LASSERT(lu_device_is_mdt(o->lo_dev));
2077 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2080 struct mdt_object *mdt_object_find(const struct lu_env *env,
2081 struct mdt_device *d,
2082 const struct lu_fid *f)
2084 struct lu_object *o;
2085 struct mdt_object *m;
2088 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2089 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2090 if (unlikely(IS_ERR(o)))
2091 m = (struct mdt_object *)o;
2098 * Asyncronous commit for mdt device.
2100 * Pass asynchonous commit call down the MDS stack.
2102 * \param env environment
2103 * \param mdt the mdt device
2105 static void mdt_device_commit_async(const struct lu_env *env,
2106 struct mdt_device *mdt)
2108 struct dt_device *dt = mdt->mdt_bottom;
2111 rc = dt->dd_ops->dt_commit_async(env, dt);
2112 if (unlikely(rc != 0))
2113 CWARN("async commit start failed with rc = %d", rc);
2117 * Mark the lock as "synchonous".
2119 * Mark the lock to deffer transaction commit to the unlock time.
2121 * \param lock the lock to mark as "synchonous"
2123 * \see mdt_is_lock_sync
2124 * \see mdt_save_lock
2126 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2128 lock->l_ast_data = (void*)1;
2132 * Check whehter the lock "synchonous" or not.
2134 * \param lock the lock to check
2135 * \retval 1 the lock is "synchonous"
2136 * \retval 0 the lock isn't "synchronous"
2138 * \see mdt_set_lock_sync
2139 * \see mdt_save_lock
2141 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2143 return lock->l_ast_data != NULL;
2147 * Blocking AST for mdt locks.
2149 * Starts transaction commit if in case of COS lock conflict or
2150 * deffers such a commit to the mdt_save_lock.
2152 * \param lock the lock which blocks a request or cancelling lock
2153 * \param desc unused
2154 * \param data unused
2155 * \param flag indicates whether this cancelling or blocking callback
2157 * \see ldlm_blocking_ast_nocheck
2159 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2160 void *data, int flag)
2162 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2163 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2167 if (flag == LDLM_CB_CANCELING)
2169 lock_res_and_lock(lock);
2170 if (lock->l_blocking_ast != mdt_blocking_ast) {
2171 unlock_res_and_lock(lock);
2174 if (mdt_cos_is_enabled(mdt) &&
2175 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2176 lock->l_blocking_lock != NULL &&
2177 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2178 mdt_set_lock_sync(lock);
2180 rc = ldlm_blocking_ast_nocheck(lock);
2182 /* There is no lock conflict if l_blocking_lock == NULL,
2183 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2184 * when the last reference to a local lock was released */
2185 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2188 rc = lu_env_init(&env, LCT_MD_THREAD);
2189 if (unlikely(rc != 0))
2190 CWARN("lu_env initialization failed with rc = %d,"
2191 "cannot start asynchronous commit\n", rc);
2193 mdt_device_commit_async(&env, mdt);
2199 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2200 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2202 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2203 ldlm_policy_data_t *policy = &info->mti_policy;
2204 struct ldlm_res_id *res_id = &info->mti_res_id;
2208 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2209 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2210 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2211 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2213 if (mdt_object_exists(o) < 0) {
2214 if (locality == MDT_CROSS_LOCK) {
2215 /* cross-ref object fix */
2216 ibits &= ~MDS_INODELOCK_UPDATE;
2217 ibits |= MDS_INODELOCK_LOOKUP;
2219 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2220 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2222 /* No PDO lock on remote object */
2223 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2226 if (lh->mlh_type == MDT_PDO_LOCK) {
2227 /* check for exists after object is locked */
2228 if (mdt_object_exists(o) == 0) {
2229 /* Non-existent object shouldn't have PDO lock */
2232 /* Non-dir object shouldn't have PDO lock */
2233 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2238 memset(policy, 0, sizeof(*policy));
2239 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2242 * Take PDO lock on whole directory and build correct @res_id for lock
2243 * on part of directory.
2245 if (lh->mlh_pdo_hash != 0) {
2246 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2247 mdt_lock_pdo_mode(info, o, lh);
2248 if (lh->mlh_pdo_mode != LCK_NL) {
2250 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2251 * is never going to be sent to client and we do not
2252 * want it slowed down due to possible cancels.
2254 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2255 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2256 policy, res_id, LDLM_FL_ATOMIC_CB,
2257 &info->mti_exp->exp_handle.h_cookie);
2263 * Finish res_id initializing by name hash marking part of
2264 * directory which is taking modification.
2266 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2269 policy->l_inodebits.bits = ibits;
2272 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2273 * going to be sent to client. If it is - mdt_intent_policy() path will
2274 * fix it up and turn FL_LOCAL flag off.
2276 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2277 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2278 &info->mti_exp->exp_handle.h_cookie);
2280 mdt_object_unlock(info, o, lh, 1);
2281 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2282 lh->mlh_pdo_hash != 0 &&
2283 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2284 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2291 * Save a lock within request object.
2293 * Keep the lock referenced until whether client ACK or transaction
2294 * commit happens or release the lock immediately depending on input
2295 * parameters. If COS is ON, a write lock is converted to COS lock
2298 * \param info thead info object
2299 * \param h lock handle
2300 * \param mode lock mode
2301 * \param decref force immediate lock releasing
2304 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2305 ldlm_mode_t mode, int decref)
2309 if (lustre_handle_is_used(h)) {
2310 if (decref || !info->mti_has_trans ||
2311 !(mode & (LCK_PW | LCK_EX))){
2312 mdt_fid_unlock(h, mode);
2314 struct mdt_device *mdt = info->mti_mdt;
2315 struct ldlm_lock *lock = ldlm_handle2lock(h);
2316 struct ptlrpc_request *req = mdt_info_req(info);
2319 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2321 CDEBUG(D_HA, "request = %p reply state = %p"
2322 " transno = "LPD64"\n",
2323 req, req->rq_reply_state, req->rq_transno);
2324 if (mdt_cos_is_enabled(mdt)) {
2326 ldlm_lock_downgrade(lock, LCK_COS);
2329 ptlrpc_save_lock(req, h, mode, no_ack);
2330 if (mdt_is_lock_sync(lock)) {
2331 CDEBUG(D_HA, "found sync-lock,"
2332 " async commit started\n");
2333 mdt_device_commit_async(info->mti_env,
2336 LDLM_LOCK_PUT(lock);
2345 * Unlock mdt object.
2347 * Immeditely release the regular lock and the PDO lock or save the
2348 * lock in reqeuest and keep them referenced until client ACK or
2349 * transaction commit.
2351 * \param info thread info object
2352 * \param o mdt object
2353 * \param lh mdt lock handle referencing regular and PDO locks
2354 * \param decref force immediate lock releasing
2356 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2357 struct mdt_lock_handle *lh, int decref)
2361 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2362 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2367 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2368 const struct lu_fid *f,
2369 struct mdt_lock_handle *lh,
2372 struct mdt_object *o;
2374 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2378 rc = mdt_object_lock(info, o, lh, ibits,
2381 mdt_object_put(info->mti_env, o);
2388 void mdt_object_unlock_put(struct mdt_thread_info * info,
2389 struct mdt_object * o,
2390 struct mdt_lock_handle *lh,
2393 mdt_object_unlock(info, o, lh, decref);
2394 mdt_object_put(info->mti_env, o);
2397 static struct mdt_handler *mdt_handler_find(__u32 opc,
2398 struct mdt_opc_slice *supported)
2400 struct mdt_opc_slice *s;
2401 struct mdt_handler *h;
2404 for (s = supported; s->mos_hs != NULL; s++) {
2405 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2406 h = s->mos_hs + (opc - s->mos_opc_start);
2407 if (likely(h->mh_opc != 0))
2408 LASSERTF(h->mh_opc == opc,
2409 "opcode mismatch %d != %d\n",
2412 h = NULL; /* unsupported opc */
2419 static int mdt_lock_resname_compat(struct mdt_device *m,
2420 struct ldlm_request *req)
2422 /* XXX something... later. */
2426 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2428 /* XXX something... later. */
2433 * Generic code handling requests that have struct mdt_body passed in:
2435 * - extract mdt_body from request and save it in @info, if present;
2437 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2440 * - if HABEO_CORPUS flag is set for this request type check whether object
2441 * actually exists on storage (lu_object_exists()).
2444 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2446 const struct mdt_body *body;
2447 struct mdt_object *obj;
2448 const struct lu_env *env;
2449 struct req_capsule *pill;
2453 env = info->mti_env;
2454 pill = info->mti_pill;
2456 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2460 if (!(body->valid & OBD_MD_FLID))
2463 if (!fid_is_sane(&body->fid1)) {
2464 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2469 * Do not get size or any capa fields before we check that request
2470 * contains capa actually. There are some requests which do not, for
2471 * instance MDS_IS_SUBDIR.
2473 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2474 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2475 mdt_set_capainfo(info, 0, &body->fid1,
2476 req_capsule_client_get(pill, &RMF_CAPA1));
2478 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2480 if ((flags & HABEO_CORPUS) &&
2481 !mdt_object_exists(obj)) {
2482 mdt_object_put(env, obj);
2483 /* for capability renew ENOENT will be handled in
2485 if (body->valid & OBD_MD_FLOSSCAPA)
2490 info->mti_object = obj;
2499 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2501 struct req_capsule *pill = info->mti_pill;
2505 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2506 rc = mdt_body_unpack(info, flags);
2510 if (rc == 0 && (flags & HABEO_REFERO)) {
2511 struct mdt_device *mdt = info->mti_mdt;
2515 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2516 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2517 mdt->mdt_max_mdsize);
2518 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2519 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2520 mdt->mdt_max_cookiesize);
2522 rc = req_capsule_server_pack(pill);
2527 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2529 struct md_device *next = m->mdt_child;
2531 return next->md_ops->mdo_init_capa_ctxt(env, next,
2532 m->mdt_opts.mo_mds_capa,
2533 m->mdt_capa_timeout,
2539 * Invoke handler for this request opc. Also do necessary preprocessing
2540 * (according to handler ->mh_flags), and post-processing (setting of
2541 * ->last_{xid,committed}).
2543 static int mdt_req_handle(struct mdt_thread_info *info,
2544 struct mdt_handler *h, struct ptlrpc_request *req)
2546 int rc, serious = 0;
2551 LASSERT(h->mh_act != NULL);
2552 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2553 LASSERT(current->journal_info == NULL);
2556 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2557 * to put same checks into handlers like mdt_close(), mdt_reint(),
2558 * etc., without talking to mdt authors first. Checking same thing
2559 * there again is useless and returning 0 error without packing reply
2560 * is buggy! Handlers either pack reply or return error.
2562 * We return 0 here and do not send any reply in order to emulate
2563 * network failure. Do not send any reply in case any of NET related
2564 * fail_id has occured.
2566 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2570 flags = h->mh_flags;
2571 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2573 if (h->mh_fmt != NULL) {
2574 req_capsule_set(info->mti_pill, h->mh_fmt);
2575 rc = mdt_unpack_req_pack_rep(info, flags);
2578 if (rc == 0 && flags & MUTABOR &&
2579 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2580 /* should it be rq_status? */
2583 if (rc == 0 && flags & HABEO_CLAVIS) {
2584 struct ldlm_request *dlm_req;
2586 LASSERT(h->mh_fmt != NULL);
2588 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2589 if (dlm_req != NULL) {
2590 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2592 dlm_req->lock_desc.l_policy_data.\
2593 l_inodebits.bits == 0)) {
2595 * Lock without inodebits makes no sense and
2596 * will oops later in ldlm. If client miss to
2597 * set such bits, do not trigger ASSERTION.
2599 * For liblustre flock case, it maybe zero.
2603 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2604 rc = mdt_lock_resname_compat(
2607 info->mti_dlm_req = dlm_req;
2614 /* capability setting changed via /proc, needs reinitialize ctxt */
2615 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2616 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2617 info->mti_mdt->mdt_capa_conf = 0;
2620 if (likely(rc == 0)) {
2622 * Process request, there can be two types of rc:
2623 * 1) errors with msg unpack/pack, other failures outside the
2624 * operation itself. This is counted as serious errors;
2625 * 2) errors during fs operation, should be placed in rq_status
2628 rc = h->mh_act(info);
2630 !req->rq_no_reply && req->rq_reply_state == NULL) {
2631 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2632 "pack reply and returned 0 error\n",
2636 serious = is_serious(rc);
2637 rc = clear_serious(rc);
2641 req->rq_status = rc;
2644 * ELDLM_* codes which > 0 should be in rq_status only as well as
2645 * all non-serious errors.
2647 if (rc > 0 || !serious)
2650 LASSERT(current->journal_info == NULL);
2652 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2653 info->mti_mdt->mdt_opts.mo_compat_resname) {
2654 struct ldlm_reply *dlmrep;
2656 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2658 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2661 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2662 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2663 target_committed_to_req(req);
2665 if (unlikely(req_is_replay(req) &&
2666 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2667 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2671 target_send_reply(req, rc, info->mti_fail_id);
2675 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2677 lh->mlh_type = MDT_NUL_LOCK;
2678 lh->mlh_reg_lh.cookie = 0ull;
2679 lh->mlh_reg_mode = LCK_MINMODE;
2680 lh->mlh_pdo_lh.cookie = 0ull;
2681 lh->mlh_pdo_mode = LCK_MINMODE;
2684 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2686 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2687 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2691 * Initialize fields of struct mdt_thread_info. Other fields are left in
2692 * uninitialized state, because it's too expensive to zero out whole
2693 * mdt_thread_info (> 1K) on each request arrival.
2695 static void mdt_thread_info_init(struct ptlrpc_request *req,
2696 struct mdt_thread_info *info)
2699 struct md_capainfo *ci;
2701 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2702 info->mti_pill = &req->rq_pill;
2705 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2706 mdt_lock_handle_init(&info->mti_lh[i]);
2708 /* mdt device: it can be NULL while CONNECT */
2709 if (req->rq_export) {
2710 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2711 info->mti_exp = req->rq_export;
2713 info->mti_mdt = NULL;
2714 info->mti_env = req->rq_svc_thread->t_env;
2715 ci = md_capainfo(info->mti_env);
2716 memset(ci, 0, sizeof *ci);
2717 if (req->rq_export) {
2718 if (exp_connect_rmtclient(req->rq_export))
2719 ci->mc_auth = LC_ID_CONVERT;
2720 else if (req->rq_export->exp_connect_flags &
2721 OBD_CONNECT_MDS_CAPA)
2722 ci->mc_auth = LC_ID_PLAIN;
2724 ci->mc_auth = LC_ID_NONE;
2727 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2728 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2729 info->mti_mos = NULL;
2731 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2732 info->mti_body = NULL;
2733 info->mti_object = NULL;
2734 info->mti_dlm_req = NULL;
2735 info->mti_has_trans = 0;
2736 info->mti_no_need_trans = 0;
2737 info->mti_cross_ref = 0;
2738 info->mti_opdata = 0;
2740 /* To not check for split by default. */
2741 info->mti_spec.sp_ck_split = 0;
2742 info->mti_spec.no_create = 0;
2745 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2749 req_capsule_fini(info->mti_pill);
2750 if (info->mti_object != NULL) {
2752 * freeing an object may lead to OSD level transaction, do not
2753 * let it mess with MDT. bz19385.
2755 info->mti_no_need_trans = 1;
2756 mdt_object_put(info->mti_env, info->mti_object);
2757 info->mti_object = NULL;
2759 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2760 mdt_lock_handle_fini(&info->mti_lh[i]);
2761 info->mti_env = NULL;
2764 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2765 struct obd_device *obd, int *process)
2767 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2768 case MDS_CONNECT: /* This will never get here, but for completeness. */
2769 case OST_CONNECT: /* This will never get here, but for completeness. */
2770 case MDS_DISCONNECT:
2771 case OST_DISCONNECT:
2776 case MDS_DONE_WRITING:
2777 case MDS_SYNC: /* used in unmounting */
2783 *process = target_queue_recovery_request(req, obd);
2787 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2794 * Handle recovery. Return:
2795 * +1: continue request processing;
2796 * -ve: abort immediately with the given error code;
2797 * 0: send reply with error code in req->rq_status;
2799 static int mdt_recovery(struct mdt_thread_info *info)
2801 struct ptlrpc_request *req = mdt_info_req(info);
2802 struct obd_device *obd;
2806 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2809 case SEC_CTX_INIT_CONT:
2815 rc = mdt_handle_idmap(info);
2824 if (unlikely(!class_connected_export(req->rq_export))) {
2825 CERROR("operation %d on unconnected MDS from %s\n",
2826 lustre_msg_get_opc(req->rq_reqmsg),
2827 libcfs_id2str(req->rq_peer));
2828 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2829 * mds_A will get -ENOTCONN(especially for ping req),
2830 * which will cause that mds_A deactive timeout, then when
2831 * mds_A cleanup, the cleanup process will be suspended since
2832 * deactive timeout is not zero.
2834 req->rq_status = -ENOTCONN;
2835 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2839 /* sanity check: if the xid matches, the request must be marked as a
2840 * resent or replayed */
2841 if (req_xid_is_last(req)) {
2842 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2843 (MSG_RESENT | MSG_REPLAY))) {
2844 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2845 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2846 lustre_msg_get_flags(req->rq_reqmsg));
2848 req->rq_status = -ENOTCONN;
2853 /* else: note the opposite is not always true; a RESENT req after a
2854 * failover will usually not match the last_xid, since it was likely
2855 * never committed. A REPLAYed request will almost never match the
2856 * last xid, however it could for a committed, but still retained,
2859 obd = req->rq_export->exp_obd;
2861 /* Check for aborted recovery... */
2862 if (unlikely(obd->obd_recovering)) {
2865 DEBUG_REQ(D_INFO, req, "Got new replay");
2866 rc = mdt_filter_recovery_request(req, obd, &should_process);
2867 if (rc != 0 || !should_process)
2869 else if (should_process < 0) {
2870 req->rq_status = should_process;
2871 rc = ptlrpc_error(req);
2878 static int mdt_msg_check_version(struct lustre_msg *msg)
2882 switch (lustre_msg_get_opc(msg)) {
2884 case MDS_DISCONNECT:
2887 case SEC_CTX_INIT_CONT:
2889 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2891 CERROR("bad opc %u version %08x, expecting %08x\n",
2892 lustre_msg_get_opc(msg),
2893 lustre_msg_get_version(msg),
2894 LUSTRE_OBD_VERSION);
2898 case MDS_GETATTR_NAME:
2905 case MDS_DONE_WRITING:
2912 case MDS_QUOTACHECK:
2918 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2920 CERROR("bad opc %u version %08x, expecting %08x\n",
2921 lustre_msg_get_opc(msg),
2922 lustre_msg_get_version(msg),
2923 LUSTRE_MDS_VERSION);
2927 case LDLM_BL_CALLBACK:
2928 case LDLM_CP_CALLBACK:
2929 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2931 CERROR("bad opc %u version %08x, expecting %08x\n",
2932 lustre_msg_get_opc(msg),
2933 lustre_msg_get_version(msg),
2934 LUSTRE_DLM_VERSION);
2936 case OBD_LOG_CANCEL:
2937 case LLOG_ORIGIN_HANDLE_CREATE:
2938 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2939 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2940 case LLOG_ORIGIN_HANDLE_CLOSE:
2941 case LLOG_ORIGIN_HANDLE_DESTROY:
2942 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2944 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2946 CERROR("bad opc %u version %08x, expecting %08x\n",
2947 lustre_msg_get_opc(msg),
2948 lustre_msg_get_version(msg),
2949 LUSTRE_LOG_VERSION);
2952 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2958 static int mdt_handle0(struct ptlrpc_request *req,
2959 struct mdt_thread_info *info,
2960 struct mdt_opc_slice *supported)
2962 struct mdt_handler *h;
2963 struct lustre_msg *msg;
2968 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2971 LASSERT(current->journal_info == NULL);
2973 msg = req->rq_reqmsg;
2974 rc = mdt_msg_check_version(msg);
2975 if (likely(rc == 0)) {
2976 rc = mdt_recovery(info);
2977 if (likely(rc == +1)) {
2978 h = mdt_handler_find(lustre_msg_get_opc(msg),
2980 if (likely(h != NULL)) {
2981 rc = mdt_req_handle(info, h, req);
2983 CERROR("The unsupported opc: 0x%x\n",
2984 lustre_msg_get_opc(msg) );
2985 req->rq_status = -ENOTSUPP;
2986 rc = ptlrpc_error(req);
2991 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2996 * MDT handler function called by ptlrpc service thread when request comes.
2998 * XXX common "target" functionality should be factored into separate module
2999 * shared by mdt, ost and stand-alone services like fld.
3001 static int mdt_handle_common(struct ptlrpc_request *req,
3002 struct mdt_opc_slice *supported)
3005 struct mdt_thread_info *info;
3009 env = req->rq_svc_thread->t_env;
3010 LASSERT(env != NULL);
3011 LASSERT(env->le_ses != NULL);
3012 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3013 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3014 LASSERT(info != NULL);
3016 mdt_thread_info_init(req, info);
3018 rc = mdt_handle0(req, info, supported);
3020 mdt_thread_info_fini(info);
3025 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3028 int mdt_recovery_handle(struct ptlrpc_request *req)
3033 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3035 rc = mdt_handle_common(req, mdt_fld_handlers);
3038 rc = mdt_handle_common(req, mdt_seq_handlers);
3041 rc = mdt_handle_common(req, mdt_regular_handlers);
3048 static int mdt_regular_handle(struct ptlrpc_request *req)
3050 return mdt_handle_common(req, mdt_regular_handlers);
3053 static int mdt_readpage_handle(struct ptlrpc_request *req)
3055 return mdt_handle_common(req, mdt_readpage_handlers);
3058 static int mdt_xmds_handle(struct ptlrpc_request *req)
3060 return mdt_handle_common(req, mdt_xmds_handlers);
3063 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3065 return mdt_handle_common(req, mdt_seq_handlers);
3068 static int mdt_mdss_handle(struct ptlrpc_request *req)
3070 return mdt_handle_common(req, mdt_seq_handlers);
3073 static int mdt_dtss_handle(struct ptlrpc_request *req)
3075 return mdt_handle_common(req, mdt_seq_handlers);
3078 static int mdt_fld_handle(struct ptlrpc_request *req)
3080 return mdt_handle_common(req, mdt_fld_handlers);
3097 static int mdt_intent_getattr(enum mdt_it_code opcode,
3098 struct mdt_thread_info *info,
3099 struct ldlm_lock **,
3101 static int mdt_intent_reint(enum mdt_it_code opcode,
3102 struct mdt_thread_info *info,
3103 struct ldlm_lock **,
3106 static struct mdt_it_flavor {
3107 const struct req_format *it_fmt;
3109 int (*it_act)(enum mdt_it_code ,
3110 struct mdt_thread_info *,
3111 struct ldlm_lock **,
3114 } mdt_it_flavor[] = {
3116 .it_fmt = &RQF_LDLM_INTENT,
3117 /*.it_flags = HABEO_REFERO,*/
3119 .it_act = mdt_intent_reint,
3120 .it_reint = REINT_OPEN
3123 .it_fmt = &RQF_LDLM_INTENT,
3124 .it_flags = MUTABOR,
3125 .it_act = mdt_intent_reint,
3126 .it_reint = REINT_OPEN
3129 .it_fmt = &RQF_LDLM_INTENT,
3130 .it_flags = MUTABOR,
3131 .it_act = mdt_intent_reint,
3132 .it_reint = REINT_CREATE
3134 [MDT_IT_GETATTR] = {
3135 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3136 .it_flags = HABEO_REFERO,
3137 .it_act = mdt_intent_getattr
3139 [MDT_IT_READDIR] = {
3145 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3146 .it_flags = HABEO_REFERO,
3147 .it_act = mdt_intent_getattr
3150 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3151 .it_flags = MUTABOR,
3153 .it_reint = REINT_UNLINK
3157 .it_flags = MUTABOR,
3160 [MDT_IT_GETXATTR] = {
3166 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3167 .it_flags = HABEO_REFERO,
3168 .it_act = mdt_intent_getattr
3172 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3173 struct ldlm_lock **lockp,
3174 struct ldlm_lock *new_lock,
3175 struct mdt_lock_handle *lh,
3178 struct ptlrpc_request *req = mdt_info_req(info);
3179 struct ldlm_lock *lock = *lockp;
3182 * Get new lock only for cases when possible resent did not find any
3185 if (new_lock == NULL)
3186 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3188 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3189 lh->mlh_reg_lh.cookie = 0;
3193 LASSERTF(new_lock != NULL,
3194 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3197 * If we've already given this lock to a client once, then we should
3198 * have no readers or writers. Otherwise, we should have one reader
3199 * _or_ writer ref (which will be zeroed below) before returning the
3202 if (new_lock->l_export == req->rq_export) {
3203 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3205 LASSERT(new_lock->l_export == NULL);
3206 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3211 if (new_lock->l_export == req->rq_export) {
3213 * Already gave this to the client, which means that we
3214 * reconstructed a reply.
3216 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3218 lh->mlh_reg_lh.cookie = 0;
3219 RETURN(ELDLM_LOCK_REPLACED);
3223 * Fixup the lock to be given to the client.
3225 lock_res_and_lock(new_lock);
3226 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3227 * possible blocking AST. */
3228 while (new_lock->l_readers > 0) {
3229 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3230 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3231 new_lock->l_readers--;
3233 while (new_lock->l_writers > 0) {
3234 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3235 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3236 new_lock->l_writers--;