4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2010, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_handler.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Yury Umanets <umka@clusterfs.com>
49 #define DEBUG_SUBSYSTEM S_MDS
51 #include <linux/module.h>
53 * struct OBD_{ALLOC,FREE}*()
55 #include <obd_support.h>
56 /* struct ptlrpc_request */
57 #include <lustre_net.h>
58 /* struct obd_export */
59 #include <lustre_export.h>
60 /* struct obd_device */
63 #include <dt_object.h>
64 #include <lustre_mds.h>
65 #include <lustre_mdt.h>
66 #include <lustre_log.h>
67 #include "mdt_internal.h"
68 #include <lustre_acl.h>
69 #include <lustre_param.h>
70 #include <lustre_quota.h>
71 #include <lustre_linkea.h>
72 #include <lustre_lfsck.h>
74 mdl_mode_t mdt_mdl_lock_modes[] = {
75 [LCK_MINMODE] = MDL_MINMODE,
82 [LCK_GROUP] = MDL_GROUP
85 ldlm_mode_t mdt_dlm_lock_modes[] = {
86 [MDL_MINMODE] = LCK_MINMODE,
93 [MDL_GROUP] = LCK_GROUP
96 static struct mdt_device *mdt_dev(struct lu_device *d);
97 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
99 static const struct lu_object_operations mdt_obj_ops;
101 /* Slab for MDT object allocation */
102 static struct kmem_cache *mdt_object_kmem;
104 static struct lu_kmem_descr mdt_caches[] = {
106 .ckd_cache = &mdt_object_kmem,
107 .ckd_name = "mdt_obj",
108 .ckd_size = sizeof(struct mdt_object)
115 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
119 return (rep->lock_policy_res1 & flag);
122 void mdt_clear_disposition(struct mdt_thread_info *info,
123 struct ldlm_reply *rep, int flag)
126 info->mti_opdata &= ~flag;
128 rep->lock_policy_res1 &= ~flag;
131 void mdt_set_disposition(struct mdt_thread_info *info,
132 struct ldlm_reply *rep, int flag)
135 info->mti_opdata |= flag;
137 rep->lock_policy_res1 |= flag;
140 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
142 lh->mlh_pdo_hash = 0;
143 lh->mlh_reg_mode = lm;
144 lh->mlh_rreg_mode = lm;
145 lh->mlh_type = MDT_REG_LOCK;
148 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
149 const char *name, int namelen)
151 lh->mlh_reg_mode = lm;
152 lh->mlh_rreg_mode = lm;
153 lh->mlh_type = MDT_PDO_LOCK;
155 if (name != NULL && (name[0] != '\0')) {
156 LASSERT(namelen > 0);
157 lh->mlh_pdo_hash = full_name_hash(name, namelen);
158 /* XXX Workaround for LU-2856
159 * Zero is a valid return value of full_name_hash, but several
160 * users of mlh_pdo_hash assume a non-zero hash value. We
161 * therefore map zero onto an arbitrary, but consistent
162 * value (1) to avoid problems further down the road. */
163 if (unlikely(!lh->mlh_pdo_hash))
164 lh->mlh_pdo_hash = 1;
166 LASSERT(namelen == 0);
167 lh->mlh_pdo_hash = 0ull;
171 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
172 struct mdt_lock_handle *lh)
178 * Any dir access needs couple of locks:
180 * 1) on part of dir we gonna take lookup/modify;
182 * 2) on whole dir to protect it from concurrent splitting and/or to
183 * flush client's cache for readdir().
185 * so, for a given mode and object this routine decides what lock mode
186 * to use for lock #2:
188 * 1) if caller's gonna lookup in dir then we need to protect dir from
189 * being splitted only - LCK_CR
191 * 2) if caller's gonna modify dir then we need to protect dir from
192 * being splitted and to flush cache - LCK_CW
194 * 3) if caller's gonna modify dir and that dir seems ready for
195 * splitting then we need to protect it from any type of access
196 * (lookup/modify/split) - LCK_EX --bzzz
199 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
200 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
203 * Ask underlaying level its opinion about preferable PDO lock mode
204 * having access type passed as regular lock mode:
206 * - MDL_MINMODE means that lower layer does not want to specify lock
209 * - MDL_NL means that no PDO lock should be taken. This is used in some
210 * cases. Say, for non-splittable directories no need to use PDO locks
213 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
214 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
216 if (mode != MDL_MINMODE) {
217 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
220 * Lower layer does not want to specify locking mode. We do it
221 * our selves. No special protection is needed, just flush
222 * client's cache on modification and allow concurrent
225 switch (lh->mlh_reg_mode) {
227 lh->mlh_pdo_mode = LCK_EX;
230 lh->mlh_pdo_mode = LCK_CR;
233 lh->mlh_pdo_mode = LCK_CW;
236 CERROR("Not expected lock type (0x%x)\n",
237 (int)lh->mlh_reg_mode);
242 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
246 int mdt_getstatus(struct mdt_thread_info *info)
248 struct mdt_device *mdt = info->mti_mdt;
249 struct mdt_body *repbody;
253 rc = mdt_check_ucred(info);
255 RETURN(err_serious(rc));
257 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
258 RETURN(err_serious(-ENOMEM));
260 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
261 repbody->fid1 = mdt->mdt_md_root_fid;
262 repbody->valid |= OBD_MD_FLID;
264 if (mdt->mdt_opts.mo_mds_capa &&
265 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
266 struct mdt_object *root;
267 struct lustre_capa *capa;
269 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
271 RETURN(PTR_ERR(root));
273 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
275 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
276 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
278 mdt_object_put(info->mti_env, root);
280 repbody->valid |= OBD_MD_FLMDSCAPA;
286 int mdt_statfs(struct mdt_thread_info *info)
288 struct ptlrpc_request *req = mdt_info_req(info);
289 struct md_device *next = info->mti_mdt->mdt_child;
290 struct ptlrpc_service_part *svcpt;
291 struct obd_statfs *osfs;
296 svcpt = info->mti_pill->rc_req->rq_rqbd->rqbd_svcpt;
298 /* This will trigger a watchdog timeout */
299 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
300 (MDT_SERVICE_WATCHDOG_FACTOR *
301 at_get(&svcpt->scp_at_estimate)) + 1);
303 rc = mdt_check_ucred(info);
305 RETURN(err_serious(rc));
307 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
308 RETURN(err_serious(-ENOMEM));
310 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
314 /** statfs information are cached in the mdt_device */
315 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
316 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
317 /** statfs data is too old, get up-to-date one */
318 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
321 spin_lock(&info->mti_mdt->mdt_osfs_lock);
322 info->mti_mdt->mdt_osfs = *osfs;
323 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
324 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
326 /** use cached statfs data */
327 spin_lock(&info->mti_mdt->mdt_osfs_lock);
328 *osfs = info->mti_mdt->mdt_osfs;
329 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
333 mdt_counter_incr(req, LPROC_MDT_STATFS);
339 * Pack SOM attributes into the reply.
340 * Call under a DLM UPDATE lock.
342 static void mdt_pack_size2body(struct mdt_thread_info *info,
343 struct mdt_object *mo)
346 struct md_attr *ma = &info->mti_attr;
348 LASSERT(ma->ma_attr.la_valid & LA_MODE);
349 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
351 /* Check if Size-on-MDS is supported, if this is a regular file,
352 * if SOM is enabled on the object and if SOM cache exists and valid.
353 * Otherwise do not pack Size-on-MDS attributes to the reply. */
354 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
355 !S_ISREG(ma->ma_attr.la_mode) ||
356 !mdt_object_is_som_enabled(mo) ||
357 !(ma->ma_valid & MA_SOM))
360 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
361 b->size = ma->ma_som->msd_size;
362 b->blocks = ma->ma_som->msd_blocks;
365 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
366 const struct lu_attr *attr, const struct lu_fid *fid)
368 struct md_attr *ma = &info->mti_attr;
370 LASSERT(ma->ma_valid & MA_INODE);
372 b->atime = attr->la_atime;
373 b->mtime = attr->la_mtime;
374 b->ctime = attr->la_ctime;
375 b->mode = attr->la_mode;
376 b->size = attr->la_size;
377 b->blocks = attr->la_blocks;
378 b->uid = attr->la_uid;
379 b->gid = attr->la_gid;
380 b->flags = attr->la_flags;
381 b->nlink = attr->la_nlink;
382 b->rdev = attr->la_rdev;
384 /*XXX should pack the reply body according to lu_valid*/
385 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
386 OBD_MD_FLGID | OBD_MD_FLTYPE |
387 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
388 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
390 if (!S_ISREG(attr->la_mode)) {
391 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
392 } else if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV)) {
393 /* means no objects are allocated on osts. */
394 LASSERT(!(ma->ma_valid & MA_LOV));
395 /* just ignore blocks occupied by extend attributes on MDS */
397 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
398 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
403 b->valid |= OBD_MD_FLID;
404 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
405 PFID(fid), b->nlink, b->mode, b->size);
409 mdt_body_reverse_idmap(info, b);
411 if (b->valid & OBD_MD_FLSIZE)
412 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
413 PFID(fid), (unsigned long long)b->size);
416 static inline int mdt_body_has_lov(const struct lu_attr *la,
417 const struct mdt_body *body)
419 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
420 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
423 void mdt_client_compatibility(struct mdt_thread_info *info)
425 struct mdt_body *body;
426 struct ptlrpc_request *req = mdt_info_req(info);
427 struct obd_export *exp = req->rq_export;
428 struct md_attr *ma = &info->mti_attr;
429 struct lu_attr *la = &ma->ma_attr;
432 if (exp_connect_layout(exp))
433 /* the client can deal with 16-bit lmm_stripe_count */
436 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
438 if (!mdt_body_has_lov(la, body))
441 /* now we have a reply with a lov for a client not compatible with the
442 * layout lock so we have to clean the layout generation number */
443 if (S_ISREG(la->la_mode))
444 ma->ma_lmm->lmm_layout_gen = 0;
448 static int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o,
451 const struct lu_env *env = info->mti_env;
455 LASSERT(info->mti_big_lmm_used == 0);
456 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL, name);
460 /* big_lmm may need to be grown */
461 if (info->mti_big_lmmsize < rc) {
462 int size = size_roundup_power2(rc);
464 if (info->mti_big_lmmsize > 0) {
465 /* free old buffer */
466 LASSERT(info->mti_big_lmm);
467 OBD_FREE_LARGE(info->mti_big_lmm,
468 info->mti_big_lmmsize);
469 info->mti_big_lmm = NULL;
470 info->mti_big_lmmsize = 0;
473 OBD_ALLOC_LARGE(info->mti_big_lmm, size);
474 if (info->mti_big_lmm == NULL)
476 info->mti_big_lmmsize = size;
478 LASSERT(info->mti_big_lmmsize >= rc);
480 info->mti_buf.lb_buf = info->mti_big_lmm;
481 info->mti_buf.lb_len = info->mti_big_lmmsize;
482 rc = mo_xattr_get(env, mdt_object_child(o), &info->mti_buf, name);
487 int mdt_attr_get_lov(struct mdt_thread_info *info,
488 struct mdt_object *o, struct md_attr *ma)
490 struct md_object *next = mdt_object_child(o);
491 struct lu_buf *buf = &info->mti_buf;
494 buf->lb_buf = ma->ma_lmm;
495 buf->lb_len = ma->ma_lmm_size;
496 rc = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_LOV);
498 ma->ma_lmm_size = rc;
499 ma->ma_valid |= MA_LOV;
501 } else if (rc == -ENODATA) {
504 } else if (rc == -ERANGE) {
505 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LOV);
507 info->mti_big_lmm_used = 1;
508 ma->ma_valid |= MA_LOV;
509 ma->ma_lmm = info->mti_big_lmm;
510 ma->ma_lmm_size = rc;
511 /* update mdt_max_mdsize so all clients
512 * will be aware about that */
513 if (info->mti_mdt->mdt_max_mdsize < rc)
514 info->mti_mdt->mdt_max_mdsize = rc;
522 int mdt_attr_get_pfid(struct mdt_thread_info *info,
523 struct mdt_object *o, struct lu_fid *pfid)
525 struct lu_buf *buf = &info->mti_buf;
526 struct link_ea_header *leh;
527 struct link_ea_entry *lee;
531 buf->lb_buf = info->mti_big_lmm;
532 buf->lb_len = info->mti_big_lmmsize;
533 rc = mo_xattr_get(info->mti_env, mdt_object_child(o),
534 buf, XATTR_NAME_LINK);
535 /* ignore errors, MA_PFID won't be set and it is
536 * up to the caller to treat this as an error */
537 if (rc == -ERANGE || buf->lb_len == 0) {
538 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LINK);
539 buf->lb_buf = info->mti_big_lmm;
540 buf->lb_len = info->mti_big_lmmsize;
545 if (rc < sizeof(*leh)) {
546 CERROR("short LinkEA on "DFID": rc = %d\n",
547 PFID(mdt_object_fid(o)), rc);
551 leh = (struct link_ea_header *) buf->lb_buf;
552 lee = (struct link_ea_entry *)(leh + 1);
553 if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) {
554 leh->leh_magic = LINK_EA_MAGIC;
555 leh->leh_reccount = __swab32(leh->leh_reccount);
556 leh->leh_len = __swab64(leh->leh_len);
558 if (leh->leh_magic != LINK_EA_MAGIC)
560 if (leh->leh_reccount == 0)
563 memcpy(pfid, &lee->lee_parent_fid, sizeof(*pfid));
564 fid_be_to_cpu(pfid, pfid);
569 int mdt_attr_get_complex(struct mdt_thread_info *info,
570 struct mdt_object *o, struct md_attr *ma)
572 const struct lu_env *env = info->mti_env;
573 struct md_object *next = mdt_object_child(o);
574 struct lu_buf *buf = &info->mti_buf;
575 u32 mode = lu_object_attr(&next->mo_lu);
576 int need = ma->ma_need;
582 if (need & MA_INODE) {
583 ma->ma_need = MA_INODE;
584 rc = mo_attr_get(env, next, ma);
587 ma->ma_valid |= MA_INODE;
590 if (need & MA_PFID) {
591 rc = mdt_attr_get_pfid(info, o, &ma->ma_pfid);
593 ma->ma_valid |= MA_PFID;
594 /* ignore this error, parent fid is not mandatory */
598 if (need & MA_LOV && (S_ISREG(mode) || S_ISDIR(mode))) {
599 rc = mdt_attr_get_lov(info, o, ma);
604 if (need & MA_LMV && S_ISDIR(mode)) {
605 buf->lb_buf = ma->ma_lmv;
606 buf->lb_len = ma->ma_lmv_size;
607 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_LMV);
609 ma->ma_lmv_size = rc2;
610 ma->ma_valid |= MA_LMV;
611 } else if (rc2 == -ENODATA) {
618 if (need & MA_SOM && S_ISREG(mode)) {
619 buf->lb_buf = info->mti_xattr_buf;
620 buf->lb_len = sizeof(info->mti_xattr_buf);
621 CLASSERT(sizeof(struct som_attrs) <=
622 sizeof(info->mti_xattr_buf));
623 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_SOM);
624 rc2 = lustre_buf2som(info->mti_xattr_buf, rc2, ma->ma_som);
626 ma->ma_valid |= MA_SOM;
627 else if (rc2 < 0 && rc2 != -ENODATA)
631 if (need & MA_HSM && S_ISREG(mode)) {
632 buf->lb_buf = info->mti_xattr_buf;
633 buf->lb_len = sizeof(info->mti_xattr_buf);
634 CLASSERT(sizeof(struct hsm_attrs) <=
635 sizeof(info->mti_xattr_buf));
636 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_HSM);
637 rc2 = lustre_buf2hsm(info->mti_xattr_buf, rc2, &ma->ma_hsm);
639 ma->ma_valid |= MA_HSM;
640 else if (rc2 < 0 && rc2 != -ENODATA)
644 #ifdef CONFIG_FS_POSIX_ACL
645 if (need & MA_ACL_DEF && S_ISDIR(mode)) {
646 buf->lb_buf = ma->ma_acl;
647 buf->lb_len = ma->ma_acl_size;
648 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_DEFAULT);
650 ma->ma_acl_size = rc2;
651 ma->ma_valid |= MA_ACL_DEF;
652 } else if (rc2 == -ENODATA) {
661 CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = "LPX64" ma_lmm=%p\n",
662 rc, ma->ma_valid, ma->ma_lmm);
666 static int mdt_getattr_internal(struct mdt_thread_info *info,
667 struct mdt_object *o, int ma_need)
669 struct md_object *next = mdt_object_child(o);
670 const struct mdt_body *reqbody = info->mti_body;
671 struct ptlrpc_request *req = mdt_info_req(info);
672 struct md_attr *ma = &info->mti_attr;
673 struct lu_attr *la = &ma->ma_attr;
674 struct req_capsule *pill = info->mti_pill;
675 const struct lu_env *env = info->mti_env;
676 struct mdt_body *repbody;
677 struct lu_buf *buffer = &info->mti_buf;
682 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
683 RETURN(err_serious(-ENOMEM));
685 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
689 if (mdt_object_remote(o)) {
690 /* This object is located on remote node.*/
691 /* Return -EIO for old client */
692 if (!mdt_is_dne_client(req->rq_export))
693 GOTO(out, rc = -EIO);
695 repbody->fid1 = *mdt_object_fid(o);
696 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
700 buffer->lb_len = reqbody->eadatasize;
701 if (buffer->lb_len > 0)
702 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
704 buffer->lb_buf = NULL;
706 /* If it is dir object and client require MEA, then we got MEA */
707 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
708 reqbody->valid & OBD_MD_MEA) {
709 /* Assumption: MDT_MD size is enough for lmv size. */
710 ma->ma_lmv = buffer->lb_buf;
711 ma->ma_lmv_size = buffer->lb_len;
712 ma->ma_need = MA_LMV | MA_INODE;
714 ma->ma_lmm = buffer->lb_buf;
715 ma->ma_lmm_size = buffer->lb_len;
716 ma->ma_need = MA_LOV | MA_INODE | MA_HSM;
719 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
720 reqbody->valid & OBD_MD_FLDIREA &&
721 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
722 /* get default stripe info for this dir. */
723 ma->ma_need |= MA_LOV_DEF;
725 ma->ma_need |= ma_need;
726 if (ma->ma_need & MA_SOM)
727 ma->ma_som = &info->mti_u.som.data;
729 rc = mdt_attr_get_complex(info, o, ma);
731 CERROR("%s: getattr error for "DFID": rc = %d\n",
732 mdt_obd_name(info->mti_mdt),
733 PFID(mdt_object_fid(o)), rc);
737 is_root = lu_fid_eq(mdt_object_fid(o), &info->mti_mdt->mdt_md_root_fid);
739 /* the Lustre protocol supposes to return default striping
740 * on the user-visible root if explicitly requested */
741 if ((ma->ma_valid & MA_LOV) == 0 && S_ISDIR(la->la_mode) &&
742 (ma->ma_need & MA_LOV_DEF && is_root) && (ma->ma_need & MA_LOV)) {
743 struct lu_fid rootfid;
744 struct mdt_object *root;
745 struct mdt_device *mdt = info->mti_mdt;
747 rc = dt_root_get(env, mdt->mdt_bottom, &rootfid);
750 root = mdt_object_find(env, mdt, &rootfid);
752 RETURN(PTR_ERR(root));
753 rc = mdt_attr_get_lov(info, root, ma);
754 mdt_object_put(info->mti_env, root);
756 CERROR("%s: getattr error for "DFID": rc = %d\n",
757 mdt_obd_name(info->mti_mdt),
758 PFID(mdt_object_fid(o)), rc);
763 if (likely(ma->ma_valid & MA_INODE))
764 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
768 if (mdt_body_has_lov(la, reqbody)) {
769 if (ma->ma_valid & MA_LOV) {
770 LASSERT(ma->ma_lmm_size);
771 mdt_dump_lmm(D_INFO, ma->ma_lmm);
772 repbody->eadatasize = ma->ma_lmm_size;
773 if (S_ISDIR(la->la_mode))
774 repbody->valid |= OBD_MD_FLDIREA;
776 repbody->valid |= OBD_MD_FLEASIZE;
778 if (ma->ma_valid & MA_LMV) {
779 LASSERT(S_ISDIR(la->la_mode));
780 repbody->eadatasize = ma->ma_lmv_size;
781 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
783 } else if (S_ISLNK(la->la_mode) &&
784 reqbody->valid & OBD_MD_LINKNAME) {
785 buffer->lb_buf = ma->ma_lmm;
786 /* eadatasize from client includes NULL-terminator, so
787 * there is no need to read it */
788 buffer->lb_len = reqbody->eadatasize - 1;
789 rc = mo_readlink(env, next, buffer);
790 if (unlikely(rc <= 0)) {
791 CERROR("%s: readlink failed for "DFID": rc = %d\n",
792 mdt_obd_name(info->mti_mdt),
793 PFID(mdt_object_fid(o)), rc);
796 int print_limit = min_t(int, PAGE_CACHE_SIZE - 128, rc);
798 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
800 repbody->valid |= OBD_MD_LINKNAME;
801 /* we need to report back size with NULL-terminator
802 * because client expects that */
803 repbody->eadatasize = rc + 1;
804 if (repbody->eadatasize != reqbody->eadatasize)
805 CDEBUG(D_INODE, "%s: Read shorter symlink %d "
806 "on "DFID ", expected %d\n",
807 mdt_obd_name(info->mti_mdt),
808 rc, PFID(mdt_object_fid(o)),
809 reqbody->eadatasize - 1);
811 ((char *)ma->ma_lmm)[rc] = 0;
813 /* If the total CDEBUG() size is larger than a page, it
814 * will print a warning to the console, avoid this by
815 * printing just the last part of the symlink. */
816 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
817 print_limit < rc ? "..." : "", print_limit,
818 (char *)ma->ma_lmm + rc - print_limit, rc);
823 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
824 repbody->max_cookiesize = 0;
825 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
826 repbody->valid |= OBD_MD_FLMODEASIZE;
827 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
828 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
829 repbody->max_cookiesize);
832 if (exp_connect_rmtclient(info->mti_exp) &&
833 reqbody->valid & OBD_MD_FLRMTPERM) {
834 void *buf = req_capsule_server_get(pill, &RMF_ACL);
836 /* mdt_getattr_lock only */
837 rc = mdt_pack_remote_perm(info, o, buf);
839 repbody->valid &= ~OBD_MD_FLRMTPERM;
840 repbody->aclsize = 0;
843 repbody->valid |= OBD_MD_FLRMTPERM;
844 repbody->aclsize = sizeof(struct mdt_remote_perm);
847 #ifdef CONFIG_FS_POSIX_ACL
848 else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
849 (reqbody->valid & OBD_MD_FLACL)) {
850 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
851 buffer->lb_len = req_capsule_get_size(pill,
852 &RMF_ACL, RCL_SERVER);
853 if (buffer->lb_len > 0) {
854 rc = mo_xattr_get(env, next, buffer,
855 XATTR_NAME_ACL_ACCESS);
857 if (rc == -ENODATA) {
858 repbody->aclsize = 0;
859 repbody->valid |= OBD_MD_FLACL;
861 } else if (rc == -EOPNOTSUPP) {
864 CERROR("%s: unable to read "DFID
866 mdt_obd_name(info->mti_mdt),
867 PFID(mdt_object_fid(o)), rc);
870 repbody->aclsize = rc;
871 repbody->valid |= OBD_MD_FLACL;
878 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
879 info->mti_mdt->mdt_opts.mo_mds_capa &&
880 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
881 struct lustre_capa *capa;
883 capa = req_capsule_server_get(pill, &RMF_CAPA1);
885 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
886 rc = mo_capa_get(env, next, capa, 0);
889 repbody->valid |= OBD_MD_FLMDSCAPA;
894 mdt_counter_incr(req, LPROC_MDT_GETATTR);
899 static int mdt_renew_capa(struct mdt_thread_info *info)
901 struct mdt_object *obj = info->mti_object;
902 struct mdt_body *body;
903 struct lustre_capa *capa, *c;
907 /* if object doesn't exist, or server has disabled capability,
908 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
911 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
912 !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA))
915 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
916 LASSERT(body != NULL);
918 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
921 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
925 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
927 body->valid |= OBD_MD_FLOSSCAPA;
931 int mdt_getattr(struct mdt_thread_info *info)
933 struct mdt_object *obj = info->mti_object;
934 struct req_capsule *pill = info->mti_pill;
935 struct mdt_body *reqbody;
936 struct mdt_body *repbody;
941 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
944 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
945 rc = req_capsule_server_pack(pill);
947 RETURN(err_serious(rc));
948 rc = mdt_renew_capa(info);
949 GOTO(out_shrink, rc);
952 LASSERT(obj != NULL);
953 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
955 mode = lu_object_attr(&obj->mot_obj.mo_lu);
957 /* old clients may not report needed easize, use max value then */
958 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
959 reqbody->eadatasize == 0 ?
960 info->mti_mdt->mdt_max_mdsize :
961 reqbody->eadatasize);
963 rc = req_capsule_server_pack(pill);
964 if (unlikely(rc != 0))
965 RETURN(err_serious(rc));
967 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
968 LASSERT(repbody != NULL);
969 repbody->eadatasize = 0;
970 repbody->aclsize = 0;
972 if (reqbody->valid & OBD_MD_FLRMTPERM)
973 rc = mdt_init_ucred(info, reqbody);
975 rc = mdt_check_ucred(info);
977 GOTO(out_shrink, rc);
979 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
982 * Don't check capability at all, because rename might getattr for
983 * remote obj, and at that time no capability is available.
985 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
986 rc = mdt_getattr_internal(info, obj, 0);
987 if (reqbody->valid & OBD_MD_FLRMTPERM)
988 mdt_exit_ucred(info);
991 mdt_client_compatibility(info);
992 rc2 = mdt_fix_reply(info);
998 int mdt_is_subdir(struct mdt_thread_info *info)
1000 struct mdt_object *o = info->mti_object;
1001 struct req_capsule *pill = info->mti_pill;
1002 const struct mdt_body *body = info->mti_body;
1003 struct mdt_body *repbody;
1009 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1012 * We save last checked parent fid to @repbody->fid1 for remote
1015 LASSERT(fid_is_sane(&body->fid2));
1016 LASSERT(mdt_object_exists(o) && !mdt_object_remote(o));
1017 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
1018 &body->fid2, &repbody->fid1);
1019 if (rc == 0 || rc == -EREMOTE)
1020 repbody->valid |= OBD_MD_FLID;
1025 int mdt_swap_layouts(struct mdt_thread_info *info)
1027 struct ptlrpc_request *req = mdt_info_req(info);
1028 struct obd_export *exp = req->rq_export;
1029 struct mdt_object *o1, *o2, *o;
1030 struct mdt_lock_handle *lh1, *lh2;
1031 struct mdc_swap_layouts *msl;
1035 /* client does not support layout lock, so layout swaping
1037 * FIXME: there is a problem for old clients which don't support
1038 * layout lock yet. If those clients have already opened the file
1039 * they won't be notified at all so that old layout may still be
1040 * used to do IO. This can be fixed after file release is landed by
1041 * doing exclusive open and taking full EX ibits lock. - Jinshan */
1042 if (!exp_connect_layout(exp))
1043 RETURN(-EOPNOTSUPP);
1045 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT))
1046 mdt_set_capainfo(info, 0, &info->mti_body->fid1,
1047 req_capsule_client_get(info->mti_pill,
1050 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA2, RCL_CLIENT))
1051 mdt_set_capainfo(info, 1, &info->mti_body->fid2,
1052 req_capsule_client_get(info->mti_pill,
1055 o1 = info->mti_object;
1056 o = o2 = mdt_object_find(info->mti_env, info->mti_mdt,
1057 &info->mti_body->fid2);
1059 GOTO(out, rc = PTR_ERR(o));
1061 if (mdt_object_remote(o) || !mdt_object_exists(o)) /* remote object */
1062 GOTO(put, rc = -ENOENT);
1064 rc = lu_fid_cmp(&info->mti_body->fid1, &info->mti_body->fid2);
1065 if (unlikely(rc == 0)) /* same file, you kidding me? no-op. */
1071 /* permission check. Make sure the calling process having permission
1072 * to write both files. */
1073 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o1), NULL,
1078 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o2), NULL,
1083 msl = req_capsule_client_get(info->mti_pill, &RMF_SWAP_LAYOUTS);
1085 GOTO(put, rc = -EPROTO);
1087 lh1 = &info->mti_lh[MDT_LH_NEW];
1088 mdt_lock_reg_init(lh1, LCK_EX);
1089 lh2 = &info->mti_lh[MDT_LH_OLD];
1090 mdt_lock_reg_init(lh2, LCK_EX);
1092 rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT,
1097 rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT,
1102 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
1103 mdt_object_child(o2), msl->msl_flags);
1106 mdt_object_unlock(info, o2, lh2, rc);
1108 mdt_object_unlock(info, o1, lh1, rc);
1110 mdt_object_put(info->mti_env, o);
1115 static int mdt_raw_lookup(struct mdt_thread_info *info,
1116 struct mdt_object *parent,
1117 const struct lu_name *lname,
1118 struct ldlm_reply *ldlm_rep)
1120 struct md_object *next = mdt_object_child(info->mti_object);
1121 const struct mdt_body *reqbody = info->mti_body;
1122 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1123 struct mdt_body *repbody;
1127 if (reqbody->valid != OBD_MD_FLID)
1130 LASSERT(!info->mti_cross_ref);
1132 /* Only got the fid of this obj by name */
1133 fid_zero(child_fid);
1134 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1137 /* XXX is raw_lookup possible as intent operation? */
1140 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1143 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1145 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1148 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1149 repbody->fid1 = *child_fid;
1150 repbody->valid = OBD_MD_FLID;
1156 * UPDATE lock should be taken against parent, and be release before exit;
1157 * child_bits lock should be taken against child, and be returned back:
1158 * (1)normal request should release the child lock;
1159 * (2)intent request will grant the lock to client.
1161 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
1162 struct mdt_lock_handle *lhc,
1164 struct ldlm_reply *ldlm_rep)
1166 struct ptlrpc_request *req = mdt_info_req(info);
1167 struct mdt_body *reqbody = NULL;
1168 struct mdt_object *parent = info->mti_object;
1169 struct mdt_object *child;
1170 struct md_object *next = mdt_object_child(parent);
1171 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1172 struct lu_name *lname = NULL;
1173 const char *name = NULL;
1175 struct mdt_lock_handle *lhp = NULL;
1176 struct ldlm_lock *lock;
1177 struct ldlm_res_id *res_id;
1184 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
1185 LASSERT(ergo(is_resent,
1186 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
1188 LASSERT(parent != NULL);
1189 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
1191 RETURN(err_serious(-EFAULT));
1193 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
1195 if (!info->mti_cross_ref) {
1197 * XXX: Check for "namelen == 0" is for getattr by fid
1198 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
1199 * that is the name must contain at least one character and
1200 * the terminating '\0'
1203 reqbody = req_capsule_client_get(info->mti_pill,
1205 if (unlikely(reqbody == NULL))
1206 RETURN(err_serious(-EFAULT));
1208 if (unlikely(!fid_is_sane(&reqbody->fid2)))
1209 RETURN(err_serious(-EINVAL));
1212 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
1214 PFID(mdt_object_fid(parent)),
1215 PFID(&reqbody->fid2), ldlm_rep);
1217 lname = mdt_name(info->mti_env, (char *)name, namelen);
1218 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
1219 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
1223 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
1225 if (unlikely(!mdt_object_exists(parent))) {
1226 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1227 &parent->mot_obj.mo_lu,
1228 "Parent doesn't exist!\n");
1230 } else if (!info->mti_cross_ref) {
1231 LASSERTF(!mdt_object_remote(parent),
1232 "Parent "DFID" is on remote server\n",
1233 PFID(mdt_object_fid(parent)));
1236 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
1244 if (info->mti_cross_ref) {
1245 /* Only getattr on the child. Parent is on another node. */
1246 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1248 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
1249 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
1252 /* Do not take lock for resent case. */
1253 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1254 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1255 lhc->mlh_reg_lh.cookie);
1256 LASSERT(fid_res_name_eq(mdt_object_fid(child),
1257 &lock->l_resource->lr_name));
1258 LDLM_LOCK_PUT(lock);
1261 mdt_lock_handle_init(lhc);
1262 mdt_lock_reg_init(lhc, LCK_PR);
1265 * Object's name is on another MDS, no lookup lock is
1266 * needed here but update is.
1268 child_bits &= ~MDS_INODELOCK_LOOKUP;
1269 child_bits |= MDS_INODELOCK_PERM | MDS_INODELOCK_UPDATE;
1271 rc = mdt_object_lock(info, child, lhc, child_bits,
1275 /* Finally, we can get attr for child. */
1276 mdt_set_capainfo(info, 0, mdt_object_fid(child),
1278 rc = mdt_getattr_internal(info, child, 0);
1279 if (unlikely(rc != 0))
1280 mdt_object_unlock(info, child, lhc, 1);
1286 /* step 1: lock parent only if parent is a directory */
1287 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
1288 lhp = &info->mti_lh[MDT_LH_PARENT];
1289 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
1290 rc = mdt_object_lock(info, parent, lhp,
1291 MDS_INODELOCK_UPDATE,
1293 if (unlikely(rc != 0))
1297 /* step 2: lookup child's fid by name */
1298 fid_zero(child_fid);
1299 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1304 mdt_set_disposition(info, ldlm_rep,
1306 GOTO(out_parent, rc);
1308 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1310 *child_fid = reqbody->fid2;
1311 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1315 *step 3: find the child object by fid & lock it.
1316 * regardless if it is local or remote.
1318 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1320 if (unlikely(IS_ERR(child)))
1321 GOTO(out_parent, rc = PTR_ERR(child));
1323 /* Do not take lock for resent case. */
1324 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1325 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1326 lhc->mlh_reg_lh.cookie);
1328 res_id = &lock->l_resource->lr_name;
1329 if (!fid_res_name_eq(mdt_object_fid(child),
1330 &lock->l_resource->lr_name)) {
1331 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1332 &lock->l_resource->lr_name),
1333 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1334 (unsigned long)res_id->name[0],
1335 (unsigned long)res_id->name[1],
1336 (unsigned long)res_id->name[2],
1337 PFID(mdt_object_fid(parent)));
1338 CWARN("Although resent, but still not get child lock"
1339 "parent:"DFID" child:"DFID"\n",
1340 PFID(mdt_object_fid(parent)),
1341 PFID(mdt_object_fid(child)));
1342 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1343 LDLM_LOCK_PUT(lock);
1346 LDLM_LOCK_PUT(lock);
1349 bool try_layout = false;
1352 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1353 mdt_lock_handle_init(lhc);
1354 mdt_lock_reg_init(lhc, LCK_PR);
1356 if (!mdt_object_exists(child)) {
1357 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1358 &child->mot_obj.mo_lu,
1359 "Object doesn't exist!\n");
1360 GOTO(out_child, rc = -ENOENT);
1363 if (!(child_bits & MDS_INODELOCK_UPDATE) &&
1364 mdt_object_exists(child) && !mdt_object_remote(child)) {
1365 struct md_attr *ma = &info->mti_attr;
1368 ma->ma_need = MA_INODE;
1369 rc = mdt_attr_get_complex(info, child, ma);
1370 if (unlikely(rc != 0))
1371 GOTO(out_child, rc);
1373 /* If the file has not been changed for some time, we
1374 * return not only a LOOKUP lock, but also an UPDATE
1375 * lock and this might save us RPC on later STAT. For
1376 * directories, it also let negative dentry starts
1377 * working for this dir. */
1378 if (ma->ma_valid & MA_INODE &&
1379 ma->ma_attr.la_valid & LA_CTIME &&
1380 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1381 ma->ma_attr.la_ctime < cfs_time_current_sec())
1382 child_bits |= MDS_INODELOCK_UPDATE;
1385 /* layout lock must be granted in a best-effort way
1386 * for IT operations */
1387 LASSERT(!(child_bits & MDS_INODELOCK_LAYOUT));
1388 if (!OBD_FAIL_CHECK(OBD_FAIL_MDS_NO_LL_GETATTR) &&
1389 exp_connect_layout(info->mti_exp) &&
1390 S_ISREG(lu_object_attr(&child->mot_obj.mo_lu)) &&
1392 /* try to grant layout lock for regular file. */
1398 child_bits |= MDS_INODELOCK_LAYOUT;
1399 /* try layout lock, it may fail to be granted due to
1400 * contention at LOOKUP or UPDATE */
1401 if (!mdt_object_lock_try(info, child, lhc, child_bits,
1403 child_bits &= ~MDS_INODELOCK_LAYOUT;
1404 LASSERT(child_bits != 0);
1405 rc = mdt_object_lock(info, child, lhc,
1406 child_bits, MDT_CROSS_LOCK);
1411 rc = mdt_object_lock(info, child, lhc, child_bits,
1414 if (unlikely(rc != 0))
1415 GOTO(out_child, rc);
1418 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1419 /* Get MA_SOM attributes if update lock is given. */
1421 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1422 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1425 /* finally, we can get attr for child. */
1426 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1427 rc = mdt_getattr_internal(info, child, ma_need);
1428 if (unlikely(rc != 0)) {
1429 mdt_object_unlock(info, child, lhc, 1);
1431 /* Debugging code. */
1432 res_id = &lock->l_resource->lr_name;
1433 LDLM_DEBUG(lock, "Returning lock to client");
1434 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1435 &lock->l_resource->lr_name),
1436 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1437 (unsigned long)res_id->name[0],
1438 (unsigned long)res_id->name[1],
1439 (unsigned long)res_id->name[2],
1440 PFID(mdt_object_fid(child)));
1441 if (mdt_object_exists(child) && !mdt_object_remote(child))
1442 mdt_pack_size2body(info, child);
1445 LDLM_LOCK_PUT(lock);
1449 mdt_object_put(info->mti_env, child);
1452 mdt_object_unlock(info, parent, lhp, 1);
1456 /* normal handler: should release the child lock */
1457 int mdt_getattr_name(struct mdt_thread_info *info)
1459 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1460 struct mdt_body *reqbody;
1461 struct mdt_body *repbody;
1465 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1466 LASSERT(reqbody != NULL);
1467 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1468 LASSERT(repbody != NULL);
1470 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1471 repbody->eadatasize = 0;
1472 repbody->aclsize = 0;
1474 rc = mdt_init_ucred(info, reqbody);
1476 GOTO(out_shrink, rc);
1478 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1479 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1480 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1481 lhc->mlh_reg_lh.cookie = 0;
1483 mdt_exit_ucred(info);
1486 mdt_client_compatibility(info);
1487 rc2 = mdt_fix_reply(info);
1493 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1494 void *karg, void *uarg);
1496 int mdt_set_info(struct mdt_thread_info *info)
1498 struct ptlrpc_request *req = mdt_info_req(info);
1501 int keylen, vallen, rc = 0;
1504 rc = req_capsule_server_pack(info->mti_pill);
1508 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1510 DEBUG_REQ(D_HA, req, "no set_info key");
1514 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1517 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1519 DEBUG_REQ(D_HA, req, "no set_info val");
1523 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1526 /* Swab any part of val you need to here */
1527 if (KEY_IS(KEY_READ_ONLY)) {
1529 lustre_msg_set_status(req->rq_repmsg, 0);
1531 spin_lock(&req->rq_export->exp_lock);
1533 *exp_connect_flags_ptr(req->rq_export) |=
1536 *exp_connect_flags_ptr(req->rq_export) &=
1537 ~OBD_CONNECT_RDONLY;
1538 spin_unlock(&req->rq_export->exp_lock);
1540 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1541 struct changelog_setinfo *cs =
1542 (struct changelog_setinfo *)val;
1543 if (vallen != sizeof(*cs)) {
1544 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1547 if (ptlrpc_req_need_swab(req)) {
1548 __swab64s(&cs->cs_recno);
1549 __swab32s(&cs->cs_id);
1552 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1554 lustre_msg_set_status(req->rq_repmsg, rc);
1563 * Top-level handler for MDT connection requests.
1565 int mdt_connect(struct mdt_thread_info *info)
1568 struct obd_connect_data *reply;
1569 struct obd_export *exp;
1570 struct ptlrpc_request *req = mdt_info_req(info);
1572 rc = target_handle_connect(req);
1574 return err_serious(rc);
1576 LASSERT(req->rq_export != NULL);
1577 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1578 rc = mdt_init_sec_level(info);
1580 obd_disconnect(class_export_get(req->rq_export));
1584 /* To avoid exposing partially initialized connection flags, changes up
1585 * to this point have been staged in reply->ocd_connect_flags. Now that
1586 * connection handling has completed successfully, atomically update
1587 * the connect flags in the shared export data structure. LU-1623 */
1588 reply = req_capsule_server_get(info->mti_pill, &RMF_CONNECT_DATA);
1589 exp = req->rq_export;
1590 spin_lock(&exp->exp_lock);
1591 *exp_connect_flags_ptr(exp) = reply->ocd_connect_flags;
1592 spin_unlock(&exp->exp_lock);
1594 rc = mdt_init_idmap(info);
1596 obd_disconnect(class_export_get(req->rq_export));
1601 int mdt_disconnect(struct mdt_thread_info *info)
1606 rc = target_handle_disconnect(mdt_info_req(info));
1608 rc = err_serious(rc);
1612 static int mdt_sendpage(struct mdt_thread_info *info,
1613 struct lu_rdpg *rdpg, int nob)
1615 struct ptlrpc_request *req = mdt_info_req(info);
1616 struct obd_export *exp = req->rq_export;
1617 struct ptlrpc_bulk_desc *desc;
1618 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1625 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, 1, BULK_PUT_SOURCE,
1630 if (!(exp_connect_flags(exp) & OBD_CONNECT_BRW_SIZE))
1631 /* old client requires reply size in it's PAGE_SIZE,
1632 * which is rdpg->rp_count */
1633 nob = rdpg->rp_count;
1635 for (i = 0, tmpcount = nob; i < rdpg->rp_npages && tmpcount > 0;
1636 i++, tmpcount -= tmpsize) {
1637 tmpsize = min_t(int, tmpcount, PAGE_CACHE_SIZE);
1638 ptlrpc_prep_bulk_page_pin(desc, rdpg->rp_pages[i], 0, tmpsize);
1641 LASSERT(desc->bd_nob == nob);
1642 rc = target_bulk_io(exp, desc, lwi);
1643 ptlrpc_free_bulk_pin(desc);
1647 int mdt_readpage(struct mdt_thread_info *info)
1649 struct mdt_object *object = info->mti_object;
1650 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1651 struct mdt_body *reqbody;
1652 struct mdt_body *repbody;
1657 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1658 RETURN(err_serious(-ENOMEM));
1660 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1661 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1662 if (reqbody == NULL || repbody == NULL)
1663 RETURN(err_serious(-EFAULT));
1666 * prepare @rdpg before calling lower layers and transfer itself. Here
1667 * reqbody->size contains offset of where to start to read and
1668 * reqbody->nlink contains number bytes to read.
1670 rdpg->rp_hash = reqbody->size;
1671 if (rdpg->rp_hash != reqbody->size) {
1672 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1673 rdpg->rp_hash, reqbody->size);
1677 rdpg->rp_attrs = reqbody->mode;
1678 if (exp_connect_flags(info->mti_exp) & OBD_CONNECT_64BITHASH)
1679 rdpg->rp_attrs |= LUDA_64BITHASH;
1680 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1681 exp_max_brw_size(info->mti_exp));
1682 rdpg->rp_npages = (rdpg->rp_count + PAGE_CACHE_SIZE - 1) >>
1684 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1685 if (rdpg->rp_pages == NULL)
1688 for (i = 0; i < rdpg->rp_npages; ++i) {
1689 rdpg->rp_pages[i] = alloc_page(GFP_IOFS);
1690 if (rdpg->rp_pages[i] == NULL)
1691 GOTO(free_rdpg, rc = -ENOMEM);
1694 /* call lower layers to fill allocated pages with directory data */
1695 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1697 GOTO(free_rdpg, rc);
1699 /* send pages to client */
1700 rc = mdt_sendpage(info, rdpg, rc);
1705 for (i = 0; i < rdpg->rp_npages; i++)
1706 if (rdpg->rp_pages[i] != NULL)
1707 __free_page(rdpg->rp_pages[i]);
1708 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1710 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1716 static int mdt_reint_internal(struct mdt_thread_info *info,
1717 struct mdt_lock_handle *lhc,
1720 struct req_capsule *pill = info->mti_pill;
1721 struct mdt_body *repbody;
1726 rc = mdt_reint_unpack(info, op);
1728 CERROR("Can't unpack reint, rc %d\n", rc);
1729 RETURN(err_serious(rc));
1732 /* for replay (no_create) lmm is not needed, client has it already */
1733 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1734 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1735 info->mti_rr.rr_eadatalen);
1737 /* llog cookies are always 0, the field is kept for compatibility */
1738 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1739 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, 0);
1741 rc = req_capsule_server_pack(pill);
1743 CERROR("Can't pack response, rc %d\n", rc);
1744 RETURN(err_serious(rc));
1747 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1748 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1750 repbody->eadatasize = 0;
1751 repbody->aclsize = 0;
1754 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1756 /* for replay no cookkie / lmm need, because client have this already */
1757 if (info->mti_spec.no_create)
1758 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1759 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1761 rc = mdt_init_ucred_reint(info);
1763 GOTO(out_shrink, rc);
1765 rc = mdt_fix_attr_ucred(info, op);
1767 GOTO(out_ucred, rc = err_serious(rc));
1769 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1770 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1771 GOTO(out_ucred, rc);
1773 rc = mdt_reint_rec(info, lhc);
1776 mdt_exit_ucred(info);
1778 mdt_client_compatibility(info);
1779 rc2 = mdt_fix_reply(info);
1785 static long mdt_reint_opcode(struct mdt_thread_info *info,
1786 const struct req_format **fmt)
1788 struct mdt_rec_reint *rec;
1791 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1793 opc = rec->rr_opcode;
1794 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1795 if (opc < REINT_MAX && fmt[opc] != NULL)
1796 req_capsule_extend(info->mti_pill, fmt[opc]);
1798 CERROR("%s: Unsupported opcode '%ld' from client '%s': "
1799 "rc = %d\n", mdt_obd_name(info->mti_mdt), opc,
1800 info->mti_mdt->mdt_ldlm_client->cli_name,
1802 opc = err_serious(-EFAULT);
1805 opc = err_serious(-EFAULT);
1810 int mdt_reint(struct mdt_thread_info *info)
1815 static const struct req_format *reint_fmts[REINT_MAX] = {
1816 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1817 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1818 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1819 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1820 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1821 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1822 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR,
1823 [REINT_RMENTRY] = &RQF_MDS_REINT_UNLINK
1828 opc = mdt_reint_opcode(info, reint_fmts);
1831 * No lock possible here from client to pass it to reint code
1834 rc = mdt_reint_internal(info, NULL, opc);
1839 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1843 /* this should sync the whole device */
1844 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1846 struct dt_device *dt = mdt->mdt_bottom;
1850 rc = dt->dd_ops->dt_sync(env, dt);
1854 /* this should sync this object */
1855 static int mdt_object_sync(struct mdt_thread_info *info)
1857 struct md_object *next;
1861 if (!mdt_object_exists(info->mti_object)) {
1862 CWARN("Non existing object "DFID"!\n",
1863 PFID(mdt_object_fid(info->mti_object)));
1866 next = mdt_object_child(info->mti_object);
1867 rc = mo_object_sync(info->mti_env, next);
1872 int mdt_sync(struct mdt_thread_info *info)
1874 struct ptlrpc_request *req = mdt_info_req(info);
1875 struct req_capsule *pill = info->mti_pill;
1876 struct mdt_body *body;
1880 /* The fid may be zero, so we req_capsule_set manually */
1881 req_capsule_set(pill, &RQF_MDS_SYNC);
1883 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1885 RETURN(err_serious(-EINVAL));
1887 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1888 RETURN(err_serious(-ENOMEM));
1890 if (fid_seq(&body->fid1) == 0) {
1891 /* sync the whole device */
1892 rc = req_capsule_server_pack(pill);
1894 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1896 rc = err_serious(rc);
1898 /* sync an object */
1899 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1901 rc = mdt_object_sync(info);
1903 const struct lu_fid *fid;
1904 struct lu_attr *la = &info->mti_attr.ma_attr;
1906 info->mti_attr.ma_need = MA_INODE;
1907 info->mti_attr.ma_valid = 0;
1908 rc = mdt_attr_get_complex(info, info->mti_object,
1911 body = req_capsule_server_get(pill,
1913 fid = mdt_object_fid(info->mti_object);
1914 mdt_pack_attr2body(info, body, la, fid);
1918 rc = err_serious(rc);
1921 mdt_counter_incr(req, LPROC_MDT_SYNC);
1927 * Quotacheck handler.
1928 * in-kernel quotacheck isn't supported any more.
1930 int mdt_quotacheck(struct mdt_thread_info *info)
1932 struct obd_quotactl *oqctl;
1936 oqctl = req_capsule_client_get(info->mti_pill, &RMF_OBD_QUOTACTL);
1938 RETURN(err_serious(-EPROTO));
1940 rc = req_capsule_server_pack(info->mti_pill);
1942 RETURN(err_serious(rc));
1944 /* deprecated, not used any more */
1945 RETURN(-EOPNOTSUPP);
1949 * Handle quota control requests to consult current usage/limit, but also
1950 * to configure quota enforcement
1952 int mdt_quotactl(struct mdt_thread_info *info)
1954 struct obd_export *exp = info->mti_exp;
1955 struct req_capsule *pill = info->mti_pill;
1956 struct obd_quotactl *oqctl, *repoqc;
1958 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
1961 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1963 RETURN(err_serious(-EPROTO));
1965 rc = req_capsule_server_pack(pill);
1967 RETURN(err_serious(rc));
1969 switch (oqctl->qc_cmd) {
1971 case LUSTRE_Q_INVALIDATE:
1972 case LUSTRE_Q_FINVALIDATE:
1976 /* deprecated, not used any more */
1977 RETURN(-EOPNOTSUPP);
1978 /* master quotactl */
1984 RETURN(-EOPNOTSUPP);
1985 /* slave quotactl */
1990 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
1994 /* map uid/gid for remote client */
1996 if (exp_connect_rmtclient(exp)) {
1997 struct lustre_idmap_table *idmap;
1999 idmap = mdt_req2med(mdt_info_req(info))->med_idmap;
2001 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
2002 oqctl->qc_cmd != Q_GETINFO))
2005 if (oqctl->qc_type == USRQUOTA)
2006 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
2008 else if (oqctl->qc_type == GRPQUOTA)
2009 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
2014 if (id == CFS_IDMAP_NOTFOUND) {
2015 CDEBUG(D_QUOTA, "no mapping for id %u\n", oqctl->qc_id);
2020 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
2022 RETURN(err_serious(-EFAULT));
2024 if (oqctl->qc_id != id)
2025 swap(oqctl->qc_id, id);
2027 switch (oqctl->qc_cmd) {
2033 /* forward quotactl request to QMT */
2034 rc = qmt_hdls.qmth_quotactl(info->mti_env, qmt, oqctl);
2039 /* slave quotactl */
2040 rc = lquotactl_slv(info->mti_env, info->mti_mdt->mdt_bottom,
2045 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2049 if (oqctl->qc_id != id)
2050 swap(oqctl->qc_id, id);
2057 * OBD PING and other handlers.
2059 int mdt_obd_ping(struct mdt_thread_info *info)
2064 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
2066 rc = target_handle_ping(mdt_info_req(info));
2068 rc = err_serious(rc);
2073 * OBD_IDX_READ handler
2075 int mdt_obd_idx_read(struct mdt_thread_info *info)
2077 struct mdt_device *mdt = info->mti_mdt;
2078 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
2079 struct idx_info *req_ii, *rep_ii;
2083 memset(rdpg, 0, sizeof(*rdpg));
2084 req_capsule_set(info->mti_pill, &RQF_OBD_IDX_READ);
2086 /* extract idx_info buffer from request & reply */
2087 req_ii = req_capsule_client_get(info->mti_pill, &RMF_IDX_INFO);
2088 if (req_ii == NULL || req_ii->ii_magic != IDX_INFO_MAGIC)
2089 RETURN(err_serious(-EPROTO));
2091 rc = req_capsule_server_pack(info->mti_pill);
2093 RETURN(err_serious(rc));
2095 rep_ii = req_capsule_server_get(info->mti_pill, &RMF_IDX_INFO);
2097 RETURN(err_serious(-EFAULT));
2098 rep_ii->ii_magic = IDX_INFO_MAGIC;
2100 /* extract hash to start with */
2101 rdpg->rp_hash = req_ii->ii_hash_start;
2103 /* extract requested attributes */
2104 rdpg->rp_attrs = req_ii->ii_attrs;
2106 /* check that fid packed in request is valid and supported */
2107 if (!fid_is_sane(&req_ii->ii_fid))
2109 rep_ii->ii_fid = req_ii->ii_fid;
2112 rep_ii->ii_flags = req_ii->ii_flags;
2114 /* compute number of pages to allocate, ii_count is the number of 4KB
2116 if (req_ii->ii_count <= 0)
2117 GOTO(out, rc = -EFAULT);
2118 rdpg->rp_count = min_t(unsigned int, req_ii->ii_count << LU_PAGE_SHIFT,
2119 exp_max_brw_size(info->mti_exp));
2120 rdpg->rp_npages = (rdpg->rp_count + PAGE_CACHE_SIZE - 1) >>
2123 /* allocate pages to store the containers */
2124 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2125 if (rdpg->rp_pages == NULL)
2126 GOTO(out, rc = -ENOMEM);
2127 for (i = 0; i < rdpg->rp_npages; i++) {
2128 rdpg->rp_pages[i] = alloc_page(GFP_IOFS);
2129 if (rdpg->rp_pages[i] == NULL)
2130 GOTO(out, rc = -ENOMEM);
2133 /* populate pages with key/record pairs */
2134 rc = dt_index_read(info->mti_env, mdt->mdt_bottom, rep_ii, rdpg);
2138 LASSERTF(rc <= rdpg->rp_count, "dt_index_read() returned more than "
2139 "asked %d > %d\n", rc, rdpg->rp_count);
2141 /* send pages to client */
2142 rc = mdt_sendpage(info, rdpg, rc);
2146 if (rdpg->rp_pages) {
2147 for (i = 0; i < rdpg->rp_npages; i++)
2148 if (rdpg->rp_pages[i])
2149 __free_page(rdpg->rp_pages[i]);
2150 OBD_FREE(rdpg->rp_pages,
2151 rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2156 int mdt_obd_log_cancel(struct mdt_thread_info *info)
2158 return err_serious(-EOPNOTSUPP);
2161 int mdt_obd_qc_callback(struct mdt_thread_info *info)
2163 return err_serious(-EOPNOTSUPP);
2170 /** clone llog ctxt from child (mdd)
2171 * This allows remote llog (replicator) access.
2172 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
2173 * context was originally set up, or we can handle them directly.
2174 * I choose the latter, but that means I need any llog
2175 * contexts set up by child to be accessable by the mdt. So we clone the
2176 * context into our context list here.
2178 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
2181 struct md_device *next = mdt->mdt_child;
2182 struct llog_ctxt *ctxt;
2185 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
2188 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
2189 if (rc || ctxt == NULL) {
2193 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2195 CERROR("Can't set mdt ctxt %d\n", rc);
2200 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2201 struct mdt_device *mdt, int idx)
2203 struct llog_ctxt *ctxt;
2205 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2208 /* Put once for the get we just did, and once for the clone */
2209 llog_ctxt_put(ctxt);
2210 llog_ctxt_put(ctxt);
2214 int mdt_llog_create(struct mdt_thread_info *info)
2218 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
2219 rc = llog_origin_handle_open(mdt_info_req(info));
2220 return (rc < 0 ? err_serious(rc) : rc);
2223 int mdt_llog_destroy(struct mdt_thread_info *info)
2227 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
2228 rc = llog_origin_handle_destroy(mdt_info_req(info));
2229 return (rc < 0 ? err_serious(rc) : rc);
2232 int mdt_llog_read_header(struct mdt_thread_info *info)
2236 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
2237 rc = llog_origin_handle_read_header(mdt_info_req(info));
2238 return (rc < 0 ? err_serious(rc) : rc);
2241 int mdt_llog_next_block(struct mdt_thread_info *info)
2245 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
2246 rc = llog_origin_handle_next_block(mdt_info_req(info));
2247 return (rc < 0 ? err_serious(rc) : rc);
2250 int mdt_llog_prev_block(struct mdt_thread_info *info)
2254 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
2255 rc = llog_origin_handle_prev_block(mdt_info_req(info));
2256 return (rc < 0 ? err_serious(rc) : rc);
2264 static struct ldlm_callback_suite cbs = {
2265 .lcs_completion = ldlm_server_completion_ast,
2266 .lcs_blocking = ldlm_server_blocking_ast,
2267 .lcs_glimpse = ldlm_server_glimpse_ast
2270 int mdt_enqueue(struct mdt_thread_info *info)
2272 struct ptlrpc_request *req;
2276 * info->mti_dlm_req already contains swapped and (if necessary)
2277 * converted dlm request.
2279 LASSERT(info->mti_dlm_req != NULL);
2281 req = mdt_info_req(info);
2282 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2283 req, info->mti_dlm_req, &cbs);
2284 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2285 return rc ? err_serious(rc) : req->rq_status;
2288 int mdt_convert(struct mdt_thread_info *info)
2291 struct ptlrpc_request *req;
2293 LASSERT(info->mti_dlm_req);
2294 req = mdt_info_req(info);
2295 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2296 return rc ? err_serious(rc) : req->rq_status;
2299 int mdt_bl_callback(struct mdt_thread_info *info)
2301 CERROR("bl callbacks should not happen on MDS\n");
2303 return err_serious(-EOPNOTSUPP);
2306 int mdt_cp_callback(struct mdt_thread_info *info)
2308 CERROR("cp callbacks should not happen on MDS\n");
2310 return err_serious(-EOPNOTSUPP);
2314 * sec context handlers
2316 int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2320 rc = mdt_handle_idmap(info);
2323 struct ptlrpc_request *req = mdt_info_req(info);
2326 opc = lustre_msg_get_opc(req->rq_reqmsg);
2327 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2328 sptlrpc_svc_ctx_invalidate(req);
2331 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2337 * quota request handlers
2339 int mdt_quota_dqacq(struct mdt_thread_info *info)
2341 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
2346 RETURN(err_serious(-EOPNOTSUPP));
2348 rc = qmt_hdls.qmth_dqacq(info->mti_env, qmt, mdt_info_req(info));
2352 static struct mdt_object *mdt_obj(struct lu_object *o)
2354 LASSERT(lu_device_is_mdt(o->lo_dev));
2355 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2358 struct mdt_object *mdt_object_new(const struct lu_env *env,
2359 struct mdt_device *d,
2360 const struct lu_fid *f)
2362 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2363 struct lu_object *o;
2364 struct mdt_object *m;
2367 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2368 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2369 if (unlikely(IS_ERR(o)))
2370 m = (struct mdt_object *)o;
2376 struct mdt_object *mdt_object_find(const struct lu_env *env,
2377 struct mdt_device *d,
2378 const struct lu_fid *f)
2380 struct lu_object *o;
2381 struct mdt_object *m;
2384 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2385 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2386 if (unlikely(IS_ERR(o)))
2387 m = (struct mdt_object *)o;
2394 * Asyncronous commit for mdt device.
2396 * Pass asynchonous commit call down the MDS stack.
2398 * \param env environment
2399 * \param mdt the mdt device
2401 static void mdt_device_commit_async(const struct lu_env *env,
2402 struct mdt_device *mdt)
2404 struct dt_device *dt = mdt->mdt_bottom;
2407 rc = dt->dd_ops->dt_commit_async(env, dt);
2408 if (unlikely(rc != 0))
2409 CWARN("async commit start failed with rc = %d", rc);
2413 * Mark the lock as "synchonous".
2415 * Mark the lock to deffer transaction commit to the unlock time.
2417 * \param lock the lock to mark as "synchonous"
2419 * \see mdt_is_lock_sync
2420 * \see mdt_save_lock
2422 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2424 lock->l_ast_data = (void*)1;
2428 * Check whehter the lock "synchonous" or not.
2430 * \param lock the lock to check
2431 * \retval 1 the lock is "synchonous"
2432 * \retval 0 the lock isn't "synchronous"
2434 * \see mdt_set_lock_sync
2435 * \see mdt_save_lock
2437 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2439 return lock->l_ast_data != NULL;
2443 * Blocking AST for mdt locks.
2445 * Starts transaction commit if in case of COS lock conflict or
2446 * deffers such a commit to the mdt_save_lock.
2448 * \param lock the lock which blocks a request or cancelling lock
2449 * \param desc unused
2450 * \param data unused
2451 * \param flag indicates whether this cancelling or blocking callback
2453 * \see ldlm_blocking_ast_nocheck
2455 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2456 void *data, int flag)
2458 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2459 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2463 if (flag == LDLM_CB_CANCELING)
2465 lock_res_and_lock(lock);
2466 if (lock->l_blocking_ast != mdt_blocking_ast) {
2467 unlock_res_and_lock(lock);
2470 if (mdt_cos_is_enabled(mdt) &&
2471 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2472 lock->l_blocking_lock != NULL &&
2473 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2474 mdt_set_lock_sync(lock);
2476 rc = ldlm_blocking_ast_nocheck(lock);
2478 /* There is no lock conflict if l_blocking_lock == NULL,
2479 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2480 * when the last reference to a local lock was released */
2481 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2484 rc = lu_env_init(&env, LCT_LOCAL);
2485 if (unlikely(rc != 0))
2486 CWARN("lu_env initialization failed with rc = %d,"
2487 "cannot start asynchronous commit\n", rc);
2489 mdt_device_commit_async(&env, mdt);
2495 int mdt_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2496 void *data, int flag)
2498 struct lustre_handle lockh;
2502 case LDLM_CB_BLOCKING:
2503 ldlm_lock2handle(lock, &lockh);
2504 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
2506 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
2510 case LDLM_CB_CANCELING:
2511 LDLM_DEBUG(lock, "Revoke remote lock\n");
2519 int mdt_remote_object_lock(struct mdt_thread_info *mti,
2520 struct mdt_object *o, struct lustre_handle *lh,
2521 ldlm_mode_t mode, __u64 ibits)
2523 struct ldlm_enqueue_info *einfo = &mti->mti_einfo;
2524 ldlm_policy_data_t *policy = &mti->mti_policy;
2528 LASSERT(mdt_object_remote(o));
2530 LASSERT((ibits & MDS_INODELOCK_UPDATE));
2532 memset(einfo, 0, sizeof(*einfo));
2533 einfo->ei_type = LDLM_IBITS;
2534 einfo->ei_mode = mode;
2535 einfo->ei_cb_bl = mdt_md_blocking_ast;
2536 einfo->ei_cb_cp = ldlm_completion_ast;
2538 memset(policy, 0, sizeof(*policy));
2539 policy->l_inodebits.bits = ibits;
2541 rc = mo_object_lock(mti->mti_env, mdt_object_child(o), lh, einfo,
2546 static int mdt_object_lock0(struct mdt_thread_info *info, struct mdt_object *o,
2547 struct mdt_lock_handle *lh, __u64 ibits,
2548 bool nonblock, int locality)
2550 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2551 ldlm_policy_data_t *policy = &info->mti_policy;
2552 struct ldlm_res_id *res_id = &info->mti_res_id;
2557 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2558 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2559 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2560 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2562 if (mdt_object_remote(o)) {
2563 if (locality == MDT_CROSS_LOCK) {
2564 ibits &= ~(MDS_INODELOCK_UPDATE | MDS_INODELOCK_PERM);
2565 ibits |= MDS_INODELOCK_LOOKUP;
2568 (MDS_INODELOCK_UPDATE | MDS_INODELOCK_PERM)),
2569 "%s: wrong bit "LPX64" for remote obj "DFID"\n",
2570 mdt_obd_name(info->mti_mdt), ibits,
2571 PFID(mdt_object_fid(o)));
2572 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2574 /* No PDO lock on remote object */
2575 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2578 if (lh->mlh_type == MDT_PDO_LOCK) {
2579 /* check for exists after object is locked */
2580 if (mdt_object_exists(o) == 0) {
2581 /* Non-existent object shouldn't have PDO lock */
2584 /* Non-dir object shouldn't have PDO lock */
2585 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2590 memset(policy, 0, sizeof(*policy));
2591 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2593 dlmflags = LDLM_FL_ATOMIC_CB;
2595 dlmflags |= LDLM_FL_BLOCK_NOWAIT;
2598 * Take PDO lock on whole directory and build correct @res_id for lock
2599 * on part of directory.
2601 if (lh->mlh_pdo_hash != 0) {
2602 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2603 mdt_lock_pdo_mode(info, o, lh);
2604 if (lh->mlh_pdo_mode != LCK_NL) {
2606 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2607 * is never going to be sent to client and we do not
2608 * want it slowed down due to possible cancels.
2610 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2611 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2612 policy, res_id, dlmflags,
2613 &info->mti_exp->exp_handle.h_cookie);
2619 * Finish res_id initializing by name hash marking part of
2620 * directory which is taking modification.
2622 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2625 policy->l_inodebits.bits = ibits;
2628 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2629 * going to be sent to client. If it is - mdt_intent_policy() path will
2630 * fix it up and turn FL_LOCAL flag off.
2632 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2633 res_id, LDLM_FL_LOCAL_ONLY | dlmflags,
2634 &info->mti_exp->exp_handle.h_cookie);
2636 mdt_object_unlock(info, o, lh, 1);
2637 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2638 lh->mlh_pdo_hash != 0 &&
2639 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2640 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2646 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2647 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2649 return mdt_object_lock0(info, o, lh, ibits, false, locality);
2652 int mdt_object_lock_try(struct mdt_thread_info *info, struct mdt_object *o,
2653 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2655 struct mdt_lock_handle tmp = *lh;
2658 rc = mdt_object_lock0(info, o, &tmp, ibits, true, locality);
2666 * Save a lock within request object.
2668 * Keep the lock referenced until whether client ACK or transaction
2669 * commit happens or release the lock immediately depending on input
2670 * parameters. If COS is ON, a write lock is converted to COS lock
2673 * \param info thead info object
2674 * \param h lock handle
2675 * \param mode lock mode
2676 * \param decref force immediate lock releasing
2679 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2680 ldlm_mode_t mode, int decref)
2684 if (lustre_handle_is_used(h)) {
2685 if (decref || !info->mti_has_trans ||
2686 !(mode & (LCK_PW | LCK_EX))){
2687 mdt_fid_unlock(h, mode);
2689 struct mdt_device *mdt = info->mti_mdt;
2690 struct ldlm_lock *lock = ldlm_handle2lock(h);
2691 struct ptlrpc_request *req = mdt_info_req(info);
2694 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2696 CDEBUG(D_HA, "request = %p reply state = %p"
2697 " transno = "LPD64"\n",
2698 req, req->rq_reply_state, req->rq_transno);
2699 if (mdt_cos_is_enabled(mdt)) {
2701 ldlm_lock_downgrade(lock, LCK_COS);
2704 ptlrpc_save_lock(req, h, mode, no_ack);
2705 if (mdt_is_lock_sync(lock)) {
2706 CDEBUG(D_HA, "found sync-lock,"
2707 " async commit started\n");
2708 mdt_device_commit_async(info->mti_env,
2711 LDLM_LOCK_PUT(lock);
2720 * Unlock mdt object.
2722 * Immeditely release the regular lock and the PDO lock or save the
2723 * lock in reqeuest and keep them referenced until client ACK or
2724 * transaction commit.
2726 * \param info thread info object
2727 * \param o mdt object
2728 * \param lh mdt lock handle referencing regular and PDO locks
2729 * \param decref force immediate lock releasing
2731 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2732 struct mdt_lock_handle *lh, int decref)
2736 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2737 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2739 if (lustre_handle_is_used(&lh->mlh_rreg_lh))
2740 ldlm_lock_decref(&lh->mlh_rreg_lh, lh->mlh_rreg_mode);
2745 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2746 const struct lu_fid *f,
2747 struct mdt_lock_handle *lh,
2750 struct mdt_object *o;
2752 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2756 rc = mdt_object_lock(info, o, lh, ibits,
2759 mdt_object_put(info->mti_env, o);
2766 void mdt_object_unlock_put(struct mdt_thread_info * info,
2767 struct mdt_object * o,
2768 struct mdt_lock_handle *lh,
2771 mdt_object_unlock(info, o, lh, decref);
2772 mdt_object_put(info->mti_env, o);
2775 struct mdt_handler *mdt_handler_find(__u32 opc, struct mdt_opc_slice *supported)
2777 struct mdt_opc_slice *s;
2778 struct mdt_handler *h;
2781 for (s = supported; s->mos_hs != NULL; s++) {
2782 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2783 h = s->mos_hs + (opc - s->mos_opc_start);
2784 if (likely(h->mh_opc != 0))
2785 LASSERTF(h->mh_opc == opc,
2786 "opcode mismatch %d != %d\n",
2789 h = NULL; /* unsupported opc */
2796 static int mdt_lock_resname_compat(struct mdt_device *m,
2797 struct ldlm_request *req)
2799 /* XXX something... later. */
2803 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2805 /* XXX something... later. */
2810 * Generic code handling requests that have struct mdt_body passed in:
2812 * - extract mdt_body from request and save it in @info, if present;
2814 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2817 * - if HABEO_CORPUS flag is set for this request type check whether object
2818 * actually exists on storage (lu_object_exists()).
2821 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2823 const struct mdt_body *body;
2824 struct mdt_object *obj;
2825 const struct lu_env *env;
2826 struct req_capsule *pill;
2830 env = info->mti_env;
2831 pill = info->mti_pill;
2833 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2837 if (!(body->valid & OBD_MD_FLID))
2840 if (!fid_is_sane(&body->fid1)) {
2841 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2846 * Do not get size or any capa fields before we check that request
2847 * contains capa actually. There are some requests which do not, for
2848 * instance MDS_IS_SUBDIR.
2850 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2851 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2852 mdt_set_capainfo(info, 0, &body->fid1,
2853 req_capsule_client_get(pill, &RMF_CAPA1));
2855 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2857 if ((flags & HABEO_CORPUS) &&
2858 !mdt_object_exists(obj)) {
2859 mdt_object_put(env, obj);
2860 /* for capability renew ENOENT will be handled in
2862 if (body->valid & OBD_MD_FLOSSCAPA)
2867 info->mti_object = obj;
2876 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2878 struct req_capsule *pill = info->mti_pill;
2882 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2883 rc = mdt_body_unpack(info, flags);
2887 if (rc == 0 && (flags & HABEO_REFERO)) {
2889 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2890 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2891 info->mti_body->eadatasize);
2892 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2893 req_capsule_set_size(pill, &RMF_LOGCOOKIES,
2896 rc = req_capsule_server_pack(pill);
2901 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2903 struct md_device *next = m->mdt_child;
2905 return next->md_ops->mdo_init_capa_ctxt(env, next,
2906 m->mdt_opts.mo_mds_capa,
2907 m->mdt_capa_timeout,
2913 * Invoke handler for this request opc. Also do necessary preprocessing
2914 * (according to handler ->mh_flags), and post-processing (setting of
2915 * ->last_{xid,committed}).
2917 static int mdt_req_handle(struct mdt_thread_info *info,
2918 struct mdt_handler *h, struct ptlrpc_request *req)
2920 int rc, serious = 0;
2925 LASSERT(h->mh_act != NULL);
2926 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2927 LASSERT(current->journal_info == NULL);
2930 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2931 * to put same checks into handlers like mdt_close(), mdt_reint(),
2932 * etc., without talking to mdt authors first. Checking same thing
2933 * there again is useless and returning 0 error without packing reply
2934 * is buggy! Handlers either pack reply or return error.
2936 * We return 0 here and do not send any reply in order to emulate
2937 * network failure. Do not send any reply in case any of NET related
2938 * fail_id has occured.
2940 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2944 flags = h->mh_flags;
2945 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2947 if (h->mh_fmt != NULL) {
2948 req_capsule_set(info->mti_pill, h->mh_fmt);
2949 rc = mdt_unpack_req_pack_rep(info, flags);
2952 if (rc == 0 && flags & MUTABOR &&
2953 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
2954 /* should it be rq_status? */
2957 if (rc == 0 && flags & HABEO_CLAVIS) {
2958 struct ldlm_request *dlm_req;
2960 LASSERT(h->mh_fmt != NULL);
2962 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2963 if (dlm_req != NULL) {
2964 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2966 dlm_req->lock_desc.l_policy_data.\
2967 l_inodebits.bits == 0)) {
2969 * Lock without inodebits makes no sense and
2970 * will oops later in ldlm. If client miss to
2971 * set such bits, do not trigger ASSERTION.
2973 * For liblustre flock case, it maybe zero.
2977 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2978 rc = mdt_lock_resname_compat(
2981 info->mti_dlm_req = dlm_req;
2988 /* capability setting changed via /proc, needs reinitialize ctxt */
2989 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2990 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2991 info->mti_mdt->mdt_capa_conf = 0;
2994 if (likely(rc == 0)) {
2996 * Process request, there can be two types of rc:
2997 * 1) errors with msg unpack/pack, other failures outside the
2998 * operation itself. This is counted as serious errors;
2999 * 2) errors during fs operation, should be placed in rq_status
3002 rc = h->mh_act(info);
3004 !req->rq_no_reply && req->rq_reply_state == NULL) {
3005 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
3006 "pack reply and returned 0 error\n",
3010 serious = is_serious(rc);
3011 rc = clear_serious(rc);
3015 req->rq_status = rc;
3018 * ELDLM_* codes which > 0 should be in rq_status only as well as
3019 * all non-serious errors.
3021 if (rc > 0 || !serious)
3024 LASSERT(current->journal_info == NULL);
3026 if (rc == 0 && (flags & HABEO_CLAVIS) &&
3027 info->mti_mdt->mdt_opts.mo_compat_resname) {
3028 struct ldlm_reply *dlmrep;
3030 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3032 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
3035 /* If we're DISCONNECTing, the mdt_export_data is already freed */
3036 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
3037 target_committed_to_req(req);
3039 if (unlikely(req_is_replay(req) &&
3040 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
3041 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
3045 target_send_reply(req, rc, info->mti_fail_id);
3049 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
3051 lh->mlh_type = MDT_NUL_LOCK;
3052 lh->mlh_reg_lh.cookie = 0ull;
3053 lh->mlh_reg_mode = LCK_MINMODE;
3054 lh->mlh_pdo_lh.cookie = 0ull;
3055 lh->mlh_pdo_mode = LCK_MINMODE;
3056 lh->mlh_rreg_lh.cookie = 0ull;
3057 lh->mlh_rreg_mode = LCK_MINMODE;
3060 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
3062 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
3063 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
3067 * Initialize fields of struct mdt_thread_info. Other fields are left in
3068 * uninitialized state, because it's too expensive to zero out whole
3069 * mdt_thread_info (> 1K) on each request arrival.
3071 static void mdt_thread_info_init(struct ptlrpc_request *req,
3072 struct mdt_thread_info *info)
3076 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
3077 info->mti_pill = &req->rq_pill;
3080 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
3081 mdt_lock_handle_init(&info->mti_lh[i]);
3083 /* mdt device: it can be NULL while CONNECT */
3084 if (req->rq_export) {
3085 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
3086 info->mti_exp = req->rq_export;
3088 info->mti_mdt = NULL;
3089 info->mti_env = req->rq_svc_thread->t_env;
3090 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
3091 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
3092 info->mti_mos = NULL;
3094 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
3095 info->mti_big_buf = LU_BUF_NULL;
3096 info->mti_body = NULL;
3097 info->mti_object = NULL;
3098 info->mti_dlm_req = NULL;
3099 info->mti_has_trans = 0;
3100 info->mti_cross_ref = 0;
3101 info->mti_opdata = 0;
3102 info->mti_big_lmm_used = 0;
3104 /* To not check for split by default. */
3105 info->mti_spec.no_create = 0;
3106 info->mti_spec.sp_rm_entry = 0;
3109 static void mdt_thread_info_fini(struct mdt_thread_info *info)
3113 req_capsule_fini(info->mti_pill);
3114 if (info->mti_object != NULL) {
3115 mdt_object_put(info->mti_env, info->mti_object);
3116 info->mti_object = NULL;
3119 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
3120 mdt_lock_handle_fini(&info->mti_lh[i]);
3121 info->mti_env = NULL;
3123 if (unlikely(info->mti_big_buf.lb_buf != NULL))
3124 lu_buf_free(&info->mti_big_buf);
3127 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
3128 struct obd_device *obd, int *process)
3130 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3131 case MDS_CONNECT: /* This will never get here, but for completeness. */
3132 case OST_CONNECT: /* This will never get here, but for completeness. */
3133 case MDS_DISCONNECT:
3134 case OST_DISCONNECT:
3140 case MDS_DONE_WRITING:
3141 case MDS_SYNC: /* used in unmounting */
3148 *process = target_queue_recovery_request(req, obd);
3152 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
3159 * Handle recovery. Return:
3160 * +1: continue request processing;
3161 * -ve: abort immediately with the given error code;
3162 * 0: send reply with error code in req->rq_status;
3164 static int mdt_recovery(struct mdt_thread_info *info)
3166 struct ptlrpc_request *req = mdt_info_req(info);
3167 struct obd_device *obd;
3171 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3174 case SEC_CTX_INIT_CONT:
3180 rc = mdt_handle_idmap(info);
3189 if (unlikely(!class_connected_export(req->rq_export))) {
3190 CDEBUG(D_HA, "operation %d on unconnected MDS from %s\n",
3191 lustre_msg_get_opc(req->rq_reqmsg),
3192 libcfs_id2str(req->rq_peer));
3193 /* FIXME: For CMD cleanup, when mds_B stop, the req from
3194 * mds_A will get -ENOTCONN(especially for ping req),
3195 * which will cause that mds_A deactive timeout, then when
3196 * mds_A cleanup, the cleanup process will be suspended since
3197 * deactive timeout is not zero.
3199 req->rq_status = -ENOTCONN;
3200 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
3204 /* sanity check: if the xid matches, the request must be marked as a
3205 * resent or replayed */
3206 if (req_xid_is_last(req)) {
3207 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
3208 (MSG_RESENT | MSG_REPLAY))) {
3209 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
3210 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
3211 lustre_msg_get_flags(req->rq_reqmsg));
3213 req->rq_status = -ENOTCONN;
3218 /* else: note the opposite is not always true; a RESENT req after a
3219 * failover will usually not match the last_xid, since it was likely
3220 * never committed. A REPLAYed request will almost never match the
3221 * last xid, however it could for a committed, but still retained,
3224 obd = req->rq_export->exp_obd;
3226 /* Check for aborted recovery... */
3227 if (unlikely(obd->obd_recovering)) {
3230 DEBUG_REQ(D_INFO, req, "Got new replay");
3231 rc = mdt_filter_recovery_request(req, obd, &should_process);
3232 if (rc != 0 || !should_process)
3234 else if (should_process < 0) {
3235 req->rq_status = should_process;
3236 rc = ptlrpc_error(req);
3243 static int mdt_msg_check_version(struct lustre_msg *msg)
3247 switch (lustre_msg_get_opc(msg)) {
3249 case MDS_DISCONNECT:
3252 case SEC_CTX_INIT_CONT:
3255 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
3257 CERROR("bad opc %u version %08x, expecting %08x\n",
3258 lustre_msg_get_opc(msg),
3259 lustre_msg_get_version(msg),
3260 LUSTRE_OBD_VERSION);
3264 case MDS_GETATTR_NAME:
3271 case MDS_DONE_WRITING:
3278 case MDS_HSM_PROGRESS:
3279 case MDS_HSM_REQUEST:
3280 case MDS_HSM_CT_REGISTER:
3281 case MDS_HSM_CT_UNREGISTER:
3282 case MDS_HSM_STATE_GET:
3283 case MDS_HSM_STATE_SET:
3284 case MDS_HSM_ACTION:
3285 case MDS_QUOTACHECK:
3288 case MDS_SWAP_LAYOUTS:
3293 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
3295 CERROR("bad opc %u version %08x, expecting %08x\n",
3296 lustre_msg_get_opc(msg),
3297 lustre_msg_get_version(msg),
3298 LUSTRE_MDS_VERSION);
3302 case LDLM_BL_CALLBACK:
3303 case LDLM_CP_CALLBACK:
3304 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
3306 CERROR("bad opc %u version %08x, expecting %08x\n",
3307 lustre_msg_get_opc(msg),
3308 lustre_msg_get_version(msg),
3309 LUSTRE_DLM_VERSION);
3311 case OBD_LOG_CANCEL:
3312 case LLOG_ORIGIN_HANDLE_CREATE:
3313 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3314 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3315 case LLOG_ORIGIN_HANDLE_CLOSE:
3316 case LLOG_ORIGIN_HANDLE_DESTROY:
3317 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3319 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
3321 CERROR("bad opc %u version %08x, expecting %08x\n",
3322 lustre_msg_get_opc(msg),
3323 lustre_msg_get_version(msg),
3324 LUSTRE_LOG_VERSION);
3327 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
3333 static int mdt_handle0(struct ptlrpc_request *req,
3334 struct mdt_thread_info *info,
3335 struct mdt_opc_slice *supported)
3337 struct mdt_handler *h;
3338 struct lustre_msg *msg;
3343 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
3346 LASSERT(current->journal_info == NULL);
3348 msg = req->rq_reqmsg;
3349 rc = mdt_msg_check_version(msg);
3350 if (likely(rc == 0)) {
3351 rc = mdt_recovery(info);
3352 if (likely(rc == +1)) {
3353 h = mdt_handler_find(lustre_msg_get_opc(msg),
3355 if (likely(h != NULL)) {
3356 rc = mdt_req_handle(info, h, req);
3358 CERROR("The unsupported opc: 0x%x\n",
3359 lustre_msg_get_opc(msg) );
3360 req->rq_status = -ENOTSUPP;
3361 rc = ptlrpc_error(req);
3366 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3371 * MDT handler function called by ptlrpc service thread when request comes.
3373 * XXX common "target" functionality should be factored into separate module
3374 * shared by mdt, ost and stand-alone services like fld.
3376 int mdt_handle_common(struct ptlrpc_request *req,
3377 struct mdt_opc_slice *supported)
3380 struct mdt_thread_info *info;
3384 env = req->rq_svc_thread->t_env;
3385 /* Refill(initilize) the context(mdt_thread_info), in case it is
3386 * not initialized yet. Usually it happens during start up, after
3387 * MDS(ptlrpc threads) is start up, it gets the first CONNECT request,
3388 * before MDT_thread_info is initialized */
3390 LASSERT(env != NULL);
3391 LASSERT(env->le_ses != NULL);
3392 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3393 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3394 LASSERT(info != NULL);
3396 mdt_thread_info_init(req, info);
3398 rc = mdt_handle0(req, info, supported);
3400 mdt_thread_info_fini(info);
3405 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3408 int mdt_recovery_handle(struct ptlrpc_request *req)
3413 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3415 rc = mdt_handle_common(req, mdt_fld_handlers);
3418 rc = mdt_handle_common(req, mdt_seq_handlers);
3421 rc = mdt_handle_common(req, mdt_regular_handlers);
3443 static int mdt_intent_getattr(enum mdt_it_code opcode,
3444 struct mdt_thread_info *info,
3445 struct ldlm_lock **,
3447 static int mdt_intent_layout(enum mdt_it_code opcode,
3448 struct mdt_thread_info *info,
3449 struct ldlm_lock **,
3451 static int mdt_intent_reint(enum mdt_it_code opcode,
3452 struct mdt_thread_info *info,
3453 struct ldlm_lock **,
3456 static struct mdt_it_flavor {
3457 const struct req_format *it_fmt;
3459 int (*it_act)(enum mdt_it_code ,
3460 struct mdt_thread_info *,
3461 struct ldlm_lock **,
3464 } mdt_it_flavor[] = {
3466 .it_fmt = &RQF_LDLM_INTENT,
3467 /*.it_flags = HABEO_REFERO,*/
3469 .it_act = mdt_intent_reint,
3470 .it_reint = REINT_OPEN
3473 .it_fmt = &RQF_LDLM_INTENT,
3474 .it_flags = MUTABOR,
3475 .it_act = mdt_intent_reint,
3476 .it_reint = REINT_OPEN
3479 .it_fmt = &RQF_LDLM_INTENT,
3480 .it_flags = MUTABOR,
3481 .it_act = mdt_intent_reint,
3482 .it_reint = REINT_CREATE
3484 [MDT_IT_GETATTR] = {
3485 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3486 .it_flags = HABEO_REFERO,
3487 .it_act = mdt_intent_getattr
3489 [MDT_IT_READDIR] = {
3495 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3496 .it_flags = HABEO_REFERO,
3497 .it_act = mdt_intent_getattr
3500 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3501 .it_flags = MUTABOR,
3503 .it_reint = REINT_UNLINK
3507 .it_flags = MUTABOR,
3510 [MDT_IT_GETXATTR] = {
3516 .it_fmt = &RQF_LDLM_INTENT_LAYOUT,
3518 .it_act = mdt_intent_layout
3522 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3523 struct ldlm_lock **lockp,
3524 struct ldlm_lock *new_lock,
3525 struct mdt_lock_handle *lh,
3528 struct ptlrpc_request *req = mdt_info_req(info);
3529 struct ldlm_lock *lock = *lockp;
3532 * Get new lock only for cases when possible resent did not find any
3535 if (new_lock == NULL)
3536 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3538 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3539 lh->mlh_reg_lh.cookie = 0;
3543 LASSERTF(new_lock != NULL,
3544 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3547 * If we've already given this lock to a client once, then we should
3548 * have no readers or writers. Otherwise, we should have one reader
3549 * _or_ writer ref (which will be zeroed below) before returning the
3552 if (new_lock->l_export == req->rq_export) {
3553 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3555 LASSERT(new_lock->l_export == NULL);
3556 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3561 if (new_lock->l_export == req->rq_export) {
3563 * Already gave this to the client, which means that we
3564 * reconstructed a reply.
3566 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3568 lh->mlh_reg_lh.cookie = 0;
3569 RETURN(ELDLM_LOCK_REPLACED);
3573 * Fixup the lock to be given to the client.
3575 lock_res_and_lock(new_lock);
3576 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3577 * possible blocking AST. */
3578 while (new_lock->l_readers > 0) {
3579 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3580 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3581 new_lock->l_readers--;
3583 while (new_lock->l_writers > 0) {
3584 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3585 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3586 new_lock->l_writers--;
3589 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3590 new_lock->l_blocking_ast = lock->l_blocking_ast;
3591 new_lock->l_completion_ast = lock->l_completion_ast;
3592 new_lock->l_remote_handle = lock->l_remote_handle;
3593 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3595 unlock_res_and_lock(new_lock);
3597 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3598 &new_lock->l_remote_handle,
3599 &new_lock->l_exp_hash);
3601 LDLM_LOCK_RELEASE(new_lock);
3602 lh->mlh_reg_lh.cookie = 0;
3604 RETURN(ELDLM_LOCK_REPLACED);
3607 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3608 struct ldlm_lock *new_lock,
3609 struct ldlm_lock **old_lock,
3610 struct mdt_lock_handle *lh)
3612 struct ptlrpc_request *req = mdt_info_req(info);
3613 struct obd_export *exp = req->rq_export;
3614 struct lustre_handle remote_hdl;
3615 struct ldlm_request *dlmreq;
3616 struct ldlm_lock *lock;
3618 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3621 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3622 remote_hdl = dlmreq->lock_handle[0];
3624 /* In the function below, .hs_keycmp resolves to
3625 * ldlm_export_lock_keycmp() */
3626 /* coverity[overrun-buffer-val] */
3627 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3629 if (lock != new_lock) {
3630 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3631 lh->mlh_reg_mode = lock->l_granted_mode;
3633 LDLM_DEBUG(lock, "Restoring lock cookie");
3634 DEBUG_REQ(D_DLMTRACE, req,
3635 "restoring lock cookie "LPX64,
3636 lh->mlh_reg_lh.cookie);
3638 *old_lock = LDLM_LOCK_GET(lock);
3639 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3643 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3647 * If the xid matches, then we know this is a resent request, and allow
3648 * it. (It's probably an OPEN, for which we don't send a lock.
3650 if (req_xid_is_last(req))
3654 * This remote handle isn't enqueued, so we never received or processed
3655 * this request. Clear MSG_RESENT, because it can be handled like any
3656 * normal request now.
3658 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3660 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3664 static int mdt_intent_getattr(enum mdt_it_code opcode,
3665 struct mdt_thread_info *info,
3666 struct ldlm_lock **lockp,
3669 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3670 struct ldlm_lock *new_lock = NULL;
3672 struct ldlm_reply *ldlm_rep;
3673 struct ptlrpc_request *req;
3674 struct mdt_body *reqbody;
3675 struct mdt_body *repbody;
3679 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3682 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3685 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3686 repbody->eadatasize = 0;
3687 repbody->aclsize = 0;
3691 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
3693 case MDT_IT_GETATTR:
3694 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
3698 CERROR("Unsupported intent (%d)\n", opcode);
3699 GOTO(out_shrink, rc = -EINVAL);
3702 rc = mdt_init_ucred(info, reqbody);
3704 GOTO(out_shrink, rc);
3706 req = info->mti_pill->rc_req;
3707 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3708 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3710 /* Get lock from request for possible resent case. */
3711 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3713 rc = mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3714 ldlm_rep->lock_policy_res2 = clear_serious(rc);
3716 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3717 ldlm_rep->lock_policy_res2 = 0;
3718 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3719 ldlm_rep->lock_policy_res2) {
3720 lhc->mlh_reg_lh.cookie = 0ull;
3721 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3724 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3727 mdt_exit_ucred(info);
3729 mdt_client_compatibility(info);
3730 rc2 = mdt_fix_reply(info);
3736 static int mdt_intent_layout(enum mdt_it_code opcode,
3737 struct mdt_thread_info *info,
3738 struct ldlm_lock **lockp,
3741 struct layout_intent *layout;
3743 struct mdt_object *obj = NULL;
3744 struct md_object *child = NULL;
3748 if (opcode != MDT_IT_LAYOUT) {
3749 CERROR("%s: Unknown intent (%d)\n", mdt_obd_name(info->mti_mdt),
3754 fid = &info->mti_tmp_fid2;
3755 fid_extract_from_res_name(fid, &(*lockp)->l_resource->lr_name);
3757 obj = mdt_object_find(info->mti_env, info->mti_mdt, fid);
3759 RETURN(PTR_ERR(obj));
3761 if (mdt_object_exists(obj) && !mdt_object_remote(obj)) {
3762 child = mdt_object_child(obj);
3764 /* get the length of lsm */
3765 rc = mo_xattr_get(info->mti_env, child, &LU_BUF_NULL,
3768 if (rc > info->mti_mdt->mdt_max_mdsize)
3769 info->mti_mdt->mdt_max_mdsize = rc;
3772 mdt_object_put(info->mti_env, obj);
3774 (*lockp)->l_lvb_type = LVB_T_LAYOUT;
3775 req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER,
3776 ldlm_lvbo_size(*lockp));
3777 rc = req_capsule_server_pack(info->mti_pill);
3781 layout = req_capsule_client_get(info->mti_pill, &RMF_LAYOUT_INTENT);
3782 LASSERT(layout != NULL);
3783 if (layout->li_opc == LAYOUT_INTENT_ACCESS)
3784 /* return to normal ldlm handling */
3787 CERROR("%s: Unsupported layout intent (%d)\n",
3788 mdt_obd_name(info->mti_mdt), layout->li_opc);
3792 static int mdt_intent_reint(enum mdt_it_code opcode,
3793 struct mdt_thread_info *info,
3794 struct ldlm_lock **lockp,
3797 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3798 struct ldlm_reply *rep = NULL;
3802 static const struct req_format *intent_fmts[REINT_MAX] = {
3803 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3804 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3809 opc = mdt_reint_opcode(info, intent_fmts);
3813 if (mdt_it_flavor[opcode].it_reint != opc) {
3814 CERROR("Reint code %ld doesn't match intent: %d\n",
3816 RETURN(err_serious(-EPROTO));
3819 /* Get lock from request for possible resent case. */
3820 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3822 rc = mdt_reint_internal(info, lhc, opc);
3824 /* Check whether the reply has been packed successfully. */
3825 if (mdt_info_req(info)->rq_repmsg != NULL)
3826 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3828 RETURN(err_serious(-EFAULT));
3830 /* MDC expects this in any case */
3832 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3834 /* the open lock or the lock for cross-ref object should be
3835 * returned to the client */
3836 if (rc == -EREMOTE || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
3837 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3838 rep->lock_policy_res2 = 0;
3839 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3843 rep->lock_policy_res2 = clear_serious(rc);
3845 if (rep->lock_policy_res2 == -ENOENT &&
3846 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3847 rep->lock_policy_res2 = 0;
3849 if (rc == -ENOTCONN || rc == -ENODEV ||
3850 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3852 * If it is the disconnect error (ENODEV & ENOCONN), the error
3853 * will be returned by rq_status, and client at ptlrpc layer
3854 * will detect this, then disconnect, reconnect the import
3855 * immediately, instead of impacting the following the rpc.
3857 lhc->mlh_reg_lh.cookie = 0ull;
3861 * For other cases, the error will be returned by intent.
3862 * and client will retrieve the result from intent.
3865 * FIXME: when open lock is finished, that should be
3868 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3869 LASSERTF(rc == 0, "Error occurred but lock handle "
3870 "is still in use, rc = %d\n", rc);
3871 rep->lock_policy_res2 = 0;
3872 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3875 lhc->mlh_reg_lh.cookie = 0ull;
3876 RETURN(ELDLM_LOCK_ABORTED);
3881 static int mdt_intent_code(long itcode)
3889 case IT_OPEN|IT_CREAT:
3896 rc = MDT_IT_READDIR;
3899 rc = MDT_IT_GETATTR;
3911 rc = MDT_IT_GETXATTR;
3916 case IT_QUOTA_DQACQ:
3921 CERROR("Unknown intent opcode: %ld\n", itcode);
3928 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3929 struct ldlm_lock **lockp, __u64 flags)
3931 struct req_capsule *pill;
3932 struct mdt_it_flavor *flv;
3937 opc = mdt_intent_code(itopc);
3941 pill = info->mti_pill;
3943 if (opc == MDT_IT_QUOTA) {
3944 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
3947 RETURN(-EOPNOTSUPP);
3949 (*lockp)->l_lvb_type = LVB_T_LQUOTA;
3950 /* pass the request to quota master */
3951 rc = qmt_hdls.qmth_intent_policy(info->mti_env, qmt,
3952 mdt_info_req(info), lockp,
3957 flv = &mdt_it_flavor[opc];
3958 if (flv->it_fmt != NULL)
3959 req_capsule_extend(pill, flv->it_fmt);
3961 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3963 struct ptlrpc_request *req = mdt_info_req(info);
3964 if (flv->it_flags & MUTABOR &&
3965 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
3968 if (rc == 0 && flv->it_act != NULL) {
3969 struct ldlm_reply *rep;
3971 /* execute policy */
3972 rc = flv->it_act(opc, info, lockp, flags);
3974 /* Check whether the reply has been packed successfully. */
3975 if (mdt_info_req(info)->rq_repmsg != NULL) {
3976 rep = req_capsule_server_get(info->mti_pill,
3978 rep->lock_policy_res2 =
3979 ptlrpc_status_hton(rep->lock_policy_res2);
3987 static int mdt_intent_policy(struct ldlm_namespace *ns,
3988 struct ldlm_lock **lockp, void *req_cookie,
3989 ldlm_mode_t mode, __u64 flags, void *data)
3991 struct mdt_thread_info *info;
3992 struct ptlrpc_request *req = req_cookie;
3993 struct ldlm_intent *it;
3994 struct req_capsule *pill;
3999 LASSERT(req != NULL);
4001 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
4003 LASSERT(info != NULL);
4004 pill = info->mti_pill;
4005 LASSERT(pill->rc_req == req);
4007 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
4008 req_capsule_extend(pill, &RQF_LDLM_INTENT_BASIC);
4009 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
4011 rc = mdt_intent_opc(it->opc, info, lockp, flags);
4015 /* Lock without inodebits makes no sense and will oops
4016 * later in ldlm. Let's check it now to see if we have
4017 * ibits corrupted somewhere in mdt_intent_opc().
4018 * The case for client miss to set ibits has been
4019 * processed by others. */
4020 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
4021 lr_type == LDLM_IBITS,
4022 info->mti_dlm_req->lock_desc.\
4023 l_policy_data.l_inodebits.bits != 0));
4025 rc = err_serious(-EFAULT);
4027 /* No intent was provided */
4028 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
4029 req_capsule_set_size(pill, &RMF_DLM_LVB, RCL_SERVER, 0);
4030 rc = req_capsule_server_pack(pill);
4032 rc = err_serious(rc);
4037 static int mdt_seq_fini(const struct lu_env *env,
4038 struct mdt_device *m)
4040 return seq_site_fini(env, mdt_seq_site(m));
4043 static int mdt_seq_init(const struct lu_env *env,
4045 struct mdt_device *m)
4047 struct seq_server_site *ss;
4052 ss = mdt_seq_site(m);
4055 * This is sequence-controller node. Init seq-controller server on local
4058 if (ss->ss_node_id == 0) {
4059 LASSERT(ss->ss_control_seq == NULL);
4061 OBD_ALLOC_PTR(ss->ss_control_seq);
4062 if (ss->ss_control_seq == NULL)
4065 rc = seq_server_init(ss->ss_control_seq,
4066 m->mdt_bottom, uuid,
4067 LUSTRE_SEQ_CONTROLLER,
4072 GOTO(out_seq_fini, rc);
4074 OBD_ALLOC_PTR(ss->ss_client_seq);
4075 if (ss->ss_client_seq == NULL)
4076 GOTO(out_seq_fini, rc = -ENOMEM);
4078 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
4079 if (prefix == NULL) {
4080 OBD_FREE_PTR(ss->ss_client_seq);
4081 GOTO(out_seq_fini, rc = -ENOMEM);
4084 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
4088 * Init seq-controller client after seq-controller server is
4089 * ready. Pass ss->ss_control_seq to it for direct talking.
4091 rc = seq_client_init(ss->ss_client_seq, NULL,
4092 LUSTRE_SEQ_METADATA, prefix,
4093 ss->ss_control_seq);
4094 OBD_FREE(prefix, MAX_OBD_NAME + 5);
4097 GOTO(out_seq_fini, rc);
4100 /* Init seq-server on local MDT */
4101 LASSERT(ss->ss_server_seq == NULL);
4103 OBD_ALLOC_PTR(ss->ss_server_seq);
4104 if (ss->ss_server_seq == NULL)
4105 GOTO(out_seq_fini, rc = -ENOMEM);
4107 rc = seq_server_init(ss->ss_server_seq,
4108 m->mdt_bottom, uuid,
4113 GOTO(out_seq_fini, rc = -ENOMEM);
4115 /* Assign seq-controller client to local seq-server. */
4116 if (ss->ss_node_id == 0) {
4117 LASSERT(ss->ss_client_seq != NULL);
4119 rc = seq_server_set_cli(ss->ss_server_seq,
4127 mdt_seq_fini(env, m);
4135 static int mdt_fld_fini(const struct lu_env *env,
4136 struct mdt_device *m)
4138 struct seq_server_site *ss = mdt_seq_site(m);
4141 if (ss && ss->ss_server_fld) {
4142 fld_server_fini(env, ss->ss_server_fld);
4143 OBD_FREE_PTR(ss->ss_server_fld);
4144 ss->ss_server_fld = NULL;
4150 static int mdt_fld_init(const struct lu_env *env,
4152 struct mdt_device *m)
4154 struct seq_server_site *ss;
4158 ss = mdt_seq_site(m);
4160 OBD_ALLOC_PTR(ss->ss_server_fld);
4161 if (ss->ss_server_fld == NULL)
4162 RETURN(rc = -ENOMEM);
4164 rc = fld_server_init(env, ss->ss_server_fld, m->mdt_bottom, uuid,
4165 ss->ss_node_id, LU_SEQ_RANGE_MDT);
4167 OBD_FREE_PTR(ss->ss_server_fld);
4168 ss->ss_server_fld = NULL;
4175 static void mdt_stack_pre_fini(const struct lu_env *env,
4176 struct mdt_device *m, struct lu_device *top)
4178 struct obd_device *obd;
4179 struct lustre_cfg_bufs *bufs;
4180 struct lustre_cfg *lcfg;
4181 struct mdt_thread_info *info;
4186 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4187 LASSERT(info != NULL);
4189 bufs = &info->mti_u.bufs;
4191 LASSERT(m->mdt_child_exp);
4192 LASSERT(m->mdt_child_exp->exp_obd);
4193 obd = m->mdt_child_exp->exp_obd;
4195 /* process cleanup, pass mdt obd name to get obd umount flags */
4196 /* XXX: this is needed because all layers are referenced by
4197 * objects (some of them are pinned by osd, for example *
4198 * the proper solution should be a model where object used
4199 * by osd only doesn't have mdt/mdd slices -bzzz */
4200 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
4201 lustre_cfg_bufs_set_string(bufs, 1, NULL);
4202 lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
4204 CERROR("%s:Cannot alloc lcfg!\n", mdt_obd_name(m));
4207 top->ld_ops->ldo_process_config(env, top, lcfg);
4208 lustre_cfg_free(lcfg);
4212 static void mdt_stack_fini(const struct lu_env *env,
4213 struct mdt_device *m, struct lu_device *top)
4215 struct obd_device *obd = mdt2obd_dev(m);
4216 struct lustre_cfg_bufs *bufs;
4217 struct lustre_cfg *lcfg;
4218 struct mdt_thread_info *info;
4222 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4223 LASSERT(info != NULL);
4225 lu_dev_del_linkage(top->ld_site, top);
4227 lu_site_purge(env, top->ld_site, -1);
4229 bufs = &info->mti_u.bufs;
4230 /* process cleanup, pass mdt obd name to get obd umount flags */
4231 /* another purpose is to let all layers to release their objects */
4232 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
4237 lustre_cfg_bufs_set_string(bufs, 1, flags);
4238 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4240 CERROR("Cannot alloc lcfg!\n");
4244 top->ld_ops->ldo_process_config(env, top, lcfg);
4245 lustre_cfg_free(lcfg);
4247 lu_site_purge(env, top->ld_site, -1);
4249 m->mdt_child = NULL;
4250 m->mdt_bottom = NULL;
4252 obd_disconnect(m->mdt_child_exp);
4253 m->mdt_child_exp = NULL;
4255 obd_disconnect(m->mdt_bottom_exp);
4256 m->mdt_child_exp = NULL;
4259 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
4260 const char *next, struct obd_export **exp)
4262 struct obd_connect_data *data = NULL;
4263 struct obd_device *obd;
4267 OBD_ALLOC_PTR(data);
4269 GOTO(out, rc = -ENOMEM);
4271 obd = class_name2obd(next);
4273 CERROR("%s: can't locate next device: %s\n",
4274 mdt_obd_name(m), next);
4275 GOTO(out, rc = -ENOTCONN);
4278 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4279 data->ocd_version = LUSTRE_VERSION_CODE;
4281 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
4283 CERROR("%s: cannot connect to next dev %s (%d)\n",
4284 mdt_obd_name(m), next, rc);
4294 static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
4295 struct lustre_cfg *cfg)
4297 char *dev = lustre_cfg_string(cfg, 0);
4298 int rc, name_size, uuid_size;
4299 char *name, *uuid, *p;
4300 struct lustre_cfg_bufs *bufs;
4301 struct lustre_cfg *lcfg;
4302 struct obd_device *obd;
4303 struct lustre_profile *lprof;
4304 struct lu_site *site;
4307 /* in 1.8 we had the only device in the stack - MDS.
4308 * 2.0 introduces MDT, MDD, OSD; MDT starts others internally.
4309 * in 2.3 OSD is instantiated by obd_mount.c, so we need
4310 * to generate names and setup MDT, MDD. MDT will be using
4311 * generated name to connect to MDD. for MDD the next device
4312 * will be LOD with name taken from so called "profile" which
4313 * is generated by mount_option line
4315 * 1.8 MGS generates config. commands like this:
4316 * #06 (104)mount_option 0: 1:lustre-MDT0000 2:lustre-mdtlov
4317 * #08 (120)setup 0:lustre-MDT0000 1:dev 2:type 3:lustre-MDT0000
4318 * 2.0 MGS generates config. commands like this:
4319 * #07 (112)mount_option 0: 1:lustre-MDT0000 2:lustre-MDT0000-mdtlov
4320 * #08 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4321 * 3:lustre-MDT0000-mdtlov 4:f
4323 * we generate MDD name from MDT one, just replacing T with D
4325 * after all the preparations, the logical equivalent will be
4326 * #01 (160)setup 0:lustre-MDD0000 1:lustre-MDD0000_UUID 2:0
4327 * 3:lustre-MDT0000-mdtlov 4:f
4328 * #02 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4329 * 3:lustre-MDD0000 4:f
4331 * notice we build the stack from down to top: MDD first, then MDT */
4333 name_size = MAX_OBD_NAME;
4334 uuid_size = MAX_OBD_NAME;
4336 OBD_ALLOC(name, name_size);
4337 OBD_ALLOC(uuid, uuid_size);
4338 if (name == NULL || uuid == NULL)
4339 GOTO(cleanup_mem, rc = -ENOMEM);
4341 OBD_ALLOC_PTR(bufs);
4343 GOTO(cleanup_mem, rc = -ENOMEM);
4346 p = strstr(name, "-MDT");
4348 GOTO(cleanup_mem, rc = -ENOMEM);
4351 snprintf(uuid, MAX_OBD_NAME, "%s_UUID", name);
4353 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4354 if (lprof == NULL || lprof->lp_dt == NULL) {
4355 CERROR("can't find the profile: %s\n",
4356 lustre_cfg_string(cfg, 0));
4357 GOTO(cleanup_mem, rc = -EINVAL);
4360 lustre_cfg_bufs_reset(bufs, name);
4361 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_MDD_NAME);
4362 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4363 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4365 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4367 GOTO(free_bufs, rc = -ENOMEM);
4369 rc = class_attach(lcfg);
4371 GOTO(lcfg_cleanup, rc);
4373 obd = class_name2obd(name);
4375 CERROR("Can not find obd %s (%s in config)\n",
4376 MDD_OBD_NAME, lustre_cfg_string(cfg, 0));
4377 GOTO(class_detach, rc = -EINVAL);
4380 lustre_cfg_free(lcfg);
4382 lustre_cfg_bufs_reset(bufs, name);
4383 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4384 lustre_cfg_bufs_set_string(bufs, 2, dev);
4385 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4387 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4389 rc = class_setup(obd, lcfg);
4391 GOTO(class_detach, rc);
4393 /* connect to MDD we just setup */
4394 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_child_exp);
4398 site = mdt->mdt_child_exp->exp_obd->obd_lu_dev->ld_site;
4400 LASSERT(mdt_lu_site(mdt) == NULL);
4401 mdt->mdt_md_dev.md_lu_dev.ld_site = site;
4402 site->ls_top_dev = &mdt->mdt_md_dev.md_lu_dev;
4403 mdt->mdt_child = lu2md_dev(mdt->mdt_child_exp->exp_obd->obd_lu_dev);
4406 /* now connect to bottom OSD */
4407 snprintf(name, MAX_OBD_NAME, "%s-osd", dev);
4408 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_bottom_exp);
4412 lu2dt_dev(mdt->mdt_bottom_exp->exp_obd->obd_lu_dev);
4415 rc = lu_env_refill((struct lu_env *)env);
4417 CERROR("Failure to refill session: '%d'\n", rc);
4419 lu_dev_add_linkage(site, &mdt->mdt_md_dev.md_lu_dev);
4424 class_detach(obd, lcfg);
4426 lustre_cfg_free(lcfg);
4431 OBD_FREE(name, name_size);
4433 OBD_FREE(uuid, uuid_size);
4437 /* setup quota master target on MDT0 */
4438 static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
4439 struct lustre_cfg *cfg)
4441 struct obd_device *obd;
4442 char *dev = lustre_cfg_string(cfg, 0);
4443 char *qmtname, *uuid, *p;
4444 struct lustre_cfg_bufs *bufs;
4445 struct lustre_cfg *lcfg;
4446 struct lustre_profile *lprof;
4447 struct obd_connect_data *data;
4451 LASSERT(mdt->mdt_qmt_exp == NULL);
4452 LASSERT(mdt->mdt_qmt_dev == NULL);
4454 /* quota master is on MDT0 only for now */
4455 if (mdt->mdt_seq_site.ss_node_id != 0)
4458 /* MGS generates config commands which look as follows:
4459 * #01 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4460 * 3:lustre-MDT0000-mdtlov 4:f
4462 * We generate the QMT name from the MDT one, just replacing MD with QM
4463 * after all the preparations, the logical equivalent will be:
4464 * #01 (160)setup 0:lustre-QMT0000 1:lustre-QMT0000_UUID 2:0
4465 * 3:lustre-MDT0000-osd 4:f */
4466 OBD_ALLOC(qmtname, MAX_OBD_NAME);
4467 OBD_ALLOC(uuid, UUID_MAX);
4468 OBD_ALLOC_PTR(bufs);
4469 OBD_ALLOC_PTR(data);
4470 if (qmtname == NULL || uuid == NULL || bufs == NULL || data == NULL)
4471 GOTO(cleanup_mem, rc = -ENOMEM);
4473 strcpy(qmtname, dev);
4474 p = strstr(qmtname, "-MDT");
4476 GOTO(cleanup_mem, rc = -ENOMEM);
4477 /* replace MD with QM */
4481 snprintf(uuid, UUID_MAX, "%s_UUID", qmtname);
4483 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4484 if (lprof == NULL || lprof->lp_dt == NULL) {
4485 CERROR("can't find profile for %s\n",
4486 lustre_cfg_string(cfg, 0));
4487 GOTO(cleanup_mem, rc = -EINVAL);
4490 lustre_cfg_bufs_reset(bufs, qmtname);
4491 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_QMT_NAME);
4492 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4493 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4495 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4497 GOTO(cleanup_mem, rc = -ENOMEM);
4499 rc = class_attach(lcfg);
4501 GOTO(lcfg_cleanup, rc);
4503 obd = class_name2obd(qmtname);
4505 CERROR("Can not find obd %s (%s in config)\n", qmtname,
4506 lustre_cfg_string(cfg, 0));
4507 GOTO(class_detach, rc = -EINVAL);
4510 lustre_cfg_free(lcfg);
4512 lustre_cfg_bufs_reset(bufs, qmtname);
4513 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4514 lustre_cfg_bufs_set_string(bufs, 2, dev);
4516 /* for quota, the next device should be the OSD device */
4517 lustre_cfg_bufs_set_string(bufs, 3,
4518 mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
4520 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4522 rc = class_setup(obd, lcfg);
4524 GOTO(class_detach, rc);
4526 mdt->mdt_qmt_dev = obd->obd_lu_dev;
4528 /* configure local quota objects */
4529 rc = mdt->mdt_qmt_dev->ld_ops->ldo_prepare(env,
4530 &mdt->mdt_md_dev.md_lu_dev,
4533 GOTO(class_cleanup, rc);
4535 /* connect to quota master target */
4536 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4537 data->ocd_version = LUSTRE_VERSION_CODE;
4538 rc = obd_connect(NULL, &mdt->mdt_qmt_exp, obd, &obd->obd_uuid,
4541 CERROR("cannot connect to quota master device %s (%d)\n",
4543 GOTO(class_cleanup, rc);
4549 class_manual_cleanup(obd);
4550 mdt->mdt_qmt_dev = NULL;
4554 class_detach(obd, lcfg);
4556 lustre_cfg_free(lcfg);
4561 OBD_FREE(qmtname, MAX_OBD_NAME);
4563 OBD_FREE(uuid, UUID_MAX);
4569 /* Shutdown quota master target associated with mdt */
4570 static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt)
4574 if (mdt->mdt_qmt_exp == NULL)
4576 LASSERT(mdt->mdt_qmt_dev != NULL);
4578 /* the qmt automatically shuts down when the mdt disconnects */
4579 obd_disconnect(mdt->mdt_qmt_exp);
4580 mdt->mdt_qmt_exp = NULL;
4581 mdt->mdt_qmt_dev = NULL;
4585 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4587 struct md_device *next = m->mdt_child;
4588 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4589 struct obd_device *obd = mdt2obd_dev(m);
4592 target_recovery_fini(obd);
4594 ping_evictor_stop();
4597 mdt_stack_pre_fini(env, m, md2lu_dev(m->mdt_child));
4598 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4599 obd_exports_barrier(obd);
4600 obd_zombie_barrier();
4604 tgt_fini(env, &m->mdt_lut);
4605 mdt_fs_cleanup(env, m);
4606 upcall_cache_cleanup(m->mdt_identity_cache);
4607 m->mdt_identity_cache = NULL;
4609 if (m->mdt_namespace != NULL) {
4610 ldlm_namespace_free(m->mdt_namespace, NULL,
4611 d->ld_obd->obd_force);
4612 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4615 mdt_quota_fini(env, m);
4617 cfs_free_nidlist(&m->mdt_nosquash_nids);
4618 if (m->mdt_nosquash_str) {
4619 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4620 m->mdt_nosquash_str = NULL;
4621 m->mdt_nosquash_strlen = 0;
4624 next->md_ops->mdo_iocontrol(env, next, OBD_IOC_PAUSE_LFSCK, 0, NULL);
4626 mdt_seq_fini(env, m);
4627 mdt_fld_fini(env, m);
4628 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4630 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4631 cfs_timer_disarm(&m->mdt_ck_timer);
4632 mdt_ck_thread_stop(m);
4637 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4639 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4641 server_put_mount(mdt_obd_name(m), NULL);
4646 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4648 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4649 struct sptlrpc_rule_set tmp_rset;
4652 sptlrpc_rule_set_init(&tmp_rset);
4653 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4655 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4656 mdt_obd_name(m), rc);
4660 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4662 write_lock(&m->mdt_sptlrpc_lock);
4663 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4664 m->mdt_sptlrpc_rset = tmp_rset;
4665 write_unlock(&m->mdt_sptlrpc_lock);
4670 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4672 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4673 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4675 struct mdt_thread_info *info;
4676 struct obd_device *obd;
4677 const char *dev = lustre_cfg_string(cfg, 0);
4678 const char *num = lustre_cfg_string(cfg, 2);
4679 struct lustre_mount_info *lmi = NULL;
4680 struct lustre_sb_info *lsi;
4682 struct seq_server_site *ss_site;
4683 const char *identity_upcall = "NONE";
4684 struct md_device *next;
4690 md_device_init(&m->mdt_md_dev, ldt);
4692 * Environment (env) might be missing mdt_thread_key values at that
4693 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4696 * Usually device allocation path doesn't use module key values, but
4697 * mdt has to do a lot of work here, so allocate key value.
4699 rc = lu_env_refill((struct lu_env *)env);
4703 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4704 LASSERT(info != NULL);
4706 obd = class_name2obd(dev);
4707 LASSERT(obd != NULL);
4709 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4711 m->mdt_som_conf = 0;
4713 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4714 lmi = server_get_mount(dev);
4716 CERROR("Cannot get mount info for %s!\n", dev);
4719 lsi = s2lsi(lmi->lmi_sb);
4720 /* CMD is supported only in IAM mode */
4722 node_id = simple_strtol(num, NULL, 10);
4723 obd->u.obt.obt_magic = OBT_MAGIC;
4726 rwlock_init(&m->mdt_sptlrpc_lock);
4727 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4729 spin_lock_init(&m->mdt_ioepoch_lock);
4730 m->mdt_opts.mo_compat_resname = 0;
4731 m->mdt_opts.mo_mds_capa = 1;
4732 m->mdt_opts.mo_oss_capa = 1;
4733 m->mdt_capa_timeout = CAPA_TIMEOUT;
4734 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4735 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4736 m->mdt_squash_uid = 0;
4737 m->mdt_squash_gid = 0;
4738 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4739 m->mdt_nosquash_str = NULL;
4740 m->mdt_nosquash_strlen = 0;
4741 init_rwsem(&m->mdt_squash_sem);
4742 spin_lock_init(&m->mdt_osfs_lock);
4743 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4744 m->mdt_enable_remote_dir = 0;
4745 m->mdt_enable_remote_dir_gid = 0;
4747 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4748 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4749 /* set this lu_device to obd, because error handling need it */
4750 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4752 /* init the stack */
4753 rc = mdt_stack_init((struct lu_env *)env, m, cfg);
4755 CERROR("%s: Can't init device stack, rc %d\n",
4756 mdt_obd_name(m), rc);
4761 ss_site = mdt_seq_site(m);
4762 s->ld_seq_site = ss_site;
4765 /* set server index */
4766 ss_site->ss_node_id = node_id;
4768 /* failover is the default
4769 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4770 * assumed whose ss_node_id == 0 XXX
4772 obd->obd_replayable = 1;
4773 /* No connection accepted until configurations will finish */
4774 obd->obd_no_conn = 1;
4776 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4777 char *str = lustre_cfg_string(cfg, 4);
4778 if (strchr(str, 'n')) {
4779 CWARN("%s: recovery disabled\n", mdt_obd_name(m));
4780 obd->obd_replayable = 0;
4784 rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4786 GOTO(err_fini_stack, rc);
4788 rc = mdt_fld_init(env, mdt_obd_name(m), m);
4792 rc = mdt_seq_init(env, mdt_obd_name(m), m);
4794 GOTO(err_fini_fld, rc);
4796 snprintf(info->mti_u.ns_name, sizeof(info->mti_u.ns_name), "%s-%s",
4797 LUSTRE_MDT_NAME, obd->obd_uuid.uuid);
4798 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4799 LDLM_NAMESPACE_SERVER,
4800 LDLM_NAMESPACE_GREEDY,
4802 if (m->mdt_namespace == NULL)
4803 GOTO(err_fini_seq, rc = -ENOMEM);
4805 m->mdt_namespace->ns_lvbp = m;
4806 m->mdt_namespace->ns_lvbo = &mdt_lvbo;
4808 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4809 /* set obd_namespace for compatibility with old code */
4810 obd->obd_namespace = m->mdt_namespace;
4812 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4814 rc = mdt_ck_thread_start(m);
4816 GOTO(err_free_ns, rc);
4818 rc = mdt_fs_setup(env, m, obd, lsi);
4822 mdt_adapt_sptlrpc_conf(obd, 1);
4824 next = m->mdt_child;
4825 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4828 GOTO(err_llog_cleanup, rc);
4830 if (mntopts & MNTOPT_USERXATTR)
4831 m->mdt_opts.mo_user_xattr = 1;
4833 m->mdt_opts.mo_user_xattr = 0;
4835 if (mntopts & MNTOPT_ACL)
4836 m->mdt_opts.mo_acl = 1;
4838 m->mdt_opts.mo_acl = 0;
4840 /* XXX: to support suppgid for ACL, we enable identity_upcall
4841 * by default, otherwise, maybe got unexpected -EACCESS. */
4842 if (m->mdt_opts.mo_acl)
4843 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4845 m->mdt_identity_cache = upcall_cache_init(mdt_obd_name(m),
4847 &mdt_identity_upcall_cache_ops);
4848 if (IS_ERR(m->mdt_identity_cache)) {
4849 rc = PTR_ERR(m->mdt_identity_cache);
4850 m->mdt_identity_cache = NULL;
4851 GOTO(err_llog_cleanup, rc);
4854 rc = mdt_procfs_init(m, dev);
4856 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4857 GOTO(err_recovery, rc);
4860 rc = mdt_quota_init(env, m, cfg);
4862 GOTO(err_procfs, rc);
4864 m->mdt_ldlm_client = &mdt2obd_dev(m)->obd_ldlm_client;
4865 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
4866 "mdt_ldlm_client", m->mdt_ldlm_client);
4868 ping_evictor_start();
4870 /* recovery will be started upon mdt_prepare()
4871 * when the whole stack is complete and ready
4872 * to serve the requests */
4874 mdt_init_capa_ctxt(env, m);
4876 /* Reduce the initial timeout on an MDS because it doesn't need such
4877 * a long timeout as an OST does. Adaptive timeouts will adjust this
4878 * value appropriately. */
4879 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4880 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4887 target_recovery_fini(obd);
4888 upcall_cache_cleanup(m->mdt_identity_cache);
4889 m->mdt_identity_cache = NULL;
4891 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4892 mdt_fs_cleanup(env, m);
4894 cfs_timer_disarm(&m->mdt_ck_timer);
4895 mdt_ck_thread_stop(m);
4897 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4898 obd->obd_namespace = m->mdt_namespace = NULL;
4900 mdt_seq_fini(env, m);
4902 mdt_fld_fini(env, m);
4904 tgt_fini(env, &m->mdt_lut);
4906 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4909 server_put_mount(dev, lmi->lmi_mnt);
4913 /* For interoperability, the left element is old parameter, the right one
4914 * is the new version of the parameter, if some parameter is deprecated,
4915 * the new version should be set as NULL. */
4916 static struct cfg_interop_param mdt_interop_param[] = {
4917 { "mdt.group_upcall", NULL },
4918 { "mdt.quota_type", NULL },
4919 { "mdd.quota_type", NULL },
4920 { "mdt.rootsquash", "mdt.root_squash" },
4921 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
4925 /* used by MGS to process specific configurations */
4926 static int mdt_process_config(const struct lu_env *env,
4927 struct lu_device *d, struct lustre_cfg *cfg)
4929 struct mdt_device *m = mdt_dev(d);
4930 struct md_device *md_next = m->mdt_child;
4931 struct lu_device *next = md2lu_dev(md_next);
4935 switch (cfg->lcfg_command) {
4937 struct lprocfs_static_vars lvars;
4938 struct obd_device *obd = d->ld_obd;
4940 /* For interoperability */
4941 struct cfg_interop_param *ptr = NULL;
4942 struct lustre_cfg *old_cfg = NULL;
4945 param = lustre_cfg_string(cfg, 1);
4946 if (param == NULL) {
4947 CERROR("param is empty\n");
4952 ptr = class_find_old_param(param, mdt_interop_param);
4954 if (ptr->new_param == NULL) {
4956 CWARN("For interoperability, skip this %s."
4957 " It is obsolete.\n", ptr->old_param);
4961 CWARN("Found old param %s, changed it to %s.\n",
4962 ptr->old_param, ptr->new_param);
4965 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
4972 lprocfs_mdt_init_vars(&lvars);
4973 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4975 if (rc > 0 || rc == -ENOSYS)
4976 /* we don't understand; pass it on */
4977 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4979 if (old_cfg != NULL)
4980 lustre_cfg_free(cfg);
4985 /* others are passed further */
4986 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4992 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4993 const struct lu_object_header *hdr,
4994 struct lu_device *d)
4996 struct mdt_object *mo;
5000 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, __GFP_IO);
5002 struct lu_object *o;
5003 struct lu_object_header *h;
5005 o = &mo->mot_obj.mo_lu;
5006 h = &mo->mot_header;
5007 lu_object_header_init(h);
5008 lu_object_init(o, h, d);
5009 lu_object_add_top(h, o);
5010 o->lo_ops = &mdt_obj_ops;
5011 mutex_init(&mo->mot_ioepoch_mutex);
5012 mutex_init(&mo->mot_lov_mutex);
5018 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
5019 const struct lu_object_conf *unused)
5021 struct mdt_device *d = mdt_dev(o->lo_dev);
5022 struct lu_device *under;
5023 struct lu_object *below;
5027 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
5028 PFID(lu_object_fid(o)));
5030 under = &d->mdt_child->md_lu_dev;
5031 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
5032 if (below != NULL) {
5033 lu_object_add(o, below);
5040 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
5042 struct mdt_object *mo = mdt_obj(o);
5043 struct lu_object_header *h;
5047 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
5048 PFID(lu_object_fid(o)));
5051 lu_object_header_fini(h);
5052 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
5057 static int mdt_object_print(const struct lu_env *env, void *cookie,
5058 lu_printer_t p, const struct lu_object *o)
5060 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
5061 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
5062 "flags="LPX64", epochcount=%d, writecount=%d)",
5063 mdto, mdto->mot_ioepoch, mdto->mot_flags,
5064 mdto->mot_ioepoch_count, mdto->mot_writecount);
5067 static int mdt_prepare(const struct lu_env *env,
5068 struct lu_device *pdev,
5069 struct lu_device *cdev)
5071 struct mdt_device *mdt = mdt_dev(cdev);
5072 struct lu_device *next = &mdt->mdt_child->md_lu_dev;
5073 struct obd_device *obd = cdev->ld_obd;
5074 struct lfsck_start_param lsp;
5081 rc = next->ld_ops->ldo_prepare(env, cdev, next);
5085 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_CHANGELOG_ORIG_CTXT);
5089 lsp.lsp_start = NULL;
5090 lsp.lsp_namespace = mdt->mdt_namespace;
5091 rc = mdt->mdt_child->md_ops->mdo_iocontrol(env, mdt->mdt_child,
5092 OBD_IOC_START_LFSCK,
5095 CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
5096 mdt_obd_name(mdt), rc);
5100 if (mdt->mdt_seq_site.ss_node_id == 0) {
5101 rc = mdt->mdt_child->md_ops->mdo_root_get(env, mdt->mdt_child,
5102 &mdt->mdt_md_root_fid);
5106 LASSERT(!test_bit(MDT_FL_CFGLOG, &mdt->mdt_state));
5107 target_recovery_init(&mdt->mdt_lut, mdt_recovery_handle);
5108 set_bit(MDT_FL_CFGLOG, &mdt->mdt_state);
5109 LASSERT(obd->obd_no_conn);
5110 spin_lock(&obd->obd_dev_lock);
5111 obd->obd_no_conn = 0;
5112 spin_unlock(&obd->obd_dev_lock);
5114 if (obd->obd_recovering == 0)
5115 mdt_postrecov(env, mdt);
5120 const struct lu_device_operations mdt_lu_ops = {
5121 .ldo_object_alloc = mdt_object_alloc,
5122 .ldo_process_config = mdt_process_config,
5123 .ldo_prepare = mdt_prepare,
5126 static const struct lu_object_operations mdt_obj_ops = {
5127 .loo_object_init = mdt_object_init,
5128 .loo_object_free = mdt_object_free,
5129 .loo_object_print = mdt_object_print
5132 static int mdt_obd_set_info_async(const struct lu_env *env,
5133 struct obd_export *exp,
5134 __u32 keylen, void *key,
5135 __u32 vallen, void *val,
5136 struct ptlrpc_request_set *set)
5138 struct obd_device *obd = exp->exp_obd;
5144 if (KEY_IS(KEY_SPTLRPC_CONF)) {
5145 rc = mdt_adapt_sptlrpc_conf(obd, 0);
5153 * Match client and server connection feature flags.
5155 * Compute the compatibility flags for a connection request based on
5156 * features mutually supported by client and server.
5158 * The obd_export::exp_connect_data.ocd_connect_flags field in \a exp
5159 * must not be updated here, otherwise a partially initialized value may
5160 * be exposed. After the connection request is successfully processed,
5161 * the top-level MDT connect request handler atomically updates the export
5162 * connect flags from the obd_connect_data::ocd_connect_flags field of the
5163 * reply. \see mdt_connect().
5165 * \param exp the obd_export associated with this client/target pair
5166 * \param mdt the target device for the connection
5167 * \param data stores data for this connect request
5170 * \retval -EPROTO \a data unexpectedly has zero obd_connect_data::ocd_brw_size
5171 * \retval -EBADE client and server feature requirements are incompatible
5173 static int mdt_connect_internal(struct obd_export *exp,
5174 struct mdt_device *mdt,
5175 struct obd_connect_data *data)
5177 LASSERT(data != NULL);
5179 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
5180 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
5182 /* If no known bits (which should not happen, probably,
5183 as everybody should support LOOKUP and UPDATE bits at least)
5184 revert to compat mode with plain locks. */
5185 if (!data->ocd_ibits_known &&
5186 data->ocd_connect_flags & OBD_CONNECT_IBITS)
5187 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
5189 if (!mdt->mdt_opts.mo_acl)
5190 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5192 if (!mdt->mdt_opts.mo_user_xattr)
5193 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5195 if (!mdt->mdt_som_conf)
5196 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5198 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5199 data->ocd_brw_size = min(data->ocd_brw_size,
5200 (__u32)MD_MAX_BRW_SIZE);
5201 if (data->ocd_brw_size == 0) {
5202 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5203 " ocd_version: %x ocd_grant: %d "
5204 "ocd_index: %u ocd_brw_size is "
5205 "unexpectedly zero, network data "
5206 "corruption? Refusing connection of this"
5209 exp->exp_client_uuid.uuid,
5210 exp, data->ocd_connect_flags, data->ocd_version,
5211 data->ocd_grant, data->ocd_index);
5216 /* NB: Disregard the rule against updating
5217 * exp_connect_data.ocd_connect_flags in this case, since
5218 * tgt_client_new() needs to know if this is a lightweight
5219 * connection, and it is safe to expose this flag before
5220 * connection processing completes. */
5221 if (data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) {
5222 spin_lock(&exp->exp_lock);
5223 *exp_connect_flags_ptr(exp) |= OBD_CONNECT_LIGHTWEIGHT;
5224 spin_unlock(&exp->exp_lock);
5227 data->ocd_version = LUSTRE_VERSION_CODE;
5228 exp->exp_connect_data = *data;
5229 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5231 if ((data->ocd_connect_flags & OBD_CONNECT_FID) == 0) {
5232 CWARN("%s: MDS requires FID support, but client not\n",
5237 if (mdt->mdt_som_conf &&
5238 !(data->ocd_connect_flags & (OBD_CONNECT_LIGHTWEIGHT |
5239 OBD_CONNECT_MDS_MDS |
5240 OBD_CONNECT_SOM))) {
5241 CWARN("%s: MDS has SOM enabled, but client does not support "
5242 "it\n", mdt_obd_name(mdt));
5246 if (OCD_HAS_FLAG(data, PINGLESS)) {
5247 if (ptlrpc_pinger_suppress_pings()) {
5248 spin_lock(&exp->exp_obd->obd_dev_lock);
5249 list_del_init(&exp->exp_obd_chain_timed);
5250 spin_unlock(&exp->exp_obd->obd_dev_lock);
5252 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
5259 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5260 struct obd_export *exp,
5261 struct ptlrpc_request *req)
5263 struct sptlrpc_flavor flvr;
5266 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5267 read_lock(&mdt->mdt_sptlrpc_lock);
5268 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5272 read_unlock(&mdt->mdt_sptlrpc_lock);
5274 spin_lock(&exp->exp_lock);
5276 exp->exp_sp_peer = req->rq_sp_from;
5277 exp->exp_flvr = flvr;
5279 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5280 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5281 CERROR("unauthorized rpc flavor %x from %s, "
5282 "expect %x\n", req->rq_flvr.sf_rpc,
5283 libcfs_nid2str(req->rq_peer.nid),
5284 exp->exp_flvr.sf_rpc);
5288 spin_unlock(&exp->exp_lock);
5290 if (exp->exp_sp_peer != req->rq_sp_from) {
5291 CERROR("RPC source %s doesn't match %s\n",
5292 sptlrpc_part2name(req->rq_sp_from),
5293 sptlrpc_part2name(exp->exp_sp_peer));
5296 rc = sptlrpc_target_export_check(exp, req);
5303 /* mds_connect copy */
5304 static int mdt_obd_connect(const struct lu_env *env,
5305 struct obd_export **exp, struct obd_device *obd,
5306 struct obd_uuid *cluuid,
5307 struct obd_connect_data *data,
5310 struct mdt_thread_info *info;
5311 struct obd_export *lexp;
5312 struct lustre_handle conn = { 0 };
5313 struct mdt_device *mdt;
5314 struct ptlrpc_request *req;
5318 LASSERT(env != NULL);
5319 if (!exp || !obd || !cluuid)
5322 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5323 req = info->mti_pill->rc_req;
5324 mdt = mdt_dev(obd->obd_lu_dev);
5327 * first, check whether the stack is ready to handle requests
5328 * XXX: probably not very appropriate method is used now
5329 * at some point we should find a better one
5331 if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) &&
5332 !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) {
5333 rc = obd_health_check(env, mdt->mdt_child_exp->exp_obd);
5336 set_bit(MDT_FL_SYNCED, &mdt->mdt_state);
5339 rc = class_connect(&conn, obd, cluuid);
5343 lexp = class_conn2export(&conn);
5344 LASSERT(lexp != NULL);
5346 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5350 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5351 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5353 rc = mdt_connect_internal(lexp, mdt, data);
5355 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5358 info->mti_exp = lexp;
5359 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5360 rc = tgt_client_new(env, lexp);
5362 mdt_export_stats_init(obd, lexp, localdata);
5367 class_disconnect(lexp);
5376 static int mdt_obd_reconnect(const struct lu_env *env,
5377 struct obd_export *exp, struct obd_device *obd,
5378 struct obd_uuid *cluuid,
5379 struct obd_connect_data *data,
5382 struct mdt_thread_info *info;
5383 struct mdt_device *mdt;
5384 struct ptlrpc_request *req;
5388 if (exp == NULL || obd == NULL || cluuid == NULL)
5391 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5392 req = info->mti_pill->rc_req;
5393 mdt = mdt_dev(obd->obd_lu_dev);
5395 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5399 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5401 mdt_export_stats_init(obd, exp, localdata);
5406 static int mdt_export_cleanup(struct obd_export *exp)
5408 struct mdt_export_data *med = &exp->exp_mdt_data;
5409 struct obd_device *obd = exp->exp_obd;
5410 struct mdt_device *mdt;
5411 struct mdt_thread_info *info;
5413 CFS_LIST_HEAD(closing_list);
5414 struct mdt_file_data *mfd, *n;
5418 spin_lock(&med->med_open_lock);
5419 while (!cfs_list_empty(&med->med_open_head)) {
5420 cfs_list_t *tmp = med->med_open_head.next;
5421 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5423 /* Remove mfd handle so it can't be found again.
5424 * We are consuming the mfd_list reference here. */
5425 class_handle_unhash(&mfd->mfd_handle);
5426 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5428 spin_unlock(&med->med_open_lock);
5429 mdt = mdt_dev(obd->obd_lu_dev);
5430 LASSERT(mdt != NULL);
5432 rc = lu_env_init(&env, LCT_MD_THREAD);
5436 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5437 LASSERT(info != NULL);
5438 memset(info, 0, sizeof *info);
5439 info->mti_env = &env;
5440 info->mti_mdt = mdt;
5441 info->mti_exp = exp;
5443 if (!cfs_list_empty(&closing_list)) {
5444 struct md_attr *ma = &info->mti_attr;
5446 /* Close any open files (which may also cause orphan unlinking). */
5447 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5448 cfs_list_del_init(&mfd->mfd_list);
5449 ma->ma_need = ma->ma_valid = 0;
5450 /* Don't unlink orphan on failover umount, LU-184 */
5451 if (exp->exp_flags & OBD_OPT_FAILOVER) {
5452 ma->ma_valid = MA_FLAGS;
5453 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5455 mdt_mfd_close(info, mfd);
5458 info->mti_mdt = NULL;
5459 /* cleanup client slot early */
5460 /* Do not erase record for recoverable client. */
5461 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5462 tgt_client_del(&env, exp);
5468 static int mdt_obd_disconnect(struct obd_export *exp)
5474 class_export_get(exp);
5476 rc = server_disconnect_export(exp);
5478 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5480 rc = mdt_export_cleanup(exp);
5481 class_export_put(exp);
5485 /* FIXME: Can we avoid using these two interfaces? */
5486 static int mdt_init_export(struct obd_export *exp)
5488 struct mdt_export_data *med = &exp->exp_mdt_data;
5492 CFS_INIT_LIST_HEAD(&med->med_open_head);
5493 spin_lock_init(&med->med_open_lock);
5494 mutex_init(&med->med_idmap_mutex);
5495 med->med_idmap = NULL;
5496 spin_lock(&exp->exp_lock);
5497 exp->exp_connecting = 1;
5498 spin_unlock(&exp->exp_lock);
5500 /* self-export doesn't need client data and ldlm initialization */
5501 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5502 &exp->exp_client_uuid)))
5505 rc = tgt_client_alloc(exp);
5509 rc = ldlm_init_export(exp);
5516 tgt_client_free(exp);
5518 CERROR("%s: Failed to initialize export: rc = %d\n",
5519 exp->exp_obd->obd_name, rc);
5523 static int mdt_destroy_export(struct obd_export *exp)
5527 if (exp_connect_rmtclient(exp))
5528 mdt_cleanup_idmap(&exp->exp_mdt_data);
5530 target_destroy_export(exp);
5531 /* destroy can be called from failed obd_setup, so
5532 * checking uuid is safer than obd_self_export */
5533 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5534 &exp->exp_client_uuid)))
5537 ldlm_destroy_export(exp);
5538 tgt_client_free(exp);
5540 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5541 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5546 /** The maximum depth that fid2path() will search.
5547 * This is limited only because we want to store the fids for
5548 * historical path lookup purposes.
5550 #define MAX_PATH_DEPTH 100
5552 /** mdt_path() lookup structure. */
5553 struct path_lookup_info {
5554 __u64 pli_recno; /**< history point */
5555 __u64 pli_currec; /**< current record */
5556 struct lu_fid pli_fid;
5557 struct lu_fid pli_fids[MAX_PATH_DEPTH]; /**< path, in fids */
5558 struct mdt_object *pli_mdt_obj;
5559 char *pli_path; /**< full path */
5561 int pli_linkno; /**< which hardlink to follow */
5562 int pli_fidcount; /**< number of \a pli_fids */
5565 static int mdt_links_read(struct mdt_thread_info *info,
5566 struct mdt_object *mdt_obj, struct linkea_data *ldata)
5570 LASSERT(ldata->ld_buf->lb_buf != NULL);
5572 if (!mdt_object_exists(mdt_obj))
5575 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5576 ldata->ld_buf, XATTR_NAME_LINK);
5577 if (rc == -ERANGE) {
5578 /* Buf was too small, figure out what we need. */
5579 lu_buf_free(ldata->ld_buf);
5580 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5581 ldata->ld_buf, XATTR_NAME_LINK);
5584 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
5585 if (ldata->ld_buf->lb_buf == NULL)
5587 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5588 ldata->ld_buf, XATTR_NAME_LINK);
5598 static int mdt_path_current(struct mdt_thread_info *info,
5599 struct path_lookup_info *pli)
5601 struct mdt_device *mdt = info->mti_mdt;
5602 struct mdt_object *mdt_obj;
5603 struct link_ea_header *leh;
5604 struct link_ea_entry *lee;
5605 struct lu_name *tmpname = &info->mti_name;
5606 struct lu_fid *tmpfid = &info->mti_tmp_fid1;
5607 struct lu_buf *buf = &info->mti_big_buf;
5610 struct linkea_data ldata = { 0 };
5614 /* temp buffer for path element, the buffer will be finally freed
5615 * in mdt_thread_info_fini */
5616 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
5617 if (buf->lb_buf == NULL)
5621 ptr = pli->pli_path + pli->pli_pathlen - 1;
5624 pli->pli_fidcount = 0;
5625 pli->pli_fids[0] = *(struct lu_fid *)mdt_object_fid(pli->pli_mdt_obj);
5627 /* root FID only exists on MDT0, and fid2path should also ends at MDT0,
5628 * so checking root_fid can only happen on MDT0. */
5629 while (!lu_fid_eq(&mdt->mdt_md_root_fid,
5630 &pli->pli_fids[pli->pli_fidcount])) {
5631 mdt_obj = mdt_object_find(info->mti_env, mdt,
5632 &pli->pli_fids[pli->pli_fidcount]);
5633 if (IS_ERR(mdt_obj))
5634 GOTO(out, rc = PTR_ERR(mdt_obj));
5635 if (mdt_object_remote(mdt_obj)) {
5636 mdt_object_put(info->mti_env, mdt_obj);
5637 GOTO(remote_out, rc = -EREMOTE);
5639 if (!mdt_object_exists(mdt_obj)) {
5640 mdt_object_put(info->mti_env, mdt_obj);
5641 GOTO(out, rc = -ENOENT);
5644 rc = mdt_links_read(info, mdt_obj, &ldata);
5645 mdt_object_put(info->mti_env, mdt_obj);
5647 GOTO(out, rc = PTR_ERR(buf));
5650 lee = (struct link_ea_entry *)(leh + 1); /* link #0 */
5651 linkea_entry_unpack(lee, &reclen, tmpname, tmpfid);
5652 /* If set, use link #linkno for path lookup, otherwise use
5653 link #0. Only do this for the final path element. */
5654 if ((pli->pli_fidcount == 0) &&
5655 (pli->pli_linkno < leh->leh_reccount)) {
5657 for (count = 0; count < pli->pli_linkno; count++) {
5658 lee = (struct link_ea_entry *)
5659 ((char *)lee + reclen);
5660 linkea_entry_unpack(lee, &reclen, tmpname,
5663 if (pli->pli_linkno < leh->leh_reccount - 1)
5664 /* indicate to user there are more links */
5668 /* Pack the name in the end of the buffer */
5669 ptr -= tmpname->ln_namelen;
5670 if (ptr - 1 <= pli->pli_path)
5671 GOTO(out, rc = -EOVERFLOW);
5672 strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
5675 /* Store the parent fid for historic lookup */
5676 if (++pli->pli_fidcount >= MAX_PATH_DEPTH)
5677 GOTO(out, rc = -EOVERFLOW);
5678 pli->pli_fids[pli->pli_fidcount] = *tmpfid;
5682 ptr++; /* skip leading / */
5683 memmove(pli->pli_path, ptr, pli->pli_path + pli->pli_pathlen - ptr);
5690 /* Returns the full path to this fid, as of changelog record recno. */
5691 static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
5692 char *path, int pathlen, __u64 *recno, int *linkno,
5695 struct mdt_device *mdt = info->mti_mdt;
5696 struct path_lookup_info *pli;
5704 if (lu_fid_eq(&mdt->mdt_md_root_fid, mdt_object_fid(obj))) {
5713 pli->pli_mdt_obj = obj;
5714 pli->pli_recno = *recno;
5715 pli->pli_path = path;
5716 pli->pli_pathlen = pathlen;
5717 pli->pli_linkno = *linkno;
5719 /* Retry multiple times in case file is being moved */
5720 while (tries-- && rc == -EAGAIN)
5721 rc = mdt_path_current(info, pli);
5723 /* return the last resolved fids to the client, so the client will
5724 * build the left path on another MDT for remote object */
5725 *fid = pli->pli_fids[pli->pli_fidcount];
5727 *recno = pli->pli_currec;
5728 /* Return next link index to caller */
5729 *linkno = pli->pli_linkno;
5736 static int mdt_fid2path(struct mdt_thread_info *info,
5737 struct getinfo_fid2path *fp)
5739 struct mdt_device *mdt = info->mti_mdt;
5740 struct mdt_object *obj;
5744 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5745 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5747 if (!fid_is_sane(&fp->gf_fid))
5750 if (!fid_is_namespace_visible(&fp->gf_fid)) {
5751 CWARN("%s: "DFID" is invalid, sequence should be "
5752 ">= "LPX64"\n", mdt_obd_name(mdt),
5753 PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
5757 obj = mdt_object_find(info->mti_env, mdt, &fp->gf_fid);
5758 if (obj == NULL || IS_ERR(obj)) {
5759 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5764 if (mdt_object_remote(obj))
5766 else if (!mdt_object_exists(obj))
5772 mdt_object_put(info->mti_env, obj);
5773 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5774 PFID(&fp->gf_fid), rc);
5778 rc = mdt_path(info, obj, fp->gf_path, fp->gf_pathlen, &fp->gf_recno,
5779 &fp->gf_linkno, &fp->gf_fid);
5781 CDEBUG(D_INFO, "fid "DFID", path %s recno "LPX64" linkno %u\n",
5782 PFID(&fp->gf_fid), fp->gf_path, fp->gf_recno, fp->gf_linkno);
5784 mdt_object_put(info->mti_env, obj);
5789 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5790 void *val, int vallen)
5792 struct getinfo_fid2path *fpout, *fpin;
5795 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5798 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5799 lustre_swab_fid2path(fpin);
5801 memcpy(fpout, fpin, sizeof(*fpin));
5802 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5805 rc = mdt_fid2path(info, fpout);
5809 int mdt_get_info(struct mdt_thread_info *info)
5811 struct ptlrpc_request *req = mdt_info_req(info);
5819 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5821 CDEBUG(D_IOCTL, "No GETINFO key");
5824 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5827 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5828 if (vallen == NULL) {
5829 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5833 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5835 rc = req_capsule_server_pack(info->mti_pill);
5836 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5837 if (valout == NULL) {
5838 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5842 if (KEY_IS(KEY_FID2PATH))
5843 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5847 lustre_msg_set_status(req->rq_repmsg, rc);
5852 /* Pass the ioc down */
5853 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5854 unsigned int cmd, int len, void *data)
5856 struct lu_context ioctl_session;
5857 struct md_device *next = mdt->mdt_child;
5861 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5864 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5865 lu_context_enter(&ioctl_session);
5866 env->le_ses = &ioctl_session;
5868 LASSERT(next->md_ops->mdo_iocontrol);
5869 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5871 lu_context_exit(&ioctl_session);
5872 lu_context_fini(&ioctl_session);
5876 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5878 struct obd_ioctl_data *data = karg;
5881 struct mdt_object *obj;
5882 struct mdt_lock_handle *lh;
5886 if (data->ioc_inlbuf1 == NULL || data->ioc_inllen1 != sizeof(*fid) ||
5887 data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
5890 fid = (struct lu_fid *)data->ioc_inlbuf1;
5892 if (!fid_is_sane(fid))
5895 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5897 lh = &mti->mti_lh[MDT_LH_PARENT];
5898 mdt_lock_reg_init(lh, LCK_CR);
5900 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5902 RETURN(PTR_ERR(obj));
5904 if (mdt_object_remote(obj)) {
5907 * before calling version get the correct MDS should be
5908 * fid, this is error to find remote object here
5910 CERROR("nonlocal object "DFID"\n", PFID(fid));
5911 } else if (!mdt_object_exists(obj)) {
5912 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5915 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5916 *(__u64 *)data->ioc_inlbuf2 = version;
5919 mdt_object_unlock_put(mti, obj, lh, 1);
5923 /* ioctls on obd dev */
5924 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5925 void *karg, void *uarg)
5928 struct obd_device *obd = exp->exp_obd;
5929 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5930 struct dt_device *dt = mdt->mdt_bottom;
5934 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5935 rc = lu_env_init(&env, LCT_MD_THREAD);
5941 rc = mdt_device_sync(&env, mdt);
5943 case OBD_IOC_SET_READONLY:
5944 rc = dt->dd_ops->dt_ro(&env, dt);
5946 case OBD_IOC_ABORT_RECOVERY:
5947 CERROR("%s: Aborting recovery for device\n", mdt_obd_name(mdt));
5948 target_stop_recovery_thread(obd);
5951 case OBD_IOC_CHANGELOG_REG:
5952 case OBD_IOC_CHANGELOG_DEREG:
5953 case OBD_IOC_CHANGELOG_CLEAR:
5954 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5956 case OBD_IOC_START_LFSCK: {
5957 struct md_device *next = mdt->mdt_child;
5958 struct obd_ioctl_data *data = karg;
5959 struct lfsck_start_param lsp;
5961 if (unlikely(data == NULL)) {
5966 lsp.lsp_start = (struct lfsck_start *)(data->ioc_inlbuf1);
5967 lsp.lsp_namespace = mdt->mdt_namespace;
5968 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, &lsp);
5971 case OBD_IOC_STOP_LFSCK: {
5972 struct md_device *next = mdt->mdt_child;
5974 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, NULL);
5977 case OBD_IOC_GET_OBJ_VERSION: {
5978 struct mdt_thread_info *mti;
5979 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5980 memset(mti, 0, sizeof *mti);
5981 mti->mti_env = &env;
5985 rc = mdt_ioc_version_get(mti, karg);
5990 CERROR("%s: Not supported cmd = %d, rc = %d\n",
5991 mdt_obd_name(mdt), cmd, rc);
5998 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
6000 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
6004 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
6008 int mdt_obd_postrecov(struct obd_device *obd)
6013 rc = lu_env_init(&env, LCT_MD_THREAD);
6016 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
6021 static struct obd_ops mdt_obd_device_ops = {
6022 .o_owner = THIS_MODULE,
6023 .o_set_info_async = mdt_obd_set_info_async,
6024 .o_connect = mdt_obd_connect,
6025 .o_reconnect = mdt_obd_reconnect,
6026 .o_disconnect = mdt_obd_disconnect,
6027 .o_init_export = mdt_init_export,
6028 .o_destroy_export = mdt_destroy_export,
6029 .o_iocontrol = mdt_iocontrol,
6030 .o_postrecov = mdt_obd_postrecov,
6033 static struct lu_device* mdt_device_fini(const struct lu_env *env,
6034 struct lu_device *d)
6036 struct mdt_device *m = mdt_dev(d);
6043 static struct lu_device *mdt_device_free(const struct lu_env *env,
6044 struct lu_device *d)
6046 struct mdt_device *m = mdt_dev(d);
6049 md_device_fini(&m->mdt_md_dev);
6054 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
6055 struct lu_device_type *t,
6056 struct lustre_cfg *cfg)
6058 struct lu_device *l;
6059 struct mdt_device *m;
6065 l = &m->mdt_md_dev.md_lu_dev;
6066 rc = mdt_init0(env, m, t, cfg);
6068 mdt_device_free(env, l);
6073 l = ERR_PTR(-ENOMEM);
6077 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
6078 LU_KEY_INIT(mdt, struct mdt_thread_info);
6080 static void mdt_key_fini(const struct lu_context *ctx,
6081 struct lu_context_key *key, void* data)
6083 struct mdt_thread_info *info = data;
6085 if (info->mti_big_lmm) {
6086 OBD_FREE_LARGE(info->mti_big_lmm, info->mti_big_lmmsize);
6087 info->mti_big_lmm = NULL;
6088 info->mti_big_lmmsize = 0;
6093 /* context key: mdt_thread_key */
6094 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
6096 struct lu_ucred *mdt_ucred(const struct mdt_thread_info *info)
6098 return lu_ucred(info->mti_env);
6101 struct lu_ucred *mdt_ucred_check(const struct mdt_thread_info *info)
6103 return lu_ucred_check(info->mti_env);
6107 * Enable/disable COS (Commit On Sharing).
6109 * Set/Clear the COS flag in mdt options.
6111 * \param mdt mdt device
6112 * \param val 0 disables COS, other values enable COS
6114 void mdt_enable_cos(struct mdt_device *mdt, int val)
6119 mdt->mdt_opts.mo_cos = !!val;
6120 rc = lu_env_init(&env, LCT_LOCAL);
6121 if (unlikely(rc != 0)) {
6122 CWARN("lu_env initialization failed with rc = %d,"
6123 "cannot sync\n", rc);
6126 mdt_device_sync(&env, mdt);
6131 * Check COS (Commit On Sharing) status.
6133 * Return COS flag status.
6135 * \param mdt mdt device
6137 int mdt_cos_is_enabled(struct mdt_device *mdt)
6139 return mdt->mdt_opts.mo_cos != 0;
6142 static struct lu_device_type_operations mdt_device_type_ops = {
6143 .ldto_device_alloc = mdt_device_alloc,
6144 .ldto_device_free = mdt_device_free,
6145 .ldto_device_fini = mdt_device_fini
6148 static struct lu_device_type mdt_device_type = {
6149 .ldt_tags = LU_DEVICE_MD,
6150 .ldt_name = LUSTRE_MDT_NAME,
6151 .ldt_ops = &mdt_device_type_ops,
6152 .ldt_ctx_tags = LCT_MD_THREAD
6155 static int __init mdt_mod_init(void)
6157 struct lprocfs_static_vars lvars;
6160 CLASSERT(sizeof("0x0123456789ABCDEF:0x01234567:0x01234567") ==
6161 FID_NOBRACE_LEN + 1);
6162 CLASSERT(sizeof("[0x0123456789ABCDEF:0x01234567:0x01234567]") ==
6164 rc = lu_kmem_init(mdt_caches);
6168 rc = mds_mod_init();
6172 lprocfs_mdt_init_vars(&lvars);
6173 rc = class_register_type(&mdt_obd_device_ops, NULL,
6174 lvars.module_vars, LUSTRE_MDT_NAME,
6180 lu_kmem_fini(mdt_caches);
6187 static void __exit mdt_mod_exit(void)
6189 class_unregister_type(LUSTRE_MDT_NAME);
6191 lu_kmem_fini(mdt_caches);
6194 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6195 MODULE_DESCRIPTION("Lustre Metadata Target ("LUSTRE_MDT_NAME")");
6196 MODULE_LICENSE("GPL");
6198 cfs_module(mdt, LUSTRE_VERSION_STRING, mdt_mod_init, mdt_mod_exit);