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_log.h>
66 #include "mdt_internal.h"
67 #include <lustre_acl.h>
68 #include <lustre_param.h>
69 #include <lustre_quota.h>
70 #include <lustre_lfsck.h>
72 mdl_mode_t mdt_mdl_lock_modes[] = {
73 [LCK_MINMODE] = MDL_MINMODE,
80 [LCK_GROUP] = MDL_GROUP
83 ldlm_mode_t mdt_dlm_lock_modes[] = {
84 [MDL_MINMODE] = LCK_MINMODE,
91 [MDL_GROUP] = LCK_GROUP
94 static struct mdt_device *mdt_dev(struct lu_device *d);
95 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
97 static const struct lu_object_operations mdt_obj_ops;
99 /* Slab for MDT object allocation */
100 static struct kmem_cache *mdt_object_kmem;
102 /* For HSM restore handles */
103 struct kmem_cache *mdt_hsm_cdt_kmem;
105 /* For HSM request handles */
106 struct kmem_cache *mdt_hsm_car_kmem;
108 static struct lu_kmem_descr mdt_caches[] = {
110 .ckd_cache = &mdt_object_kmem,
111 .ckd_name = "mdt_obj",
112 .ckd_size = sizeof(struct mdt_object)
115 .ckd_cache = &mdt_hsm_cdt_kmem,
116 .ckd_name = "mdt_cdt_restore_handle",
117 .ckd_size = sizeof(struct cdt_restore_handle)
120 .ckd_cache = &mdt_hsm_car_kmem,
121 .ckd_name = "mdt_cdt_agent_req",
122 .ckd_size = sizeof(struct cdt_agent_req)
129 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
133 return (rep->lock_policy_res1 & flag);
136 void mdt_clear_disposition(struct mdt_thread_info *info,
137 struct ldlm_reply *rep, int flag)
140 info->mti_opdata &= ~flag;
141 tgt_opdata_clear(info->mti_env, flag);
144 rep->lock_policy_res1 &= ~flag;
147 void mdt_set_disposition(struct mdt_thread_info *info,
148 struct ldlm_reply *rep, int flag)
151 info->mti_opdata |= flag;
152 tgt_opdata_set(info->mti_env, flag);
155 rep->lock_policy_res1 |= flag;
158 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
160 lh->mlh_pdo_hash = 0;
161 lh->mlh_reg_mode = lm;
162 lh->mlh_rreg_mode = lm;
163 lh->mlh_type = MDT_REG_LOCK;
166 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lock_mode,
167 const struct lu_name *lname)
169 lh->mlh_reg_mode = lock_mode;
170 lh->mlh_rreg_mode = lock_mode;
171 lh->mlh_type = MDT_PDO_LOCK;
173 if (lu_name_is_valid(lname)) {
174 lh->mlh_pdo_hash = full_name_hash(lname->ln_name,
176 /* XXX Workaround for LU-2856
178 * Zero is a valid return value of full_name_hash, but
179 * several users of mlh_pdo_hash assume a non-zero
180 * hash value. We therefore map zero onto an
181 * arbitrary, but consistent value (1) to avoid
182 * problems further down the road. */
183 if (unlikely(lh->mlh_pdo_hash == 0))
184 lh->mlh_pdo_hash = 1;
186 lh->mlh_pdo_hash = 0;
190 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
191 struct mdt_lock_handle *lh)
197 * Any dir access needs couple of locks:
199 * 1) on part of dir we gonna take lookup/modify;
201 * 2) on whole dir to protect it from concurrent splitting and/or to
202 * flush client's cache for readdir().
204 * so, for a given mode and object this routine decides what lock mode
205 * to use for lock #2:
207 * 1) if caller's gonna lookup in dir then we need to protect dir from
208 * being splitted only - LCK_CR
210 * 2) if caller's gonna modify dir then we need to protect dir from
211 * being splitted and to flush cache - LCK_CW
213 * 3) if caller's gonna modify dir and that dir seems ready for
214 * splitting then we need to protect it from any type of access
215 * (lookup/modify/split) - LCK_EX --bzzz
218 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
219 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
222 * Ask underlaying level its opinion about preferable PDO lock mode
223 * having access type passed as regular lock mode:
225 * - MDL_MINMODE means that lower layer does not want to specify lock
228 * - MDL_NL means that no PDO lock should be taken. This is used in some
229 * cases. Say, for non-splittable directories no need to use PDO locks
232 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
233 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
235 if (mode != MDL_MINMODE) {
236 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
239 * Lower layer does not want to specify locking mode. We do it
240 * our selves. No special protection is needed, just flush
241 * client's cache on modification and allow concurrent
244 switch (lh->mlh_reg_mode) {
246 lh->mlh_pdo_mode = LCK_EX;
249 lh->mlh_pdo_mode = LCK_CR;
252 lh->mlh_pdo_mode = LCK_CW;
255 CERROR("Not expected lock type (0x%x)\n",
256 (int)lh->mlh_reg_mode);
261 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
265 int mdt_getstatus(struct tgt_session_info *tsi)
267 struct mdt_thread_info *info = tsi2mdt_info(tsi);
268 struct mdt_device *mdt = info->mti_mdt;
269 struct mdt_body *repbody;
274 rc = mdt_check_ucred(info);
276 GOTO(out, rc = err_serious(rc));
278 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
279 GOTO(out, rc = err_serious(-ENOMEM));
281 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
282 repbody->fid1 = mdt->mdt_md_root_fid;
283 repbody->valid |= OBD_MD_FLID;
285 if (tsi->tsi_tgt->lut_mds_capa &&
286 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
287 struct mdt_object *root;
288 struct lustre_capa *capa;
290 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
292 GOTO(out, rc = PTR_ERR(root));
294 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
296 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
297 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
299 mdt_object_put(info->mti_env, root);
301 repbody->valid |= OBD_MD_FLMDSCAPA;
305 mdt_thread_info_fini(info);
309 int mdt_statfs(struct tgt_session_info *tsi)
311 struct ptlrpc_request *req = tgt_ses_req(tsi);
312 struct mdt_thread_info *info = tsi2mdt_info(tsi);
313 struct md_device *next = info->mti_mdt->mdt_child;
314 struct ptlrpc_service_part *svcpt;
315 struct obd_statfs *osfs;
320 svcpt = req->rq_rqbd->rqbd_svcpt;
322 /* This will trigger a watchdog timeout */
323 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
324 (MDT_SERVICE_WATCHDOG_FACTOR *
325 at_get(&svcpt->scp_at_estimate)) + 1);
327 rc = mdt_check_ucred(info);
329 GOTO(out, rc = err_serious(rc));
331 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
332 GOTO(out, rc = err_serious(-ENOMEM));
334 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
336 GOTO(out, rc = -EPROTO);
338 /** statfs information are cached in the mdt_device */
339 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
340 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
341 /** statfs data is too old, get up-to-date one */
342 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
345 spin_lock(&info->mti_mdt->mdt_osfs_lock);
346 info->mti_mdt->mdt_osfs = *osfs;
347 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
348 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
350 /** use cached statfs data */
351 spin_lock(&info->mti_mdt->mdt_osfs_lock);
352 *osfs = info->mti_mdt->mdt_osfs;
353 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
357 mdt_counter_incr(req, LPROC_MDT_STATFS);
359 mdt_thread_info_fini(info);
364 * Pack SOM attributes into the reply.
365 * Call under a DLM UPDATE lock.
367 static void mdt_pack_size2body(struct mdt_thread_info *info,
368 struct mdt_object *mo)
371 struct md_attr *ma = &info->mti_attr;
373 LASSERT(ma->ma_attr.la_valid & LA_MODE);
374 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
376 /* Check if Size-on-MDS is supported, if this is a regular file,
377 * if SOM is enabled on the object and if SOM cache exists and valid.
378 * Otherwise do not pack Size-on-MDS attributes to the reply. */
379 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
380 !S_ISREG(ma->ma_attr.la_mode) ||
381 !mdt_object_is_som_enabled(mo) ||
382 !(ma->ma_valid & MA_SOM))
385 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
386 b->size = ma->ma_som->msd_size;
387 b->blocks = ma->ma_som->msd_blocks;
390 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
391 const struct lu_attr *attr, const struct lu_fid *fid)
393 struct md_attr *ma = &info->mti_attr;
395 LASSERT(ma->ma_valid & MA_INODE);
397 b->atime = attr->la_atime;
398 b->mtime = attr->la_mtime;
399 b->ctime = attr->la_ctime;
400 b->mode = attr->la_mode;
401 b->size = attr->la_size;
402 b->blocks = attr->la_blocks;
403 b->uid = attr->la_uid;
404 b->gid = attr->la_gid;
405 b->flags = attr->la_flags;
406 b->nlink = attr->la_nlink;
407 b->rdev = attr->la_rdev;
409 /*XXX should pack the reply body according to lu_valid*/
410 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
411 OBD_MD_FLGID | OBD_MD_FLTYPE |
412 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
413 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
415 if (!S_ISREG(attr->la_mode)) {
416 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
417 } else if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV)) {
418 /* means no objects are allocated on osts. */
419 LASSERT(!(ma->ma_valid & MA_LOV));
420 /* just ignore blocks occupied by extend attributes on MDS */
422 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
423 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
424 } else if ((ma->ma_valid & MA_LOV) && ma->ma_lmm != NULL &&
425 ma->ma_lmm->lmm_pattern & LOV_PATTERN_F_RELEASED) {
426 /* A released file stores its size on MDS. */
427 /* But return 1 block for released file, unless tools like tar
428 * will consider it fully sparse. (LU-3864)
430 if (unlikely(b->size == 0))
434 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
439 b->valid |= OBD_MD_FLID;
440 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
441 PFID(fid), b->nlink, b->mode, b->size);
445 mdt_body_reverse_idmap(info, b);
447 if (fid != NULL && (b->valid & OBD_MD_FLSIZE))
448 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
449 PFID(fid), (unsigned long long)b->size);
452 static inline int mdt_body_has_lov(const struct lu_attr *la,
453 const struct mdt_body *body)
455 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
456 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
459 void mdt_client_compatibility(struct mdt_thread_info *info)
461 struct mdt_body *body;
462 struct ptlrpc_request *req = mdt_info_req(info);
463 struct obd_export *exp = req->rq_export;
464 struct md_attr *ma = &info->mti_attr;
465 struct lu_attr *la = &ma->ma_attr;
468 if (exp_connect_layout(exp))
469 /* the client can deal with 16-bit lmm_stripe_count */
472 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
474 if (!mdt_body_has_lov(la, body))
477 /* now we have a reply with a lov for a client not compatible with the
478 * layout lock so we have to clean the layout generation number */
479 if (S_ISREG(la->la_mode))
480 ma->ma_lmm->lmm_layout_gen = 0;
484 static int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o,
487 const struct lu_env *env = info->mti_env;
491 LASSERT(info->mti_big_lmm_used == 0);
492 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL, name);
496 /* big_lmm may need to be grown */
497 if (info->mti_big_lmmsize < rc) {
498 int size = size_roundup_power2(rc);
500 if (info->mti_big_lmmsize > 0) {
501 /* free old buffer */
502 LASSERT(info->mti_big_lmm);
503 OBD_FREE_LARGE(info->mti_big_lmm,
504 info->mti_big_lmmsize);
505 info->mti_big_lmm = NULL;
506 info->mti_big_lmmsize = 0;
509 OBD_ALLOC_LARGE(info->mti_big_lmm, size);
510 if (info->mti_big_lmm == NULL)
512 info->mti_big_lmmsize = size;
514 LASSERT(info->mti_big_lmmsize >= rc);
516 info->mti_buf.lb_buf = info->mti_big_lmm;
517 info->mti_buf.lb_len = info->mti_big_lmmsize;
518 rc = mo_xattr_get(env, mdt_object_child(o), &info->mti_buf, name);
523 int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o,
524 struct md_attr *ma, const char *name)
526 struct md_object *next = mdt_object_child(o);
527 struct lu_buf *buf = &info->mti_buf;
530 if (strcmp(name, XATTR_NAME_LOV) == 0) {
531 buf->lb_buf = ma->ma_lmm;
532 buf->lb_len = ma->ma_lmm_size;
533 LASSERT(!(ma->ma_valid & MA_LOV));
534 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
535 buf->lb_buf = ma->ma_lmv;
536 buf->lb_len = ma->ma_lmv_size;
537 LASSERT(!(ma->ma_valid & MA_LMV));
538 } else if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) {
539 buf->lb_buf = ma->ma_lmv;
540 buf->lb_len = ma->ma_lmv_size;
541 LASSERT(!(ma->ma_valid & MA_LMV_DEF));
546 rc = mo_xattr_get(info->mti_env, next, buf, name);
548 if (strcmp(name, XATTR_NAME_LOV) == 0) {
549 ma->ma_lmm_size = rc;
550 ma->ma_valid |= MA_LOV;
551 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
552 ma->ma_lmv_size = rc;
553 ma->ma_valid |= MA_LMV;
554 } else if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) {
555 ma->ma_lmv_size = rc;
556 ma->ma_valid |= MA_LMV_DEF;
560 } else if (rc == -ENODATA) {
563 } else if (rc == -ERANGE) {
564 /* Default LMV has fixed size, so it must be able to fit
565 * in the original buffer */
566 if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)
568 rc = mdt_big_xattr_get(info, o, name);
570 info->mti_big_lmm_used = 1;
571 if (!strcmp(name, XATTR_NAME_LOV)) {
572 ma->ma_valid |= MA_LOV;
573 ma->ma_lmm = info->mti_big_lmm;
574 ma->ma_lmm_size = rc;
575 } else if (!strcmp(name, XATTR_NAME_LMV)) {
576 ma->ma_valid |= MA_LMV;
577 ma->ma_lmv = info->mti_big_lmm;
578 ma->ma_lmv_size = rc;
583 /* update mdt_max_mdsize so all clients
584 * will be aware about that */
585 if (info->mti_mdt->mdt_max_mdsize < rc)
586 info->mti_mdt->mdt_max_mdsize = rc;
594 int mdt_attr_get_pfid(struct mdt_thread_info *info,
595 struct mdt_object *o, struct lu_fid *pfid)
597 struct lu_buf *buf = &info->mti_buf;
598 struct link_ea_header *leh;
599 struct link_ea_entry *lee;
603 buf->lb_buf = info->mti_big_lmm;
604 buf->lb_len = info->mti_big_lmmsize;
605 rc = mo_xattr_get(info->mti_env, mdt_object_child(o),
606 buf, XATTR_NAME_LINK);
607 /* ignore errors, MA_PFID won't be set and it is
608 * up to the caller to treat this as an error */
609 if (rc == -ERANGE || buf->lb_len == 0) {
610 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LINK);
611 buf->lb_buf = info->mti_big_lmm;
612 buf->lb_len = info->mti_big_lmmsize;
617 if (rc < sizeof(*leh)) {
618 CERROR("short LinkEA on "DFID": rc = %d\n",
619 PFID(mdt_object_fid(o)), rc);
623 leh = (struct link_ea_header *) buf->lb_buf;
624 lee = (struct link_ea_entry *)(leh + 1);
625 if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) {
626 leh->leh_magic = LINK_EA_MAGIC;
627 leh->leh_reccount = __swab32(leh->leh_reccount);
628 leh->leh_len = __swab64(leh->leh_len);
630 if (leh->leh_magic != LINK_EA_MAGIC)
632 if (leh->leh_reccount == 0)
635 memcpy(pfid, &lee->lee_parent_fid, sizeof(*pfid));
636 fid_be_to_cpu(pfid, pfid);
641 int mdt_attr_get_complex(struct mdt_thread_info *info,
642 struct mdt_object *o, struct md_attr *ma)
644 const struct lu_env *env = info->mti_env;
645 struct md_object *next = mdt_object_child(o);
646 struct lu_buf *buf = &info->mti_buf;
647 u32 mode = lu_object_attr(&next->mo_lu);
648 int need = ma->ma_need;
654 if (need & MA_INODE) {
655 ma->ma_need = MA_INODE;
656 rc = mo_attr_get(env, next, ma);
659 ma->ma_valid |= MA_INODE;
662 if (need & MA_PFID) {
663 rc = mdt_attr_get_pfid(info, o, &ma->ma_pfid);
665 ma->ma_valid |= MA_PFID;
666 /* ignore this error, parent fid is not mandatory */
670 if (need & MA_LOV && (S_ISREG(mode) || S_ISDIR(mode))) {
671 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LOV);
676 if (need & MA_LMV && S_ISDIR(mode)) {
677 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LMV);
682 if (need & MA_LMV_DEF && S_ISDIR(mode)) {
683 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_DEFAULT_LMV);
688 if (need & MA_SOM && S_ISREG(mode)) {
689 buf->lb_buf = info->mti_xattr_buf;
690 buf->lb_len = sizeof(info->mti_xattr_buf);
691 CLASSERT(sizeof(struct som_attrs) <=
692 sizeof(info->mti_xattr_buf));
693 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_SOM);
694 rc2 = lustre_buf2som(info->mti_xattr_buf, rc2, ma->ma_som);
696 ma->ma_valid |= MA_SOM;
697 else if (rc2 < 0 && rc2 != -ENODATA)
701 if (need & MA_HSM && S_ISREG(mode)) {
702 buf->lb_buf = info->mti_xattr_buf;
703 buf->lb_len = sizeof(info->mti_xattr_buf);
704 CLASSERT(sizeof(struct hsm_attrs) <=
705 sizeof(info->mti_xattr_buf));
706 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_HSM);
707 rc2 = lustre_buf2hsm(info->mti_xattr_buf, rc2, &ma->ma_hsm);
709 ma->ma_valid |= MA_HSM;
710 else if (rc2 < 0 && rc2 != -ENODATA)
714 #ifdef CONFIG_FS_POSIX_ACL
715 if (need & MA_ACL_DEF && S_ISDIR(mode)) {
716 buf->lb_buf = ma->ma_acl;
717 buf->lb_len = ma->ma_acl_size;
718 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_DEFAULT);
720 ma->ma_acl_size = rc2;
721 ma->ma_valid |= MA_ACL_DEF;
722 } else if (rc2 == -ENODATA) {
731 CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = "LPX64" ma_lmm=%p\n",
732 rc, ma->ma_valid, ma->ma_lmm);
736 static int mdt_getattr_internal(struct mdt_thread_info *info,
737 struct mdt_object *o, int ma_need)
739 struct md_object *next = mdt_object_child(o);
740 const struct mdt_body *reqbody = info->mti_body;
741 struct ptlrpc_request *req = mdt_info_req(info);
742 struct md_attr *ma = &info->mti_attr;
743 struct lu_attr *la = &ma->ma_attr;
744 struct req_capsule *pill = info->mti_pill;
745 const struct lu_env *env = info->mti_env;
746 struct mdt_body *repbody;
747 struct lu_buf *buffer = &info->mti_buf;
752 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
753 RETURN(err_serious(-ENOMEM));
755 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
759 if (mdt_object_remote(o)) {
760 /* This object is located on remote node.*/
761 /* Return -EIO for old client */
762 if (!mdt_is_dne_client(req->rq_export))
763 GOTO(out, rc = -EIO);
765 repbody->fid1 = *mdt_object_fid(o);
766 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
770 buffer->lb_len = reqbody->eadatasize;
771 if (buffer->lb_len > 0) {
772 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
773 if (buffer->lb_buf == NULL)
774 GOTO(out, rc = -EPROTO);
776 buffer->lb_buf = NULL;
777 ma_need &= ~(MA_LOV | MA_LMV);
778 CDEBUG(D_INFO, "%s: RPC from %s: does not need LOVEA.\n",
779 mdt_obd_name(info->mti_mdt),
780 req->rq_export->exp_client_uuid.uuid);
783 /* If it is dir object and client require MEA, then we got MEA */
784 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
785 (reqbody->valid & (OBD_MD_MEA | OBD_MD_DEFAULT_MEA))) {
786 /* Assumption: MDT_MD size is enough for lmv size. */
787 ma->ma_lmv = buffer->lb_buf;
788 ma->ma_lmv_size = buffer->lb_len;
789 ma->ma_need = MA_INODE;
790 if (ma->ma_lmv_size > 0) {
791 if (reqbody->valid & OBD_MD_MEA)
792 ma->ma_need |= MA_LMV;
793 else if (reqbody->valid & OBD_MD_DEFAULT_MEA)
794 ma->ma_need |= MA_LMV_DEF;
797 ma->ma_lmm = buffer->lb_buf;
798 ma->ma_lmm_size = buffer->lb_len;
799 ma->ma_need = MA_INODE | MA_HSM;
800 if (ma->ma_lmm_size > 0)
801 ma->ma_need |= MA_LOV;
804 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
805 reqbody->valid & OBD_MD_FLDIREA &&
806 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
807 /* get default stripe info for this dir. */
808 ma->ma_need |= MA_LOV_DEF;
810 ma->ma_need |= ma_need;
811 if (ma->ma_need & MA_SOM)
812 ma->ma_som = &info->mti_u.som.data;
814 rc = mdt_attr_get_complex(info, o, ma);
816 CERROR("%s: getattr error for "DFID": rc = %d\n",
817 mdt_obd_name(info->mti_mdt),
818 PFID(mdt_object_fid(o)), rc);
822 /* if file is released, check if a restore is running */
823 if ((ma->ma_valid & MA_HSM) && (ma->ma_hsm.mh_flags & HS_RELEASED) &&
824 mdt_hsm_restore_is_running(info, mdt_object_fid(o))) {
825 repbody->t_state = MS_RESTORE;
826 repbody->valid |= OBD_MD_TSTATE;
829 is_root = lu_fid_eq(mdt_object_fid(o), &info->mti_mdt->mdt_md_root_fid);
831 /* the Lustre protocol supposes to return default striping
832 * on the user-visible root if explicitly requested */
833 if ((ma->ma_valid & MA_LOV) == 0 && S_ISDIR(la->la_mode) &&
834 (ma->ma_need & MA_LOV_DEF && is_root) && ma->ma_need & MA_LOV) {
835 struct lu_fid rootfid;
836 struct mdt_object *root;
837 struct mdt_device *mdt = info->mti_mdt;
839 rc = dt_root_get(env, mdt->mdt_bottom, &rootfid);
842 root = mdt_object_find(env, mdt, &rootfid);
844 RETURN(PTR_ERR(root));
845 rc = mdt_stripe_get(info, root, ma, XATTR_NAME_LOV);
846 mdt_object_put(info->mti_env, root);
848 CERROR("%s: getattr error for "DFID": rc = %d\n",
849 mdt_obd_name(info->mti_mdt),
850 PFID(mdt_object_fid(o)), rc);
855 if (likely(ma->ma_valid & MA_INODE))
856 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
860 if (mdt_body_has_lov(la, reqbody)) {
861 if (ma->ma_valid & MA_LOV) {
862 LASSERT(ma->ma_lmm_size);
863 mdt_dump_lmm(D_INFO, ma->ma_lmm);
864 repbody->eadatasize = ma->ma_lmm_size;
865 if (S_ISDIR(la->la_mode))
866 repbody->valid |= OBD_MD_FLDIREA;
868 repbody->valid |= OBD_MD_FLEASIZE;
870 if (ma->ma_valid & MA_LMV) {
871 LASSERT(S_ISDIR(la->la_mode));
872 mdt_dump_lmv(D_INFO, ma->ma_lmv);
873 repbody->eadatasize = ma->ma_lmv_size;
874 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
876 if (ma->ma_valid & MA_LMV_DEF) {
877 LASSERT(S_ISDIR(la->la_mode));
878 repbody->eadatasize = ma->ma_lmv_size;
879 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_DEFAULT_MEA);
881 } else if (S_ISLNK(la->la_mode) &&
882 reqbody->valid & OBD_MD_LINKNAME) {
883 buffer->lb_buf = ma->ma_lmm;
884 /* eadatasize from client includes NULL-terminator, so
885 * there is no need to read it */
886 buffer->lb_len = reqbody->eadatasize - 1;
887 rc = mo_readlink(env, next, buffer);
888 if (unlikely(rc <= 0)) {
889 CERROR("%s: readlink failed for "DFID": rc = %d\n",
890 mdt_obd_name(info->mti_mdt),
891 PFID(mdt_object_fid(o)), rc);
894 int print_limit = min_t(int, PAGE_CACHE_SIZE - 128, rc);
896 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
898 repbody->valid |= OBD_MD_LINKNAME;
899 /* we need to report back size with NULL-terminator
900 * because client expects that */
901 repbody->eadatasize = rc + 1;
902 if (repbody->eadatasize != reqbody->eadatasize)
903 CDEBUG(D_INODE, "%s: Read shorter symlink %d "
904 "on "DFID ", expected %d\n",
905 mdt_obd_name(info->mti_mdt),
906 rc, PFID(mdt_object_fid(o)),
907 reqbody->eadatasize - 1);
909 ((char *)ma->ma_lmm)[rc] = 0;
911 /* If the total CDEBUG() size is larger than a page, it
912 * will print a warning to the console, avoid this by
913 * printing just the last part of the symlink. */
914 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
915 print_limit < rc ? "..." : "", print_limit,
916 (char *)ma->ma_lmm + rc - print_limit, rc);
921 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
922 repbody->max_cookiesize = 0;
923 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
924 repbody->valid |= OBD_MD_FLMODEASIZE;
925 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
926 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
927 repbody->max_cookiesize);
930 if (exp_connect_rmtclient(info->mti_exp) &&
931 reqbody->valid & OBD_MD_FLRMTPERM) {
932 void *buf = req_capsule_server_get(pill, &RMF_ACL);
934 /* mdt_getattr_lock only */
935 rc = mdt_pack_remote_perm(info, o, buf);
937 repbody->valid &= ~OBD_MD_FLRMTPERM;
938 repbody->aclsize = 0;
941 repbody->valid |= OBD_MD_FLRMTPERM;
942 repbody->aclsize = sizeof(struct mdt_remote_perm);
945 #ifdef CONFIG_FS_POSIX_ACL
946 else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
947 (reqbody->valid & OBD_MD_FLACL)) {
948 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
949 buffer->lb_len = req_capsule_get_size(pill,
950 &RMF_ACL, RCL_SERVER);
951 if (buffer->lb_len > 0) {
952 rc = mo_xattr_get(env, next, buffer,
953 XATTR_NAME_ACL_ACCESS);
955 if (rc == -ENODATA) {
956 repbody->aclsize = 0;
957 repbody->valid |= OBD_MD_FLACL;
959 } else if (rc == -EOPNOTSUPP) {
962 CERROR("%s: unable to read "DFID
964 mdt_obd_name(info->mti_mdt),
965 PFID(mdt_object_fid(o)), rc);
968 repbody->aclsize = rc;
969 repbody->valid |= OBD_MD_FLACL;
976 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
977 info->mti_mdt->mdt_lut.lut_mds_capa &&
978 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
979 struct lustre_capa *capa;
981 capa = req_capsule_server_get(pill, &RMF_CAPA1);
983 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
984 rc = mo_capa_get(env, next, capa, 0);
987 repbody->valid |= OBD_MD_FLMDSCAPA;
992 mdt_counter_incr(req, LPROC_MDT_GETATTR);
997 static int mdt_renew_capa(struct mdt_thread_info *info)
999 struct mdt_object *obj = info->mti_object;
1000 struct mdt_body *body;
1001 struct lustre_capa *capa, *c;
1005 /* if object doesn't exist, or server has disabled capability,
1006 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
1009 if (!obj || !info->mti_mdt->mdt_lut.lut_oss_capa ||
1010 !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA))
1013 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1014 LASSERT(body != NULL);
1016 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
1019 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
1023 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
1025 body->valid |= OBD_MD_FLOSSCAPA;
1029 int mdt_getattr(struct tgt_session_info *tsi)
1031 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1032 struct mdt_object *obj = info->mti_object;
1033 struct req_capsule *pill = info->mti_pill;
1034 struct mdt_body *reqbody;
1035 struct mdt_body *repbody;
1040 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
1043 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
1044 rc = req_capsule_server_pack(pill);
1046 RETURN(err_serious(rc));
1047 rc = mdt_renew_capa(info);
1048 GOTO(out_shrink, rc);
1051 LASSERT(obj != NULL);
1052 LASSERT(lu_object_assert_exists(&obj->mot_obj));
1054 mode = lu_object_attr(&obj->mot_obj);
1056 /* old clients may not report needed easize, use max value then */
1057 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1058 reqbody->eadatasize == 0 ?
1059 info->mti_mdt->mdt_max_mdsize :
1060 reqbody->eadatasize);
1062 rc = req_capsule_server_pack(pill);
1063 if (unlikely(rc != 0))
1064 GOTO(out, rc = err_serious(rc));
1066 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1067 LASSERT(repbody != NULL);
1068 repbody->eadatasize = 0;
1069 repbody->aclsize = 0;
1071 if (reqbody->valid & OBD_MD_FLRMTPERM)
1072 rc = mdt_init_ucred(info, reqbody);
1074 rc = mdt_check_ucred(info);
1076 GOTO(out_shrink, rc);
1078 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1081 * Don't check capability at all, because rename might getattr for
1082 * remote obj, and at that time no capability is available.
1084 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
1085 rc = mdt_getattr_internal(info, obj, 0);
1086 if (reqbody->valid & OBD_MD_FLRMTPERM)
1087 mdt_exit_ucred(info);
1090 mdt_client_compatibility(info);
1091 rc2 = mdt_fix_reply(info);
1095 mdt_thread_info_fini(info);
1099 int mdt_is_subdir(struct tgt_session_info *tsi)
1101 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1102 struct mdt_object *o = info->mti_object;
1103 struct req_capsule *pill = info->mti_pill;
1104 const struct mdt_body *body = info->mti_body;
1105 struct mdt_body *repbody;
1111 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1114 * We save last checked parent fid to @repbody->fid1 for remote
1117 LASSERT(fid_is_sane(&body->fid2));
1118 LASSERT(mdt_object_exists(o) && !mdt_object_remote(o));
1119 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
1120 &body->fid2, &repbody->fid1);
1121 if (rc == 0 || rc == -EREMOTE)
1122 repbody->valid |= OBD_MD_FLID;
1124 mdt_thread_info_fini(info);
1128 int mdt_swap_layouts(struct tgt_session_info *tsi)
1130 struct mdt_thread_info *info;
1131 struct ptlrpc_request *req = tgt_ses_req(tsi);
1132 struct obd_export *exp = req->rq_export;
1133 struct mdt_object *o1, *o2, *o;
1134 struct mdt_lock_handle *lh1, *lh2;
1135 struct mdc_swap_layouts *msl;
1139 /* client does not support layout lock, so layout swaping
1141 * FIXME: there is a problem for old clients which don't support
1142 * layout lock yet. If those clients have already opened the file
1143 * they won't be notified at all so that old layout may still be
1144 * used to do IO. This can be fixed after file release is landed by
1145 * doing exclusive open and taking full EX ibits lock. - Jinshan */
1146 if (!exp_connect_layout(exp))
1147 RETURN(-EOPNOTSUPP);
1149 info = tsi2mdt_info(tsi);
1151 if (info->mti_dlm_req != NULL)
1152 ldlm_request_cancel(req, info->mti_dlm_req, 0);
1154 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT))
1155 mdt_set_capainfo(info, 0, &info->mti_body->fid1,
1156 req_capsule_client_get(info->mti_pill,
1159 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA2, RCL_CLIENT))
1160 mdt_set_capainfo(info, 1, &info->mti_body->fid2,
1161 req_capsule_client_get(info->mti_pill,
1164 o1 = info->mti_object;
1165 o = o2 = mdt_object_find(info->mti_env, info->mti_mdt,
1166 &info->mti_body->fid2);
1168 GOTO(out, rc = PTR_ERR(o));
1170 if (mdt_object_remote(o) || !mdt_object_exists(o)) /* remote object */
1171 GOTO(put, rc = -ENOENT);
1173 rc = lu_fid_cmp(&info->mti_body->fid1, &info->mti_body->fid2);
1174 if (unlikely(rc == 0)) /* same file, you kidding me? no-op. */
1180 /* permission check. Make sure the calling process having permission
1181 * to write both files. */
1182 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o1), NULL,
1187 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o2), NULL,
1192 msl = req_capsule_client_get(info->mti_pill, &RMF_SWAP_LAYOUTS);
1194 GOTO(put, rc = -EPROTO);
1196 lh1 = &info->mti_lh[MDT_LH_NEW];
1197 mdt_lock_reg_init(lh1, LCK_EX);
1198 lh2 = &info->mti_lh[MDT_LH_OLD];
1199 mdt_lock_reg_init(lh2, LCK_EX);
1201 rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT |
1202 MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
1206 rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT |
1207 MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
1211 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
1212 mdt_object_child(o2), msl->msl_flags);
1215 mdt_object_unlock(info, o2, lh2, rc);
1217 mdt_object_unlock(info, o1, lh1, rc);
1219 mdt_object_put(info->mti_env, o);
1221 mdt_thread_info_fini(info);
1225 static int mdt_raw_lookup(struct mdt_thread_info *info,
1226 struct mdt_object *parent,
1227 const struct lu_name *lname,
1228 struct ldlm_reply *ldlm_rep)
1230 struct md_object *next = mdt_object_child(info->mti_object);
1231 const struct mdt_body *reqbody = info->mti_body;
1232 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1233 struct mdt_body *repbody;
1237 if (reqbody->valid != OBD_MD_FLID)
1240 LASSERT(!info->mti_cross_ref);
1242 /* Only got the fid of this obj by name */
1243 fid_zero(child_fid);
1244 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1247 /* XXX is raw_lookup possible as intent operation? */
1250 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1253 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1255 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1258 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1259 repbody->fid1 = *child_fid;
1260 repbody->valid = OBD_MD_FLID;
1266 * UPDATE lock should be taken against parent, and be release before exit;
1267 * child_bits lock should be taken against child, and be returned back:
1268 * (1)normal request should release the child lock;
1269 * (2)intent request will grant the lock to client.
1271 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
1272 struct mdt_lock_handle *lhc,
1274 struct ldlm_reply *ldlm_rep)
1276 struct ptlrpc_request *req = mdt_info_req(info);
1277 struct mdt_body *reqbody = NULL;
1278 struct mdt_object *parent = info->mti_object;
1279 struct mdt_object *child;
1280 struct md_object *next = mdt_object_child(parent);
1281 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1282 struct lu_name *lname = NULL;
1283 struct mdt_lock_handle *lhp = NULL;
1284 struct ldlm_lock *lock;
1285 struct ldlm_res_id *res_id;
1292 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
1293 LASSERT(ergo(is_resent,
1294 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
1296 LASSERT(parent != NULL);
1298 lname = &info->mti_name;
1299 mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON);
1301 if (!info->mti_cross_ref) {
1303 * XXX: Check for anonymous name is for getattr by fid
1304 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
1305 * that is the name must contain at least one character and
1306 * the terminating '\0'.
1308 if (!lu_name_is_valid(lname)) {
1309 reqbody = req_capsule_client_get(info->mti_pill,
1311 if (unlikely(reqbody == NULL))
1312 RETURN(err_serious(-EFAULT));
1314 if (unlikely(!fid_is_sane(&reqbody->fid2)))
1315 RETURN(err_serious(-EINVAL));
1317 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
1319 PFID(mdt_object_fid(parent)),
1320 PFID(&reqbody->fid2), ldlm_rep);
1322 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", "
1323 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
1324 PNAME(lname), ldlm_rep);
1328 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
1330 if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) {
1331 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1333 "Parent doesn't exist!\n");
1335 } else if (!info->mti_cross_ref) {
1336 LASSERTF(!mdt_object_remote(parent),
1337 "Parent "DFID" is on remote server\n",
1338 PFID(mdt_object_fid(parent)));
1341 if (lu_name_is_valid(lname)) {
1342 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
1350 if (info->mti_cross_ref) {
1351 /* Only getattr on the child. Parent is on another node. */
1352 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1354 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
1355 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
1358 /* Do not take lock for resent case. */
1359 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1360 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1361 lhc->mlh_reg_lh.cookie);
1362 LASSERT(fid_res_name_eq(mdt_object_fid(child),
1363 &lock->l_resource->lr_name));
1364 LDLM_LOCK_PUT(lock);
1367 mdt_lock_handle_init(lhc);
1368 mdt_lock_reg_init(lhc, LCK_PR);
1371 * Object's name is on another MDS, no lookup or layout
1372 * lock is needed here but update lock is.
1374 child_bits &= ~(MDS_INODELOCK_LOOKUP |
1375 MDS_INODELOCK_LAYOUT);
1376 child_bits |= MDS_INODELOCK_PERM | MDS_INODELOCK_UPDATE;
1378 rc = mdt_object_lock(info, child, lhc, child_bits,
1382 /* Finally, we can get attr for child. */
1383 if (!mdt_object_exists(child)) {
1384 LU_OBJECT_DEBUG(D_INFO, info->mti_env,
1386 "remote object doesn't exist.\n");
1387 mdt_object_unlock(info, child, lhc, 1);
1391 mdt_set_capainfo(info, 0, mdt_object_fid(child),
1393 rc = mdt_getattr_internal(info, child, 0);
1394 if (unlikely(rc != 0))
1395 mdt_object_unlock(info, child, lhc, 1);
1400 if (lu_name_is_valid(lname)) {
1401 /* step 1: lock parent only if parent is a directory */
1402 if (S_ISDIR(lu_object_attr(&parent->mot_obj))) {
1403 lhp = &info->mti_lh[MDT_LH_PARENT];
1404 mdt_lock_pdo_init(lhp, LCK_PR, lname);
1405 rc = mdt_object_lock(info, parent, lhp,
1406 MDS_INODELOCK_UPDATE,
1408 if (unlikely(rc != 0))
1412 /* step 2: lookup child's fid by name */
1413 fid_zero(child_fid);
1414 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1419 mdt_set_disposition(info, ldlm_rep,
1421 GOTO(out_parent, rc);
1423 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1425 *child_fid = reqbody->fid2;
1426 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1430 *step 3: find the child object by fid & lock it.
1431 * regardless if it is local or remote.
1433 *Note: LU-3240 (commit 762f2114d282a98ebfa4dbbeea9298a8088ad24e)
1434 * set parent dir fid the same as child fid in getattr by fid case
1435 * we should not lu_object_find() the object again, could lead
1436 * to hung if there is a concurrent unlink destroyed the object.
1438 if (lu_fid_eq(mdt_object_fid(parent), child_fid)) {
1439 mdt_object_get(info->mti_env, parent);
1442 child = mdt_object_find(info->mti_env, info->mti_mdt,
1446 if (unlikely(IS_ERR(child)))
1447 GOTO(out_parent, rc = PTR_ERR(child));
1449 /* Do not take lock for resent case. */
1450 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1451 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1452 lhc->mlh_reg_lh.cookie);
1454 res_id = &lock->l_resource->lr_name;
1455 if (!fid_res_name_eq(mdt_object_fid(child),
1456 &lock->l_resource->lr_name)) {
1457 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1458 &lock->l_resource->lr_name),
1459 "Lock res_id: "DLDLMRES", fid: "DFID"\n",
1460 PLDLMRES(lock->l_resource),
1461 PFID(mdt_object_fid(parent)));
1462 CWARN("Although resent, but still not get child lock"
1463 "parent:"DFID" child:"DFID"\n",
1464 PFID(mdt_object_fid(parent)),
1465 PFID(mdt_object_fid(child)));
1466 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1467 LDLM_LOCK_PUT(lock);
1470 LDLM_LOCK_PUT(lock);
1473 bool try_layout = false;
1476 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1477 mdt_lock_handle_init(lhc);
1478 mdt_lock_reg_init(lhc, LCK_PR);
1480 if (!mdt_object_exists(child)) {
1481 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1483 "Object doesn't exist!\n");
1484 GOTO(out_child, rc = -ENOENT);
1487 if (!(child_bits & MDS_INODELOCK_UPDATE) &&
1488 mdt_object_exists(child) && !mdt_object_remote(child)) {
1489 struct md_attr *ma = &info->mti_attr;
1492 ma->ma_need = MA_INODE;
1493 rc = mdt_attr_get_complex(info, child, ma);
1494 if (unlikely(rc != 0))
1495 GOTO(out_child, rc);
1497 /* If the file has not been changed for some time, we
1498 * return not only a LOOKUP lock, but also an UPDATE
1499 * lock and this might save us RPC on later STAT. For
1500 * directories, it also let negative dentry cache start
1501 * working for this dir. */
1502 if (ma->ma_valid & MA_INODE &&
1503 ma->ma_attr.la_valid & LA_CTIME &&
1504 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1505 ma->ma_attr.la_ctime < cfs_time_current_sec())
1506 child_bits |= MDS_INODELOCK_UPDATE;
1509 /* layout lock must be granted in a best-effort way
1510 * for IT operations */
1511 LASSERT(!(child_bits & MDS_INODELOCK_LAYOUT));
1512 if (!OBD_FAIL_CHECK(OBD_FAIL_MDS_NO_LL_GETATTR) &&
1513 exp_connect_layout(info->mti_exp) &&
1514 S_ISREG(lu_object_attr(&child->mot_obj)) &&
1515 !mdt_object_remote(child) && ldlm_rep != NULL) {
1516 /* try to grant layout lock for regular file. */
1522 child_bits |= MDS_INODELOCK_LAYOUT;
1523 /* try layout lock, it may fail to be granted due to
1524 * contention at LOOKUP or UPDATE */
1525 if (!mdt_object_lock_try(info, child, lhc, child_bits,
1527 child_bits &= ~MDS_INODELOCK_LAYOUT;
1528 LASSERT(child_bits != 0);
1529 rc = mdt_object_lock(info, child, lhc,
1530 child_bits, MDT_CROSS_LOCK);
1535 /* Do not enqueue the UPDATE lock from MDT(cross-MDT),
1536 * client will enqueue the lock to the remote MDT */
1537 if (mdt_object_remote(child))
1538 child_bits &= ~MDS_INODELOCK_UPDATE;
1539 rc = mdt_object_lock(info, child, lhc, child_bits,
1542 if (unlikely(rc != 0))
1543 GOTO(out_child, rc);
1546 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1547 /* Get MA_SOM attributes if update lock is given. */
1549 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1550 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1553 /* finally, we can get attr for child. */
1554 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1555 rc = mdt_getattr_internal(info, child, ma_need);
1556 if (unlikely(rc != 0)) {
1557 mdt_object_unlock(info, child, lhc, 1);
1559 /* Debugging code. */
1560 res_id = &lock->l_resource->lr_name;
1561 LDLM_DEBUG(lock, "Returning lock to client");
1562 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1563 &lock->l_resource->lr_name),
1564 "Lock res_id: "DLDLMRES", fid: "DFID"\n",
1565 PLDLMRES(lock->l_resource),
1566 PFID(mdt_object_fid(child)));
1567 if (mdt_object_exists(child) && !mdt_object_remote(child))
1568 mdt_pack_size2body(info, child);
1571 LDLM_LOCK_PUT(lock);
1575 mdt_object_put(info->mti_env, child);
1578 mdt_object_unlock(info, parent, lhp, 1);
1582 /* normal handler: should release the child lock */
1583 int mdt_getattr_name(struct tgt_session_info *tsi)
1585 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1586 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1587 struct mdt_body *reqbody;
1588 struct mdt_body *repbody;
1592 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1593 LASSERT(reqbody != NULL);
1594 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1595 LASSERT(repbody != NULL);
1597 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1598 repbody->eadatasize = 0;
1599 repbody->aclsize = 0;
1601 rc = mdt_init_ucred(info, reqbody);
1603 GOTO(out_shrink, rc);
1605 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1606 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1607 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1608 lhc->mlh_reg_lh.cookie = 0;
1610 mdt_exit_ucred(info);
1613 mdt_client_compatibility(info);
1614 rc2 = mdt_fix_reply(info);
1617 mdt_thread_info_fini(info);
1621 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1622 void *karg, void *uarg);
1624 int mdt_set_info(struct tgt_session_info *tsi)
1626 struct ptlrpc_request *req = tgt_ses_req(tsi);
1629 int keylen, vallen, rc = 0;
1633 key = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_KEY);
1635 DEBUG_REQ(D_HA, req, "no set_info key");
1636 RETURN(err_serious(-EFAULT));
1639 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_KEY,
1642 val = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_VAL);
1644 DEBUG_REQ(D_HA, req, "no set_info val");
1645 RETURN(err_serious(-EFAULT));
1648 vallen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_VAL,
1651 /* Swab any part of val you need to here */
1652 if (KEY_IS(KEY_READ_ONLY)) {
1653 spin_lock(&req->rq_export->exp_lock);
1655 *exp_connect_flags_ptr(req->rq_export) |=
1658 *exp_connect_flags_ptr(req->rq_export) &=
1659 ~OBD_CONNECT_RDONLY;
1660 spin_unlock(&req->rq_export->exp_lock);
1661 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1662 struct changelog_setinfo *cs = val;
1664 if (vallen != sizeof(*cs)) {
1665 CERROR("%s: bad changelog_clear setinfo size %d\n",
1666 tgt_name(tsi->tsi_tgt), vallen);
1669 if (ptlrpc_req_need_swab(req)) {
1670 __swab64s(&cs->cs_recno);
1671 __swab32s(&cs->cs_id);
1674 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, req->rq_export,
1682 int mdt_readpage(struct tgt_session_info *tsi)
1684 struct mdt_thread_info *info = mdt_th_info(tsi->tsi_env);
1685 struct mdt_object *object = mdt_obj(tsi->tsi_corpus);
1686 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1687 const struct mdt_body *reqbody = tsi->tsi_mdt_body;
1688 struct mdt_body *repbody;
1694 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1695 RETURN(err_serious(-ENOMEM));
1697 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_MDT_BODY);
1698 if (repbody == NULL || reqbody == NULL)
1699 RETURN(err_serious(-EFAULT));
1702 * prepare @rdpg before calling lower layers and transfer itself. Here
1703 * reqbody->size contains offset of where to start to read and
1704 * reqbody->nlink contains number bytes to read.
1706 rdpg->rp_hash = reqbody->size;
1707 if (rdpg->rp_hash != reqbody->size) {
1708 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1709 rdpg->rp_hash, reqbody->size);
1713 rdpg->rp_attrs = reqbody->mode;
1714 if (exp_connect_flags(tsi->tsi_exp) & OBD_CONNECT_64BITHASH)
1715 rdpg->rp_attrs |= LUDA_64BITHASH;
1716 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1717 exp_max_brw_size(tsi->tsi_exp));
1718 rdpg->rp_npages = (rdpg->rp_count + PAGE_CACHE_SIZE - 1) >>
1720 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1721 if (rdpg->rp_pages == NULL)
1724 for (i = 0; i < rdpg->rp_npages; ++i) {
1725 rdpg->rp_pages[i] = alloc_page(GFP_IOFS);
1726 if (rdpg->rp_pages[i] == NULL)
1727 GOTO(free_rdpg, rc = -ENOMEM);
1730 /* call lower layers to fill allocated pages with directory data */
1731 rc = mo_readpage(tsi->tsi_env, mdt_object_child(object), rdpg);
1733 GOTO(free_rdpg, rc);
1735 /* send pages to client */
1736 rc = tgt_sendpage(tsi, rdpg, rc);
1741 for (i = 0; i < rdpg->rp_npages; i++)
1742 if (rdpg->rp_pages[i] != NULL)
1743 __free_page(rdpg->rp_pages[i]);
1744 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1746 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1752 static int mdt_reint_internal(struct mdt_thread_info *info,
1753 struct mdt_lock_handle *lhc,
1756 struct req_capsule *pill = info->mti_pill;
1757 struct mdt_body *repbody;
1762 rc = mdt_reint_unpack(info, op);
1764 CERROR("Can't unpack reint, rc %d\n", rc);
1765 RETURN(err_serious(rc));
1768 /* for replay (no_create) lmm is not needed, client has it already */
1769 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1770 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1771 info->mti_rr.rr_eadatalen);
1773 /* llog cookies are always 0, the field is kept for compatibility */
1774 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1775 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, 0);
1777 rc = req_capsule_server_pack(pill);
1779 CERROR("Can't pack response, rc %d\n", rc);
1780 RETURN(err_serious(rc));
1783 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1784 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1786 repbody->eadatasize = 0;
1787 repbody->aclsize = 0;
1790 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1792 /* for replay no cookkie / lmm need, because client have this already */
1793 if (info->mti_spec.no_create)
1794 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1795 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1797 rc = mdt_init_ucred_reint(info);
1799 GOTO(out_shrink, rc);
1801 rc = mdt_fix_attr_ucred(info, op);
1803 GOTO(out_ucred, rc = err_serious(rc));
1805 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1806 DEBUG_REQ(D_INODE, mdt_info_req(info), "resent opt.");
1807 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1808 GOTO(out_ucred, rc);
1810 rc = mdt_reint_rec(info, lhc);
1813 mdt_exit_ucred(info);
1815 mdt_client_compatibility(info);
1816 rc2 = mdt_fix_reply(info);
1822 static long mdt_reint_opcode(struct ptlrpc_request *req,
1823 const struct req_format **fmt)
1825 struct mdt_device *mdt;
1826 struct mdt_rec_reint *rec;
1829 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
1831 opc = rec->rr_opcode;
1832 DEBUG_REQ(D_INODE, req, "reint opt = %ld", opc);
1833 if (opc < REINT_MAX && fmt[opc] != NULL)
1834 req_capsule_extend(&req->rq_pill, fmt[opc]);
1836 mdt = mdt_exp2dev(req->rq_export);
1837 CERROR("%s: Unsupported opcode '%ld' from client '%s':"
1838 " rc = %d\n", req->rq_export->exp_obd->obd_name,
1839 opc, mdt->mdt_ldlm_client->cli_name, -EFAULT);
1840 opc = err_serious(-EFAULT);
1843 opc = err_serious(-EFAULT);
1848 int mdt_reint(struct tgt_session_info *tsi)
1852 static const struct req_format *reint_fmts[REINT_MAX] = {
1853 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1854 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1855 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1856 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1857 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1858 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1859 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR,
1860 [REINT_RMENTRY] = &RQF_MDS_REINT_UNLINK,
1861 [REINT_MIGRATE] = &RQF_MDS_REINT_RENAME
1866 opc = mdt_reint_opcode(tgt_ses_req(tsi), reint_fmts);
1868 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1870 * No lock possible here from client to pass it to reint code
1873 rc = mdt_reint_internal(info, NULL, opc);
1874 mdt_thread_info_fini(info);
1879 tsi->tsi_reply_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1883 /* this should sync the whole device */
1884 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1886 struct dt_device *dt = mdt->mdt_bottom;
1890 rc = dt->dd_ops->dt_sync(env, dt);
1894 /* this should sync this object */
1895 static int mdt_object_sync(struct mdt_thread_info *info)
1897 struct md_object *next;
1901 if (!mdt_object_exists(info->mti_object)) {
1902 CWARN("Non existing object "DFID"!\n",
1903 PFID(mdt_object_fid(info->mti_object)));
1906 next = mdt_object_child(info->mti_object);
1907 rc = mo_object_sync(info->mti_env, next);
1912 int mdt_sync(struct tgt_session_info *tsi)
1914 struct ptlrpc_request *req = tgt_ses_req(tsi);
1915 struct req_capsule *pill = tsi->tsi_pill;
1916 struct mdt_body *body;
1921 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1922 RETURN(err_serious(-ENOMEM));
1924 if (fid_seq(&tsi->tsi_mdt_body->fid1) == 0) {
1925 rc = mdt_device_sync(tsi->tsi_env, mdt_exp2dev(tsi->tsi_exp));
1927 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1929 /* sync an object */
1930 rc = mdt_object_sync(info);
1932 const struct lu_fid *fid;
1933 struct lu_attr *la = &info->mti_attr.ma_attr;
1935 info->mti_attr.ma_need = MA_INODE;
1936 info->mti_attr.ma_valid = 0;
1937 rc = mdt_attr_get_complex(info, info->mti_object,
1940 body = req_capsule_server_get(pill,
1942 fid = mdt_object_fid(info->mti_object);
1943 mdt_pack_attr2body(info, body, la, fid);
1946 mdt_thread_info_fini(info);
1949 mdt_counter_incr(req, LPROC_MDT_SYNC);
1955 * Handle quota control requests to consult current usage/limit, but also
1956 * to configure quota enforcement
1958 int mdt_quotactl(struct tgt_session_info *tsi)
1960 struct obd_export *exp = tsi->tsi_exp;
1961 struct req_capsule *pill = tsi->tsi_pill;
1962 struct obd_quotactl *oqctl, *repoqc;
1964 struct mdt_device *mdt = mdt_exp2dev(exp);
1965 struct lu_device *qmt = mdt->mdt_qmt_dev;
1968 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1970 RETURN(err_serious(-EPROTO));
1972 rc = req_capsule_server_pack(pill);
1974 RETURN(err_serious(rc));
1976 switch (oqctl->qc_cmd) {
1978 case LUSTRE_Q_INVALIDATE:
1979 case LUSTRE_Q_FINVALIDATE:
1983 /* deprecated, not used any more */
1984 RETURN(-EOPNOTSUPP);
1985 /* master quotactl */
1991 RETURN(-EOPNOTSUPP);
1992 /* slave quotactl */
1997 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2001 /* map uid/gid for remote client */
2003 if (exp_connect_rmtclient(exp)) {
2004 struct lustre_idmap_table *idmap;
2006 idmap = exp->exp_mdt_data.med_idmap;
2008 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
2009 oqctl->qc_cmd != Q_GETINFO))
2012 if (oqctl->qc_type == USRQUOTA)
2013 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
2015 else if (oqctl->qc_type == GRPQUOTA)
2016 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
2021 if (id == CFS_IDMAP_NOTFOUND) {
2022 CDEBUG(D_QUOTA, "no mapping for id %u\n", oqctl->qc_id);
2027 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
2029 RETURN(err_serious(-EFAULT));
2031 if (oqctl->qc_id != id)
2032 swap(oqctl->qc_id, id);
2034 switch (oqctl->qc_cmd) {
2040 /* forward quotactl request to QMT */
2041 rc = qmt_hdls.qmth_quotactl(tsi->tsi_env, qmt, oqctl);
2046 /* slave quotactl */
2047 rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom,
2052 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2056 if (oqctl->qc_id != id)
2057 swap(oqctl->qc_id, id);
2063 /** clone llog ctxt from child (mdd)
2064 * This allows remote llog (replicator) access.
2065 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
2066 * context was originally set up, or we can handle them directly.
2067 * I choose the latter, but that means I need any llog
2068 * contexts set up by child to be accessable by the mdt. So we clone the
2069 * context into our context list here.
2071 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
2074 struct md_device *next = mdt->mdt_child;
2075 struct llog_ctxt *ctxt;
2078 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
2081 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
2082 if (rc || ctxt == NULL) {
2086 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2088 CERROR("Can't set mdt ctxt %d\n", rc);
2093 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2094 struct mdt_device *mdt, int idx)
2096 struct llog_ctxt *ctxt;
2098 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2101 /* Put once for the get we just did, and once for the clone */
2102 llog_ctxt_put(ctxt);
2103 llog_ctxt_put(ctxt);
2108 * sec context handlers
2110 int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
2114 rc = mdt_handle_idmap(tsi);
2116 struct ptlrpc_request *req = tgt_ses_req(tsi);
2119 opc = lustre_msg_get_opc(req->rq_reqmsg);
2120 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2121 sptlrpc_svc_ctx_invalidate(req);
2124 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2130 * quota request handlers
2132 int mdt_quota_dqacq(struct tgt_session_info *tsi)
2134 struct mdt_device *mdt = mdt_exp2dev(tsi->tsi_exp);
2135 struct lu_device *qmt = mdt->mdt_qmt_dev;
2140 RETURN(err_serious(-EOPNOTSUPP));
2142 rc = qmt_hdls.qmth_dqacq(tsi->tsi_env, qmt, tgt_ses_req(tsi));
2146 struct mdt_object *mdt_object_new(const struct lu_env *env,
2147 struct mdt_device *d,
2148 const struct lu_fid *f)
2150 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2151 struct lu_object *o;
2152 struct mdt_object *m;
2155 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2156 o = lu_object_find(env, &d->mdt_lu_dev, f, &conf);
2157 if (unlikely(IS_ERR(o)))
2158 m = (struct mdt_object *)o;
2164 struct mdt_object *mdt_object_find(const struct lu_env *env,
2165 struct mdt_device *d,
2166 const struct lu_fid *f)
2168 struct lu_object *o;
2169 struct mdt_object *m;
2172 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2173 o = lu_object_find(env, &d->mdt_lu_dev, f, NULL);
2174 if (unlikely(IS_ERR(o)))
2175 m = (struct mdt_object *)o;
2183 * Asyncronous commit for mdt device.
2185 * Pass asynchonous commit call down the MDS stack.
2187 * \param env environment
2188 * \param mdt the mdt device
2190 static void mdt_device_commit_async(const struct lu_env *env,
2191 struct mdt_device *mdt)
2193 struct dt_device *dt = mdt->mdt_bottom;
2196 rc = dt->dd_ops->dt_commit_async(env, dt);
2197 if (unlikely(rc != 0))
2198 CWARN("async commit start failed with rc = %d", rc);
2202 * Mark the lock as "synchonous".
2204 * Mark the lock to deffer transaction commit to the unlock time.
2206 * \param lock the lock to mark as "synchonous"
2208 * \see mdt_is_lock_sync
2209 * \see mdt_save_lock
2211 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2213 lock->l_ast_data = (void*)1;
2217 * Check whehter the lock "synchonous" or not.
2219 * \param lock the lock to check
2220 * \retval 1 the lock is "synchonous"
2221 * \retval 0 the lock isn't "synchronous"
2223 * \see mdt_set_lock_sync
2224 * \see mdt_save_lock
2226 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2228 return lock->l_ast_data != NULL;
2232 * Blocking AST for mdt locks.
2234 * Starts transaction commit if in case of COS lock conflict or
2235 * deffers such a commit to the mdt_save_lock.
2237 * \param lock the lock which blocks a request or cancelling lock
2238 * \param desc unused
2239 * \param data unused
2240 * \param flag indicates whether this cancelling or blocking callback
2242 * \see ldlm_blocking_ast_nocheck
2244 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2245 void *data, int flag)
2247 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2248 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2252 if (flag == LDLM_CB_CANCELING)
2254 lock_res_and_lock(lock);
2255 if (lock->l_blocking_ast != mdt_blocking_ast) {
2256 unlock_res_and_lock(lock);
2259 if (mdt_cos_is_enabled(mdt) &&
2260 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2261 lock->l_blocking_lock != NULL &&
2262 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2263 mdt_set_lock_sync(lock);
2265 rc = ldlm_blocking_ast_nocheck(lock);
2267 /* There is no lock conflict if l_blocking_lock == NULL,
2268 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2269 * when the last reference to a local lock was released */
2270 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2273 rc = lu_env_init(&env, LCT_LOCAL);
2274 if (unlikely(rc != 0))
2275 CWARN("lu_env initialization failed with rc = %d,"
2276 "cannot start asynchronous commit\n", rc);
2278 mdt_device_commit_async(&env, mdt);
2284 /* Used for cross-MDT lock */
2285 int mdt_remote_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2286 void *data, int flag)
2288 struct lustre_handle lockh;
2292 case LDLM_CB_BLOCKING:
2293 ldlm_lock2handle(lock, &lockh);
2294 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
2296 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
2300 case LDLM_CB_CANCELING:
2301 LDLM_DEBUG(lock, "Revoke remote lock\n");
2309 int mdt_remote_object_lock(struct mdt_thread_info *mti,
2310 struct mdt_object *o, const struct lu_fid *fid,
2311 struct lustre_handle *lh, ldlm_mode_t mode,
2314 struct ldlm_enqueue_info *einfo = &mti->mti_einfo;
2315 ldlm_policy_data_t *policy = &mti->mti_policy;
2316 struct ldlm_res_id *res_id = &mti->mti_res_id;
2320 LASSERT(mdt_object_remote(o));
2322 LASSERT(ibits == MDS_INODELOCK_UPDATE);
2324 fid_build_reg_res_name(fid, res_id);
2326 memset(einfo, 0, sizeof(*einfo));
2327 einfo->ei_type = LDLM_IBITS;
2328 einfo->ei_mode = mode;
2329 einfo->ei_cb_bl = mdt_remote_blocking_ast;
2330 einfo->ei_cb_cp = ldlm_completion_ast;
2331 einfo->ei_enq_slave = 0;
2332 einfo->ei_res_id = res_id;
2334 memset(policy, 0, sizeof(*policy));
2335 policy->l_inodebits.bits = ibits;
2337 rc = mo_object_lock(mti->mti_env, mdt_object_child(o), lh, einfo,
2342 static int mdt_object_local_lock(struct mdt_thread_info *info,
2343 struct mdt_object *o,
2344 struct mdt_lock_handle *lh, __u64 ibits,
2345 bool nonblock, int locality)
2347 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2348 ldlm_policy_data_t *policy = &info->mti_policy;
2349 struct ldlm_res_id *res_id = &info->mti_res_id;
2354 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2355 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2356 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2357 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2359 /* Only enqueue LOOKUP lock for remote object */
2360 if (mdt_object_remote(o))
2361 LASSERT(ibits == MDS_INODELOCK_LOOKUP);
2363 if (lh->mlh_type == MDT_PDO_LOCK) {
2364 /* check for exists after object is locked */
2365 if (mdt_object_exists(o) == 0) {
2366 /* Non-existent object shouldn't have PDO lock */
2369 /* Non-dir object shouldn't have PDO lock */
2370 if (!S_ISDIR(lu_object_attr(&o->mot_obj)))
2375 memset(policy, 0, sizeof(*policy));
2376 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2378 dlmflags = LDLM_FL_ATOMIC_CB;
2380 dlmflags |= LDLM_FL_BLOCK_NOWAIT;
2383 * Take PDO lock on whole directory and build correct @res_id for lock
2384 * on part of directory.
2386 if (lh->mlh_pdo_hash != 0) {
2387 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2388 mdt_lock_pdo_mode(info, o, lh);
2389 if (lh->mlh_pdo_mode != LCK_NL) {
2391 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2392 * is never going to be sent to client and we do not
2393 * want it slowed down due to possible cancels.
2395 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2396 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2397 policy, res_id, dlmflags,
2398 &info->mti_exp->exp_handle.h_cookie);
2404 * Finish res_id initializing by name hash marking part of
2405 * directory which is taking modification.
2407 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2410 policy->l_inodebits.bits = ibits;
2413 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2414 * going to be sent to client. If it is - mdt_intent_policy() path will
2415 * fix it up and turn FL_LOCAL flag off.
2417 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2418 res_id, LDLM_FL_LOCAL_ONLY | dlmflags,
2419 &info->mti_exp->exp_handle.h_cookie);
2421 mdt_object_unlock(info, o, lh, 1);
2422 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2423 lh->mlh_pdo_hash != 0 &&
2424 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2425 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2431 int mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o,
2432 struct mdt_lock_handle *lh, __u64 ibits,
2433 bool nonblock, int locality)
2438 if (!mdt_object_remote(o))
2439 return mdt_object_local_lock(info, o, lh, ibits, nonblock,
2442 if (locality == MDT_LOCAL_LOCK) {
2443 CERROR("%s: try to get local lock for remote object"
2444 DFID".\n", mdt_obd_name(info->mti_mdt),
2445 PFID(mdt_object_fid(o)));
2449 /* XXX do not support PERM/LAYOUT/XATTR lock for remote object yet */
2450 ibits &= ~(MDS_INODELOCK_PERM | MDS_INODELOCK_LAYOUT |
2451 MDS_INODELOCK_XATTR);
2452 if (ibits & MDS_INODELOCK_UPDATE) {
2453 /* Sigh, PDO needs to enqueue 2 locks right now, but
2454 * enqueue RPC can only request 1 lock, to avoid extra
2455 * RPC, so it will instead enqueue EX lock for remote
2456 * object anyway XXX*/
2457 if (lh->mlh_type == MDT_PDO_LOCK &&
2458 lh->mlh_pdo_hash != 0) {
2459 CDEBUG(D_INFO, "%s: "DFID" convert PDO lock to"
2460 "EX lock.\n", mdt_obd_name(info->mti_mdt),
2461 PFID(mdt_object_fid(o)));
2462 lh->mlh_pdo_hash = 0;
2463 lh->mlh_rreg_mode = LCK_EX;
2464 lh->mlh_type = MDT_REG_LOCK;
2466 rc = mdt_remote_object_lock(info, o, mdt_object_fid(o),
2469 MDS_INODELOCK_UPDATE);
2474 /* Only enqueue LOOKUP lock for remote object */
2475 if (ibits & MDS_INODELOCK_LOOKUP) {
2476 rc = mdt_object_local_lock(info, o, lh,
2477 MDS_INODELOCK_LOOKUP,
2478 nonblock, locality);
2486 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2487 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2489 return mdt_object_lock_internal(info, o, lh, ibits, false, locality);
2492 int mdt_object_lock_try(struct mdt_thread_info *info, struct mdt_object *o,
2493 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2495 struct mdt_lock_handle tmp = *lh;
2498 rc = mdt_object_lock_internal(info, o, &tmp, ibits, true, locality);
2506 * Save a lock within request object.
2508 * Keep the lock referenced until whether client ACK or transaction
2509 * commit happens or release the lock immediately depending on input
2510 * parameters. If COS is ON, a write lock is converted to COS lock
2513 * \param info thead info object
2514 * \param h lock handle
2515 * \param mode lock mode
2516 * \param decref force immediate lock releasing
2519 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2520 ldlm_mode_t mode, int decref)
2524 if (lustre_handle_is_used(h)) {
2525 if (decref || !info->mti_has_trans ||
2526 !(mode & (LCK_PW | LCK_EX))){
2527 mdt_fid_unlock(h, mode);
2529 struct mdt_device *mdt = info->mti_mdt;
2530 struct ldlm_lock *lock = ldlm_handle2lock(h);
2531 struct ptlrpc_request *req = mdt_info_req(info);
2534 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2536 /* there is no request if mdt_object_unlock() is called
2537 * from mdt_export_cleanup()->mdt_add_dirty_flag() */
2538 if (likely(req != NULL)) {
2539 CDEBUG(D_HA, "request = %p reply state = %p"
2540 " transno = "LPD64"\n", req,
2541 req->rq_reply_state, req->rq_transno);
2542 if (mdt_cos_is_enabled(mdt)) {
2544 ldlm_lock_downgrade(lock, LCK_COS);
2547 ptlrpc_save_lock(req, h, mode, no_ack);
2549 ldlm_lock_decref(h, mode);
2551 if (mdt_is_lock_sync(lock)) {
2552 CDEBUG(D_HA, "found sync-lock,"
2553 " async commit started\n");
2554 mdt_device_commit_async(info->mti_env,
2557 LDLM_LOCK_PUT(lock);
2566 * Unlock mdt object.
2568 * Immeditely release the regular lock and the PDO lock or save the
2569 * lock in reqeuest and keep them referenced until client ACK or
2570 * transaction commit.
2572 * \param info thread info object
2573 * \param o mdt object
2574 * \param lh mdt lock handle referencing regular and PDO locks
2575 * \param decref force immediate lock releasing
2577 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2578 struct mdt_lock_handle *lh, int decref)
2582 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2583 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2585 if (lustre_handle_is_used(&lh->mlh_rreg_lh))
2586 ldlm_lock_decref(&lh->mlh_rreg_lh, lh->mlh_rreg_mode);
2591 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2592 const struct lu_fid *f,
2593 struct mdt_lock_handle *lh,
2596 struct mdt_object *o;
2598 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2602 rc = mdt_object_lock(info, o, lh, ibits,
2605 mdt_object_put(info->mti_env, o);
2612 void mdt_object_unlock_put(struct mdt_thread_info * info,
2613 struct mdt_object * o,
2614 struct mdt_lock_handle *lh,
2617 mdt_object_unlock(info, o, lh, decref);
2618 mdt_object_put(info->mti_env, o);
2622 * Generic code handling requests that have struct mdt_body passed in:
2624 * - extract mdt_body from request and save it in @info, if present;
2626 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2629 * - if HABEO_CORPUS flag is set for this request type check whether object
2630 * actually exists on storage (lu_object_exists()).
2633 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2635 const struct mdt_body *body;
2636 struct mdt_object *obj;
2637 const struct lu_env *env;
2638 struct req_capsule *pill;
2642 env = info->mti_env;
2643 pill = info->mti_pill;
2645 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2649 if (!(body->valid & OBD_MD_FLID))
2652 if (!fid_is_sane(&body->fid1)) {
2653 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2658 * Do not get size or any capa fields before we check that request
2659 * contains capa actually. There are some requests which do not, for
2660 * instance MDS_IS_SUBDIR.
2662 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2663 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2664 mdt_set_capainfo(info, 0, &body->fid1,
2665 req_capsule_client_get(pill, &RMF_CAPA1));
2667 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2669 if ((flags & HABEO_CORPUS) &&
2670 !mdt_object_exists(obj)) {
2671 mdt_object_put(env, obj);
2672 /* for capability renew ENOENT will be handled in
2674 if (body->valid & OBD_MD_FLOSSCAPA)
2679 info->mti_object = obj;
2688 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2690 struct req_capsule *pill = info->mti_pill;
2694 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2695 rc = mdt_body_unpack(info, flags);
2699 if (rc == 0 && (flags & HABEO_REFERO)) {
2701 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2702 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2703 info->mti_body->eadatasize);
2704 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2705 req_capsule_set_size(pill, &RMF_LOGCOOKIES,
2708 rc = req_capsule_server_pack(pill);
2713 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2715 struct md_device *next = m->mdt_child;
2717 return next->md_ops->mdo_init_capa_ctxt(env, next,
2718 m->mdt_lut.lut_mds_capa,
2719 m->mdt_capa_timeout,
2724 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2726 lh->mlh_type = MDT_NUL_LOCK;
2727 lh->mlh_reg_lh.cookie = 0ull;
2728 lh->mlh_reg_mode = LCK_MINMODE;
2729 lh->mlh_pdo_lh.cookie = 0ull;
2730 lh->mlh_pdo_mode = LCK_MINMODE;
2731 lh->mlh_rreg_lh.cookie = 0ull;
2732 lh->mlh_rreg_mode = LCK_MINMODE;
2735 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2737 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2738 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2742 * Initialize fields of struct mdt_thread_info. Other fields are left in
2743 * uninitialized state, because it's too expensive to zero out whole
2744 * mdt_thread_info (> 1K) on each request arrival.
2746 void mdt_thread_info_init(struct ptlrpc_request *req,
2747 struct mdt_thread_info *info)
2751 info->mti_pill = &req->rq_pill;
2754 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2755 mdt_lock_handle_init(&info->mti_lh[i]);
2757 /* mdt device: it can be NULL while CONNECT */
2758 if (req->rq_export) {
2759 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2760 info->mti_exp = req->rq_export;
2762 info->mti_mdt = NULL;
2763 info->mti_env = req->rq_svc_thread->t_env;
2764 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2766 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2767 info->mti_big_buf = LU_BUF_NULL;
2768 info->mti_body = NULL;
2769 info->mti_object = NULL;
2770 info->mti_dlm_req = NULL;
2771 info->mti_has_trans = 0;
2772 info->mti_cross_ref = 0;
2773 info->mti_opdata = 0;
2774 info->mti_big_lmm_used = 0;
2776 info->mti_spec.no_create = 0;
2777 info->mti_spec.sp_rm_entry = 0;
2779 info->mti_spec.u.sp_ea.eadata = NULL;
2780 info->mti_spec.u.sp_ea.eadatalen = 0;
2783 void mdt_thread_info_fini(struct mdt_thread_info *info)
2787 if (info->mti_object != NULL) {
2788 mdt_object_put(info->mti_env, info->mti_object);
2789 info->mti_object = NULL;
2792 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2793 mdt_lock_handle_fini(&info->mti_lh[i]);
2794 info->mti_env = NULL;
2795 info->mti_pill = NULL;
2796 info->mti_exp = NULL;
2798 if (unlikely(info->mti_big_buf.lb_buf != NULL))
2799 lu_buf_free(&info->mti_big_buf);
2802 struct mdt_thread_info *tsi2mdt_info(struct tgt_session_info *tsi)
2804 struct mdt_thread_info *mti;
2805 struct lustre_capa *lc;
2807 mti = mdt_th_info(tsi->tsi_env);
2808 LASSERT(mti != NULL);
2810 mdt_thread_info_init(tgt_ses_req(tsi), mti);
2811 if (tsi->tsi_corpus != NULL) {
2812 struct req_capsule *pill = tsi->tsi_pill;
2814 mti->mti_object = mdt_obj(tsi->tsi_corpus);
2815 lu_object_get(tsi->tsi_corpus);
2818 * XXX: must be part of tgt_mdt_body_unpack but moved here
2819 * due to mdt_set_capainfo().
2821 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2822 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT) > 0) {
2823 lc = req_capsule_client_get(pill, &RMF_CAPA1);
2824 mdt_set_capainfo(mti, 0, &tsi->tsi_mdt_body->fid1, lc);
2827 mti->mti_body = tsi->tsi_mdt_body;
2828 mti->mti_dlm_req = tsi->tsi_dlm_req;
2833 int mdt_tgt_connect(struct tgt_session_info *tsi)
2835 struct ptlrpc_request *req = tgt_ses_req(tsi);
2840 rc = tgt_connect(tsi);
2844 rc = mdt_init_idmap(tsi);
2849 obd_disconnect(class_export_get(req->rq_export));
2868 static int mdt_intent_getattr(enum mdt_it_code opcode,
2869 struct mdt_thread_info *info,
2870 struct ldlm_lock **,
2873 static int mdt_intent_getxattr(enum mdt_it_code opcode,
2874 struct mdt_thread_info *info,
2875 struct ldlm_lock **lockp,
2878 static int mdt_intent_layout(enum mdt_it_code opcode,
2879 struct mdt_thread_info *info,
2880 struct ldlm_lock **,
2882 static int mdt_intent_reint(enum mdt_it_code opcode,
2883 struct mdt_thread_info *info,
2884 struct ldlm_lock **,
2887 static struct mdt_it_flavor {
2888 const struct req_format *it_fmt;
2890 int (*it_act)(enum mdt_it_code ,
2891 struct mdt_thread_info *,
2892 struct ldlm_lock **,
2895 } mdt_it_flavor[] = {
2897 .it_fmt = &RQF_LDLM_INTENT,
2898 /*.it_flags = HABEO_REFERO,*/
2900 .it_act = mdt_intent_reint,
2901 .it_reint = REINT_OPEN
2904 .it_fmt = &RQF_LDLM_INTENT,
2906 * OCREAT is not a MUTABOR request as if the file
2908 * We do the extra check of OBD_CONNECT_RDONLY in
2909 * mdt_reint_open() when we really need to create
2913 .it_act = mdt_intent_reint,
2914 .it_reint = REINT_OPEN
2917 .it_fmt = &RQF_LDLM_INTENT,
2918 .it_flags = MUTABOR,
2919 .it_act = mdt_intent_reint,
2920 .it_reint = REINT_CREATE
2922 [MDT_IT_GETATTR] = {
2923 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2924 .it_flags = HABEO_REFERO,
2925 .it_act = mdt_intent_getattr
2927 [MDT_IT_READDIR] = {
2933 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2934 .it_flags = HABEO_REFERO,
2935 .it_act = mdt_intent_getattr
2938 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2939 .it_flags = MUTABOR,
2941 .it_reint = REINT_UNLINK
2945 .it_flags = MUTABOR,
2948 [MDT_IT_GETXATTR] = {
2949 .it_fmt = &RQF_LDLM_INTENT_GETXATTR,
2950 .it_flags = HABEO_CORPUS,
2951 .it_act = mdt_intent_getxattr
2954 .it_fmt = &RQF_LDLM_INTENT_LAYOUT,
2956 .it_act = mdt_intent_layout
2960 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2961 struct ldlm_lock **lockp,
2962 struct ldlm_lock *new_lock,
2963 struct mdt_lock_handle *lh,
2966 struct ptlrpc_request *req = mdt_info_req(info);
2967 struct ldlm_lock *lock = *lockp;
2970 * Get new lock only for cases when possible resent did not find any
2973 if (new_lock == NULL)
2974 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
2976 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2977 lh->mlh_reg_lh.cookie = 0;
2981 LASSERTF(new_lock != NULL,
2982 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2985 * If we've already given this lock to a client once, then we should
2986 * have no readers or writers. Otherwise, we should have one reader
2987 * _or_ writer ref (which will be zeroed below) before returning the
2990 if (new_lock->l_export == req->rq_export) {
2991 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2993 LASSERT(new_lock->l_export == NULL);
2994 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2999 if (new_lock->l_export == req->rq_export) {
3001 * Already gave this to the client, which means that we
3002 * reconstructed a reply.
3004 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3006 lh->mlh_reg_lh.cookie = 0;
3007 RETURN(ELDLM_LOCK_REPLACED);
3011 * Fixup the lock to be given to the client.
3013 lock_res_and_lock(new_lock);
3014 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3015 * possible blocking AST. */
3016 while (new_lock->l_readers > 0) {
3017 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3018 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3019 new_lock->l_readers--;
3021 while (new_lock->l_writers > 0) {
3022 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3023 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3024 new_lock->l_writers--;
3027 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3028 new_lock->l_blocking_ast = lock->l_blocking_ast;
3029 new_lock->l_completion_ast = lock->l_completion_ast;
3030 new_lock->l_remote_handle = lock->l_remote_handle;
3031 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3033 unlock_res_and_lock(new_lock);
3035 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3036 &new_lock->l_remote_handle,
3037 &new_lock->l_exp_hash);
3039 LDLM_LOCK_RELEASE(new_lock);
3040 lh->mlh_reg_lh.cookie = 0;
3042 RETURN(ELDLM_LOCK_REPLACED);
3045 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3046 struct ldlm_lock *new_lock,
3047 struct ldlm_lock **old_lock,
3048 struct mdt_lock_handle *lh,
3049 enum mdt_it_code opcode)
3051 struct ptlrpc_request *req = mdt_info_req(info);
3052 struct obd_export *exp = req->rq_export;
3053 struct lustre_handle remote_hdl;
3054 struct ldlm_request *dlmreq;
3055 struct ldlm_lock *lock;
3057 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3060 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3061 remote_hdl = dlmreq->lock_handle[0];
3062 /* If the client does not require open lock, it does not need to
3063 * search lock in exp_lock_hash, since the server thread will
3064 * make sure the lock will be released, and the resend request
3065 * can always re-enqueue the lock */
3066 if ((opcode != MDT_IT_OPEN) || (opcode == MDT_IT_OPEN &&
3067 info->mti_spec.sp_cr_flags & MDS_OPEN_LOCK)) {
3068 /* In the function below, .hs_keycmp resolves to
3069 * ldlm_export_lock_keycmp() */
3070 /* coverity[overrun-buffer-val] */
3071 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3073 lock_res_and_lock(lock);
3074 if (lock != new_lock) {
3075 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3076 lh->mlh_reg_mode = lock->l_granted_mode;
3078 LDLM_DEBUG(lock, "Restoring lock cookie");
3079 DEBUG_REQ(D_DLMTRACE, req,
3080 "restoring lock cookie "LPX64,
3081 lh->mlh_reg_lh.cookie);
3083 *old_lock = LDLM_LOCK_GET(lock);
3084 cfs_hash_put(exp->exp_lock_hash,
3086 unlock_res_and_lock(lock);
3089 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3090 unlock_res_and_lock(lock);
3094 * If the xid matches, then we know this is a resent request, and allow
3095 * it. (It's probably an OPEN, for which we don't send a lock.
3097 if (req_xid_is_last(req))
3101 * This remote handle isn't enqueued, so we never received or processed
3102 * this request. Clear MSG_RESENT, because it can be handled like any
3103 * normal request now.
3105 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3107 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3111 static int mdt_intent_getxattr(enum mdt_it_code opcode,
3112 struct mdt_thread_info *info,
3113 struct ldlm_lock **lockp,
3116 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3117 struct ldlm_reply *ldlm_rep = NULL;
3121 * Initialize lhc->mlh_reg_lh either from a previously granted lock
3122 * (for the resend case) or a new lock. Below we will use it to
3123 * replace the original lock.
3125 mdt_intent_fixup_resent(info, *lockp, NULL, lhc, opcode);
3126 if (!lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3127 mdt_lock_reg_init(lhc, (*lockp)->l_req_mode);
3128 rc = mdt_object_lock(info, info->mti_object, lhc,
3129 MDS_INODELOCK_XATTR,
3135 grc = mdt_getxattr(info);
3137 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3139 if (mdt_info_req(info)->rq_repmsg != NULL)
3140 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3141 if (ldlm_rep == NULL)
3142 RETURN(err_serious(-EFAULT));
3144 ldlm_rep->lock_policy_res2 = grc;
3149 static int mdt_intent_getattr(enum mdt_it_code opcode,
3150 struct mdt_thread_info *info,
3151 struct ldlm_lock **lockp,
3154 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3155 struct ldlm_lock *new_lock = NULL;
3157 struct ldlm_reply *ldlm_rep;
3158 struct ptlrpc_request *req;
3159 struct mdt_body *reqbody;
3160 struct mdt_body *repbody;
3164 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3167 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3170 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3171 repbody->eadatasize = 0;
3172 repbody->aclsize = 0;
3176 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
3178 case MDT_IT_GETATTR:
3179 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
3183 CERROR("Unsupported intent (%d)\n", opcode);
3184 GOTO(out_shrink, rc = -EINVAL);
3187 rc = mdt_init_ucred(info, reqbody);
3189 GOTO(out_shrink, rc);
3191 req = info->mti_pill->rc_req;
3192 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3193 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3195 /* Get lock from request for possible resent case. */
3196 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc, opcode);
3198 rc = mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3199 ldlm_rep->lock_policy_res2 = clear_serious(rc);
3201 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3202 ldlm_rep->lock_policy_res2 = 0;
3203 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3204 ldlm_rep->lock_policy_res2) {
3205 lhc->mlh_reg_lh.cookie = 0ull;
3206 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3209 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3212 mdt_exit_ucred(info);
3214 mdt_client_compatibility(info);
3215 rc2 = mdt_fix_reply(info);
3221 static int mdt_intent_layout(enum mdt_it_code opcode,
3222 struct mdt_thread_info *info,
3223 struct ldlm_lock **lockp,
3226 struct layout_intent *layout;
3228 struct mdt_object *obj = NULL;
3229 struct md_object *child = NULL;
3233 if (opcode != MDT_IT_LAYOUT) {
3234 CERROR("%s: Unknown intent (%d)\n", mdt_obd_name(info->mti_mdt),
3239 fid = &info->mti_tmp_fid2;
3240 fid_extract_from_res_name(fid, &(*lockp)->l_resource->lr_name);
3242 obj = mdt_object_find(info->mti_env, info->mti_mdt, fid);
3244 RETURN(PTR_ERR(obj));
3246 if (mdt_object_exists(obj) && !mdt_object_remote(obj)) {
3247 child = mdt_object_child(obj);
3249 /* get the length of lsm */
3250 rc = mo_xattr_get(info->mti_env, child, &LU_BUF_NULL,
3253 if (rc > info->mti_mdt->mdt_max_mdsize)
3254 info->mti_mdt->mdt_max_mdsize = rc;
3257 mdt_object_put(info->mti_env, obj);
3259 (*lockp)->l_lvb_type = LVB_T_LAYOUT;
3260 req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER,
3261 ldlm_lvbo_size(*lockp));
3262 rc = req_capsule_server_pack(info->mti_pill);
3266 layout = req_capsule_client_get(info->mti_pill, &RMF_LAYOUT_INTENT);
3267 LASSERT(layout != NULL);
3268 if (layout->li_opc == LAYOUT_INTENT_ACCESS)
3269 /* return to normal ldlm handling */
3272 CERROR("%s: Unsupported layout intent (%d)\n",
3273 mdt_obd_name(info->mti_mdt), layout->li_opc);
3277 static int mdt_intent_reint(enum mdt_it_code opcode,
3278 struct mdt_thread_info *info,
3279 struct ldlm_lock **lockp,
3282 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3283 struct ldlm_reply *rep = NULL;
3287 static const struct req_format *intent_fmts[REINT_MAX] = {
3288 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3289 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3294 opc = mdt_reint_opcode(mdt_info_req(info), intent_fmts);
3298 if (mdt_it_flavor[opcode].it_reint != opc) {
3299 CERROR("Reint code %ld doesn't match intent: %d\n",
3301 RETURN(err_serious(-EPROTO));
3304 /* Get lock from request for possible resent case. */
3305 mdt_intent_fixup_resent(info, *lockp, NULL, lhc, opcode);
3307 rc = mdt_reint_internal(info, lhc, opc);
3309 /* Check whether the reply has been packed successfully. */
3310 if (mdt_info_req(info)->rq_repmsg != NULL)
3311 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3313 RETURN(err_serious(-EFAULT));
3315 /* MDC expects this in any case */
3317 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3319 /* the open lock or the lock for cross-ref object should be
3320 * returned to the client */
3321 if (rc == -EREMOTE || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
3322 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3323 rep->lock_policy_res2 = 0;
3324 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3328 rep->lock_policy_res2 = clear_serious(rc);
3330 if (rep->lock_policy_res2 == -ENOENT &&
3331 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3332 rep->lock_policy_res2 = 0;
3334 if (rc == -ENOTCONN || rc == -ENODEV ||
3335 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3337 * If it is the disconnect error (ENODEV & ENOCONN), the error
3338 * will be returned by rq_status, and client at ptlrpc layer
3339 * will detect this, then disconnect, reconnect the import
3340 * immediately, instead of impacting the following the rpc.
3342 lhc->mlh_reg_lh.cookie = 0ull;
3346 * For other cases, the error will be returned by intent.
3347 * and client will retrieve the result from intent.
3350 * FIXME: when open lock is finished, that should be
3353 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3354 LASSERTF(rc == 0, "Error occurred but lock handle "
3355 "is still in use, rc = %d\n", rc);
3356 rep->lock_policy_res2 = 0;
3357 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3360 lhc->mlh_reg_lh.cookie = 0ull;
3361 RETURN(ELDLM_LOCK_ABORTED);
3366 static int mdt_intent_code(long itcode)
3374 case IT_OPEN|IT_CREAT:
3381 rc = MDT_IT_READDIR;
3384 rc = MDT_IT_GETATTR;
3396 rc = MDT_IT_GETXATTR;
3401 case IT_QUOTA_DQACQ:
3406 CERROR("Unknown intent opcode: %ld\n", itcode);
3413 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3414 struct ldlm_lock **lockp, __u64 flags)
3416 struct req_capsule *pill;
3417 struct mdt_it_flavor *flv;
3422 opc = mdt_intent_code(itopc);
3426 pill = info->mti_pill;
3428 if (opc == MDT_IT_QUOTA) {
3429 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
3432 RETURN(-EOPNOTSUPP);
3434 (*lockp)->l_lvb_type = LVB_T_LQUOTA;
3435 /* pass the request to quota master */
3436 rc = qmt_hdls.qmth_intent_policy(info->mti_env, qmt,
3437 mdt_info_req(info), lockp,
3442 flv = &mdt_it_flavor[opc];
3443 if (flv->it_fmt != NULL)
3444 req_capsule_extend(pill, flv->it_fmt);
3446 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3448 struct ptlrpc_request *req = mdt_info_req(info);
3449 if (flv->it_flags & MUTABOR &&
3450 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
3453 if (rc == 0 && flv->it_act != NULL) {
3454 struct ldlm_reply *rep;
3456 /* execute policy */
3457 rc = flv->it_act(opc, info, lockp, flags);
3459 /* Check whether the reply has been packed successfully. */
3460 if (mdt_info_req(info)->rq_repmsg != NULL) {
3461 rep = req_capsule_server_get(info->mti_pill,
3463 rep->lock_policy_res2 =
3464 ptlrpc_status_hton(rep->lock_policy_res2);
3472 static int mdt_intent_policy(struct ldlm_namespace *ns,
3473 struct ldlm_lock **lockp, void *req_cookie,
3474 ldlm_mode_t mode, __u64 flags, void *data)
3476 struct tgt_session_info *tsi;
3477 struct mdt_thread_info *info;
3478 struct ptlrpc_request *req = req_cookie;
3479 struct ldlm_intent *it;
3480 struct req_capsule *pill;
3485 LASSERT(req != NULL);
3487 tsi = tgt_ses_info(req->rq_svc_thread->t_env);
3489 info = tsi2mdt_info(tsi);
3490 LASSERT(info != NULL);
3491 pill = info->mti_pill;
3492 LASSERT(pill->rc_req == req);
3494 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3495 req_capsule_extend(pill, &RQF_LDLM_INTENT_BASIC);
3496 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3498 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3502 /* Lock without inodebits makes no sense and will oops
3503 * later in ldlm. Let's check it now to see if we have
3504 * ibits corrupted somewhere in mdt_intent_opc().
3505 * The case for client miss to set ibits has been
3506 * processed by others. */
3507 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3508 lr_type == LDLM_IBITS,
3509 info->mti_dlm_req->lock_desc.\
3510 l_policy_data.l_inodebits.bits != 0));
3512 rc = err_serious(-EFAULT);
3514 /* No intent was provided */
3515 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3516 req_capsule_set_size(pill, &RMF_DLM_LVB, RCL_SERVER, 0);
3517 rc = req_capsule_server_pack(pill);
3519 rc = err_serious(rc);
3521 mdt_thread_info_fini(info);
3525 static void mdt_deregister_seq_exp(struct mdt_device *mdt)
3527 struct seq_server_site *ss = mdt_seq_site(mdt);
3529 if (ss->ss_node_id == 0)
3532 if (ss->ss_client_seq != NULL) {
3533 lustre_deregister_lwp_item(&ss->ss_client_seq->lcs_exp);
3534 ss->ss_client_seq->lcs_exp = NULL;
3537 if (ss->ss_server_fld != NULL) {
3538 lustre_deregister_lwp_item(&ss->ss_server_fld->lsf_control_exp);
3539 ss->ss_server_fld->lsf_control_exp = NULL;
3543 static void mdt_seq_fini_cli(struct mdt_device *mdt)
3545 struct seq_server_site *ss = mdt_seq_site(mdt);
3550 if (ss->ss_server_seq == NULL)
3551 seq_server_set_cli(NULL, ss->ss_server_seq, NULL);
3556 static int mdt_seq_fini(const struct lu_env *env, struct mdt_device *mdt)
3558 mdt_seq_fini_cli(mdt);
3559 mdt_deregister_seq_exp(mdt);
3561 return seq_site_fini(env, mdt_seq_site(mdt));
3565 * It will retrieve its FLDB entries from MDT0, and it only happens
3566 * when upgrading existent FS to 2.6 or when local FLDB is corrupted,
3567 * and it needs to refresh FLDB from the MDT0.
3569 static int mdt_register_lwp_callback(void *data)
3572 struct mdt_device *mdt = data;
3573 struct lu_server_fld *fld = mdt_seq_site(mdt)->ss_server_fld;
3577 LASSERT(mdt_seq_site(mdt)->ss_node_id != 0);
3579 if (!likely(fld->lsf_new))
3582 rc = lu_env_init(&env, LCT_MD_THREAD);
3584 CERROR("%s: cannot init env: rc = %d\n", mdt_obd_name(mdt), rc);
3588 rc = fld_update_from_controller(&env, fld);
3590 CERROR("%s: cannot update controller: rc = %d\n",
3591 mdt_obd_name(mdt), rc);
3599 static int mdt_register_seq_exp(struct mdt_device *mdt)
3601 struct seq_server_site *ss = mdt_seq_site(mdt);
3602 char *lwp_name = NULL;
3605 if (ss->ss_node_id == 0)
3608 OBD_ALLOC(lwp_name, MAX_OBD_NAME);
3609 if (lwp_name == NULL)
3610 GOTO(out_free, rc = -ENOMEM);
3612 rc = tgt_name2lwp_name(mdt_obd_name(mdt), lwp_name, MAX_OBD_NAME, 0);
3616 rc = lustre_register_lwp_item(lwp_name, &ss->ss_client_seq->lcs_exp,
3621 rc = lustre_register_lwp_item(lwp_name,
3622 &ss->ss_server_fld->lsf_control_exp,
3623 mdt_register_lwp_callback, mdt);
3625 lustre_deregister_lwp_item(&ss->ss_client_seq->lcs_exp);
3626 ss->ss_client_seq->lcs_exp = NULL;
3630 if (lwp_name != NULL)
3631 OBD_FREE(lwp_name, MAX_OBD_NAME);
3637 * Init client sequence manager which is used by local MDS to talk to sequence
3638 * controller on remote node.
3640 static int mdt_seq_init_cli(const struct lu_env *env, struct mdt_device *mdt)
3642 struct seq_server_site *ss = mdt_seq_site(mdt);
3647 /* check if this is adding the first MDC and controller is not yet
3649 OBD_ALLOC_PTR(ss->ss_client_seq);
3650 if (ss->ss_client_seq == NULL)
3653 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3654 if (prefix == NULL) {
3655 OBD_FREE_PTR(ss->ss_client_seq);
3656 ss->ss_client_seq = NULL;
3660 /* Note: seq_client_fini will be called in seq_site_fini */
3661 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s", mdt_obd_name(mdt));
3662 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_METADATA,
3663 prefix, ss->ss_node_id == 0 ? ss->ss_control_seq :
3665 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3667 OBD_FREE_PTR(ss->ss_client_seq);
3668 ss->ss_client_seq = NULL;
3672 rc = seq_server_set_cli(env, ss->ss_server_seq, ss->ss_client_seq);
3677 static int mdt_seq_init(const struct lu_env *env, struct mdt_device *mdt)
3679 struct seq_server_site *ss;
3683 ss = mdt_seq_site(mdt);
3684 /* init sequence controller server(MDT0) */
3685 if (ss->ss_node_id == 0) {
3686 OBD_ALLOC_PTR(ss->ss_control_seq);
3687 if (ss->ss_control_seq == NULL)
3690 rc = seq_server_init(env, ss->ss_control_seq, mdt->mdt_bottom,
3691 mdt_obd_name(mdt), LUSTRE_SEQ_CONTROLLER,
3694 GOTO(out_seq_fini, rc);
3697 /* Init normal sequence server */
3698 OBD_ALLOC_PTR(ss->ss_server_seq);
3699 if (ss->ss_server_seq == NULL)
3700 GOTO(out_seq_fini, rc = -ENOMEM);
3702 rc = seq_server_init(env, ss->ss_server_seq, mdt->mdt_bottom,
3703 mdt_obd_name(mdt), LUSTRE_SEQ_SERVER, ss);
3705 GOTO(out_seq_fini, rc);
3707 /* init seq client for seq server to talk to seq controller(MDT0) */
3708 rc = mdt_seq_init_cli(env, mdt);
3710 GOTO(out_seq_fini, rc);
3712 if (ss->ss_node_id != 0)
3713 /* register controler export through lwp */
3714 rc = mdt_register_seq_exp(mdt);
3719 mdt_seq_fini(env, mdt);
3727 static int mdt_fld_fini(const struct lu_env *env,
3728 struct mdt_device *m)
3730 struct seq_server_site *ss = mdt_seq_site(m);
3733 if (ss && ss->ss_server_fld) {
3734 fld_server_fini(env, ss->ss_server_fld);
3735 OBD_FREE_PTR(ss->ss_server_fld);
3736 ss->ss_server_fld = NULL;
3742 static int mdt_fld_init(const struct lu_env *env,
3744 struct mdt_device *m)
3746 struct seq_server_site *ss;
3750 ss = mdt_seq_site(m);
3752 OBD_ALLOC_PTR(ss->ss_server_fld);
3753 if (ss->ss_server_fld == NULL)
3754 RETURN(rc = -ENOMEM);
3756 rc = fld_server_init(env, ss->ss_server_fld, m->mdt_bottom, uuid,
3759 OBD_FREE_PTR(ss->ss_server_fld);
3760 ss->ss_server_fld = NULL;
3767 static void mdt_stack_pre_fini(const struct lu_env *env,
3768 struct mdt_device *m, struct lu_device *top)
3770 struct obd_device *obd;
3771 struct lustre_cfg_bufs *bufs;
3772 struct lustre_cfg *lcfg;
3773 struct mdt_thread_info *info;
3778 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3779 LASSERT(info != NULL);
3781 bufs = &info->mti_u.bufs;
3783 LASSERT(m->mdt_child_exp);
3784 LASSERT(m->mdt_child_exp->exp_obd);
3785 obd = m->mdt_child_exp->exp_obd;
3787 /* process cleanup, pass mdt obd name to get obd umount flags */
3788 /* XXX: this is needed because all layers are referenced by
3789 * objects (some of them are pinned by osd, for example *
3790 * the proper solution should be a model where object used
3791 * by osd only doesn't have mdt/mdd slices -bzzz */
3792 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
3793 lustre_cfg_bufs_set_string(bufs, 1, NULL);
3794 lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
3796 CERROR("%s:Cannot alloc lcfg!\n", mdt_obd_name(m));
3799 top->ld_ops->ldo_process_config(env, top, lcfg);
3800 lustre_cfg_free(lcfg);
3804 static void mdt_stack_fini(const struct lu_env *env,
3805 struct mdt_device *m, struct lu_device *top)
3807 struct obd_device *obd = mdt2obd_dev(m);
3808 struct lustre_cfg_bufs *bufs;
3809 struct lustre_cfg *lcfg;
3810 struct mdt_thread_info *info;
3814 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3815 LASSERT(info != NULL);
3817 lu_dev_del_linkage(top->ld_site, top);
3819 lu_site_purge(env, top->ld_site, -1);
3821 bufs = &info->mti_u.bufs;
3822 /* process cleanup, pass mdt obd name to get obd umount flags */
3823 /* another purpose is to let all layers to release their objects */
3824 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
3829 lustre_cfg_bufs_set_string(bufs, 1, flags);
3830 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3832 CERROR("Cannot alloc lcfg!\n");
3836 top->ld_ops->ldo_process_config(env, top, lcfg);
3837 lustre_cfg_free(lcfg);
3839 lu_site_purge(env, top->ld_site, -1);
3841 m->mdt_child = NULL;
3842 m->mdt_bottom = NULL;
3844 obd_disconnect(m->mdt_child_exp);
3845 m->mdt_child_exp = NULL;
3847 obd_disconnect(m->mdt_bottom_exp);
3848 m->mdt_child_exp = NULL;
3851 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
3852 const char *next, struct obd_export **exp)
3854 struct obd_connect_data *data = NULL;
3855 struct obd_device *obd;
3859 OBD_ALLOC_PTR(data);
3861 GOTO(out, rc = -ENOMEM);
3863 obd = class_name2obd(next);
3865 CERROR("%s: can't locate next device: %s\n",
3866 mdt_obd_name(m), next);
3867 GOTO(out, rc = -ENOTCONN);
3870 data->ocd_connect_flags = OBD_CONNECT_VERSION;
3871 data->ocd_version = LUSTRE_VERSION_CODE;
3873 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
3875 CERROR("%s: cannot connect to next dev %s (%d)\n",
3876 mdt_obd_name(m), next, rc);
3886 static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
3887 struct lustre_cfg *cfg)
3889 char *dev = lustre_cfg_string(cfg, 0);
3890 int rc, name_size, uuid_size;
3891 char *name, *uuid, *p;
3892 struct lustre_cfg_bufs *bufs;
3893 struct lustre_cfg *lcfg;
3894 struct obd_device *obd;
3895 struct lustre_profile *lprof;
3896 struct lu_site *site;
3899 /* in 1.8 we had the only device in the stack - MDS.
3900 * 2.0 introduces MDT, MDD, OSD; MDT starts others internally.
3901 * in 2.3 OSD is instantiated by obd_mount.c, so we need
3902 * to generate names and setup MDT, MDD. MDT will be using
3903 * generated name to connect to MDD. for MDD the next device
3904 * will be LOD with name taken from so called "profile" which
3905 * is generated by mount_option line
3907 * 1.8 MGS generates config. commands like this:
3908 * #06 (104)mount_option 0: 1:lustre-MDT0000 2:lustre-mdtlov
3909 * #08 (120)setup 0:lustre-MDT0000 1:dev 2:type 3:lustre-MDT0000
3910 * 2.0 MGS generates config. commands like this:
3911 * #07 (112)mount_option 0: 1:lustre-MDT0000 2:lustre-MDT0000-mdtlov
3912 * #08 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
3913 * 3:lustre-MDT0000-mdtlov 4:f
3915 * we generate MDD name from MDT one, just replacing T with D
3917 * after all the preparations, the logical equivalent will be
3918 * #01 (160)setup 0:lustre-MDD0000 1:lustre-MDD0000_UUID 2:0
3919 * 3:lustre-MDT0000-mdtlov 4:f
3920 * #02 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
3921 * 3:lustre-MDD0000 4:f
3923 * notice we build the stack from down to top: MDD first, then MDT */
3925 name_size = MAX_OBD_NAME;
3926 uuid_size = MAX_OBD_NAME;
3928 OBD_ALLOC(name, name_size);
3929 OBD_ALLOC(uuid, uuid_size);
3930 if (name == NULL || uuid == NULL)
3931 GOTO(cleanup_mem, rc = -ENOMEM);
3933 OBD_ALLOC_PTR(bufs);
3935 GOTO(cleanup_mem, rc = -ENOMEM);
3938 p = strstr(name, "-MDT");
3940 GOTO(free_bufs, rc = -ENOMEM);
3943 snprintf(uuid, MAX_OBD_NAME, "%s_UUID", name);
3945 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
3946 if (lprof == NULL || lprof->lp_dt == NULL) {
3947 CERROR("can't find the profile: %s\n",
3948 lustre_cfg_string(cfg, 0));
3949 GOTO(free_bufs, rc = -EINVAL);
3952 lustre_cfg_bufs_reset(bufs, name);
3953 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_MDD_NAME);
3954 lustre_cfg_bufs_set_string(bufs, 2, uuid);
3955 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
3957 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
3959 GOTO(free_bufs, rc = -ENOMEM);
3961 rc = class_attach(lcfg);
3963 GOTO(lcfg_cleanup, rc);
3965 obd = class_name2obd(name);
3967 CERROR("Can not find obd %s (%s in config)\n",
3968 MDD_OBD_NAME, lustre_cfg_string(cfg, 0));
3969 GOTO(class_detach, rc = -EINVAL);
3972 lustre_cfg_free(lcfg);
3974 lustre_cfg_bufs_reset(bufs, name);
3975 lustre_cfg_bufs_set_string(bufs, 1, uuid);
3976 lustre_cfg_bufs_set_string(bufs, 2, dev);
3977 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
3979 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
3981 rc = class_setup(obd, lcfg);
3983 GOTO(class_detach, rc);
3985 /* connect to MDD we just setup */
3986 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_child_exp);
3988 GOTO(class_detach, rc);
3990 site = mdt->mdt_child_exp->exp_obd->obd_lu_dev->ld_site;
3992 LASSERT(mdt_lu_site(mdt) == NULL);
3993 mdt->mdt_lu_dev.ld_site = site;
3994 site->ls_top_dev = &mdt->mdt_lu_dev;
3995 mdt->mdt_child = lu2md_dev(mdt->mdt_child_exp->exp_obd->obd_lu_dev);
3997 /* now connect to bottom OSD */
3998 snprintf(name, MAX_OBD_NAME, "%s-osd", dev);
3999 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_bottom_exp);
4001 GOTO(class_detach, rc);
4003 lu2dt_dev(mdt->mdt_bottom_exp->exp_obd->obd_lu_dev);
4005 rc = lu_env_refill((struct lu_env *)env);
4007 CERROR("Failure to refill session: '%d'\n", rc);
4009 lu_dev_add_linkage(site, &mdt->mdt_lu_dev);
4014 class_detach(obd, lcfg);
4016 lustre_cfg_free(lcfg);
4021 OBD_FREE(name, name_size);
4023 OBD_FREE(uuid, uuid_size);
4027 /* setup quota master target on MDT0 */
4028 static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
4029 struct lustre_cfg *cfg)
4031 struct obd_device *obd;
4032 char *dev = lustre_cfg_string(cfg, 0);
4033 char *qmtname, *uuid, *p;
4034 struct lustre_cfg_bufs *bufs;
4035 struct lustre_cfg *lcfg;
4036 struct lustre_profile *lprof;
4037 struct obd_connect_data *data;
4041 LASSERT(mdt->mdt_qmt_exp == NULL);
4042 LASSERT(mdt->mdt_qmt_dev == NULL);
4044 /* quota master is on MDT0 only for now */
4045 if (mdt->mdt_seq_site.ss_node_id != 0)
4048 /* MGS generates config commands which look as follows:
4049 * #01 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4050 * 3:lustre-MDT0000-mdtlov 4:f
4052 * We generate the QMT name from the MDT one, just replacing MD with QM
4053 * after all the preparations, the logical equivalent will be:
4054 * #01 (160)setup 0:lustre-QMT0000 1:lustre-QMT0000_UUID 2:0
4055 * 3:lustre-MDT0000-osd 4:f */
4056 OBD_ALLOC(qmtname, MAX_OBD_NAME);
4057 OBD_ALLOC(uuid, UUID_MAX);
4058 OBD_ALLOC_PTR(bufs);
4059 OBD_ALLOC_PTR(data);
4060 if (qmtname == NULL || uuid == NULL || bufs == NULL || data == NULL)
4061 GOTO(cleanup_mem, rc = -ENOMEM);
4063 strcpy(qmtname, dev);
4064 p = strstr(qmtname, "-MDT");
4066 GOTO(cleanup_mem, rc = -ENOMEM);
4067 /* replace MD with QM */
4071 snprintf(uuid, UUID_MAX, "%s_UUID", qmtname);
4073 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4074 if (lprof == NULL || lprof->lp_dt == NULL) {
4075 CERROR("can't find profile for %s\n",
4076 lustre_cfg_string(cfg, 0));
4077 GOTO(cleanup_mem, rc = -EINVAL);
4080 lustre_cfg_bufs_reset(bufs, qmtname);
4081 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_QMT_NAME);
4082 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4083 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4085 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4087 GOTO(cleanup_mem, rc = -ENOMEM);
4089 rc = class_attach(lcfg);
4091 GOTO(lcfg_cleanup, rc);
4093 obd = class_name2obd(qmtname);
4095 CERROR("Can not find obd %s (%s in config)\n", qmtname,
4096 lustre_cfg_string(cfg, 0));
4097 GOTO(class_detach, rc = -EINVAL);
4100 lustre_cfg_free(lcfg);
4102 lustre_cfg_bufs_reset(bufs, qmtname);
4103 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4104 lustre_cfg_bufs_set_string(bufs, 2, dev);
4106 /* for quota, the next device should be the OSD device */
4107 lustre_cfg_bufs_set_string(bufs, 3,
4108 mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
4110 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4112 rc = class_setup(obd, lcfg);
4114 GOTO(class_detach, rc);
4116 mdt->mdt_qmt_dev = obd->obd_lu_dev;
4118 /* configure local quota objects */
4119 rc = mdt->mdt_qmt_dev->ld_ops->ldo_prepare(env,
4123 GOTO(class_cleanup, rc);
4125 /* connect to quota master target */
4126 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4127 data->ocd_version = LUSTRE_VERSION_CODE;
4128 rc = obd_connect(NULL, &mdt->mdt_qmt_exp, obd, &obd->obd_uuid,
4131 CERROR("cannot connect to quota master device %s (%d)\n",
4133 GOTO(class_cleanup, rc);
4139 class_manual_cleanup(obd);
4140 mdt->mdt_qmt_dev = NULL;
4144 class_detach(obd, lcfg);
4146 lustre_cfg_free(lcfg);
4151 OBD_FREE(qmtname, MAX_OBD_NAME);
4153 OBD_FREE(uuid, UUID_MAX);
4159 /* Shutdown quota master target associated with mdt */
4160 static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt)
4164 if (mdt->mdt_qmt_exp == NULL)
4166 LASSERT(mdt->mdt_qmt_dev != NULL);
4168 /* the qmt automatically shuts down when the mdt disconnects */
4169 obd_disconnect(mdt->mdt_qmt_exp);
4170 mdt->mdt_qmt_exp = NULL;
4171 mdt->mdt_qmt_dev = NULL;
4175 /* mdt_getxattr() is used from mdt_intent_getxattr(), use this wrapper
4176 * for now. This will be removed along with converting rest of MDT code
4177 * to use tgt_session_info */
4178 int mdt_tgt_getxattr(struct tgt_session_info *tsi)
4180 struct mdt_thread_info *info = tsi2mdt_info(tsi);
4183 rc = mdt_getxattr(info);
4185 mdt_thread_info_fini(info);
4189 static struct tgt_handler mdt_tgt_handlers[] = {
4190 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4191 0, MDS_CONNECT, mdt_tgt_connect,
4192 &RQF_CONNECT, LUSTRE_OBD_VERSION),
4193 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4194 0, MDS_DISCONNECT, tgt_disconnect,
4195 &RQF_MDS_DISCONNECT, LUSTRE_OBD_VERSION),
4196 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4197 HABEO_REFERO, MDS_SET_INFO, mdt_set_info,
4198 &RQF_OBD_SET_INFO, LUSTRE_MDS_VERSION),
4199 TGT_MDT_HDL(0, MDS_GET_INFO, mdt_get_info),
4200 TGT_MDT_HDL(0 | HABEO_REFERO, MDS_GETSTATUS, mdt_getstatus),
4201 TGT_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr),
4202 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME,
4204 TGT_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_tgt_getxattr),
4205 TGT_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs),
4206 TGT_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint),
4207 TGT_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
4208 TGT_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING,
4210 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_READPAGE, mdt_readpage),
4211 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_SYNC, mdt_sync),
4212 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_IS_SUBDIR, mdt_is_subdir),
4213 TGT_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl),
4214 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_PROGRESS,
4216 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_CT_REGISTER,
4217 mdt_hsm_ct_register),
4218 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_CT_UNREGISTER,
4219 mdt_hsm_ct_unregister),
4220 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_STATE_GET,
4222 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_STATE_SET,
4224 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_ACTION, mdt_hsm_action),
4225 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_REQUEST,
4227 TGT_MDT_HDL(HABEO_CLAVIS | HABEO_CORPUS | HABEO_REFERO | MUTABOR,
4232 static struct tgt_handler mdt_sec_ctx_ops[] = {
4233 TGT_SEC_HDL_VAR(0, SEC_CTX_INIT, mdt_sec_ctx_handle),
4234 TGT_SEC_HDL_VAR(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle),
4235 TGT_SEC_HDL_VAR(0, SEC_CTX_FINI, mdt_sec_ctx_handle)
4238 static struct tgt_handler mdt_quota_ops[] = {
4239 TGT_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq),
4242 static struct tgt_opc_slice mdt_common_slice[] = {
4244 .tos_opc_start = MDS_FIRST_OPC,
4245 .tos_opc_end = MDS_LAST_OPC,
4246 .tos_hs = mdt_tgt_handlers
4249 .tos_opc_start = OBD_FIRST_OPC,
4250 .tos_opc_end = OBD_LAST_OPC,
4251 .tos_hs = tgt_obd_handlers
4254 .tos_opc_start = LDLM_FIRST_OPC,
4255 .tos_opc_end = LDLM_LAST_OPC,
4256 .tos_hs = tgt_dlm_handlers
4259 .tos_opc_start = SEC_FIRST_OPC,
4260 .tos_opc_end = SEC_LAST_OPC,
4261 .tos_hs = mdt_sec_ctx_ops
4264 .tos_opc_start = OUT_UPDATE_FIRST_OPC,
4265 .tos_opc_end = OUT_UPDATE_LAST_OPC,
4266 .tos_hs = tgt_out_handlers
4269 .tos_opc_start = FLD_FIRST_OPC,
4270 .tos_opc_end = FLD_LAST_OPC,
4271 .tos_hs = fld_handlers
4274 .tos_opc_start = SEQ_FIRST_OPC,
4275 .tos_opc_end = SEQ_LAST_OPC,
4276 .tos_hs = seq_handlers
4279 .tos_opc_start = QUOTA_DQACQ,
4280 .tos_opc_end = QUOTA_LAST_OPC,
4281 .tos_hs = mdt_quota_ops
4284 .tos_opc_start = LLOG_FIRST_OPC,
4285 .tos_opc_end = LLOG_LAST_OPC,
4286 .tos_hs = tgt_llog_handlers
4289 .tos_opc_start = LFSCK_FIRST_OPC,
4290 .tos_opc_end = LFSCK_LAST_OPC,
4291 .tos_hs = tgt_lfsck_handlers
4299 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4301 struct md_device *next = m->mdt_child;
4302 struct lu_device *d = &m->mdt_lu_dev;
4303 struct obd_device *obd = mdt2obd_dev(m);
4304 struct lfsck_stop stop;
4307 target_recovery_fini(obd);
4308 ping_evictor_stop();
4309 mdt_stack_pre_fini(env, m, md2lu_dev(m->mdt_child));
4311 if (m->mdt_opts.mo_coordinator)
4312 mdt_hsm_cdt_stop(m);
4314 mdt_hsm_cdt_fini(m);
4316 mdt_llog_ctxt_unclone(env, m, LLOG_AGENT_ORIG_CTXT);
4317 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4318 obd_exports_barrier(obd);
4319 obd_zombie_barrier();
4323 tgt_fini(env, &m->mdt_lut);
4324 mdt_fs_cleanup(env, m);
4325 upcall_cache_cleanup(m->mdt_identity_cache);
4326 m->mdt_identity_cache = NULL;
4328 if (m->mdt_namespace != NULL) {
4329 ldlm_namespace_free(m->mdt_namespace, NULL,
4330 d->ld_obd->obd_force);
4331 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4334 mdt_quota_fini(env, m);
4336 cfs_free_nidlist(&m->mdt_nosquash_nids);
4337 if (m->mdt_nosquash_str) {
4338 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4339 m->mdt_nosquash_str = NULL;
4340 m->mdt_nosquash_strlen = 0;
4343 stop.ls_status = LS_PAUSED;
4345 next->md_ops->mdo_iocontrol(env, next, OBD_IOC_STOP_LFSCK, 0, &stop);
4347 mdt_seq_fini(env, m);
4348 mdt_fld_fini(env, m);
4350 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4351 cfs_timer_disarm(&m->mdt_ck_timer);
4352 mdt_ck_thread_stop(m);
4357 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4359 LASSERT(atomic_read(&d->ld_ref) == 0);
4361 server_put_mount(mdt_obd_name(m));
4366 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4368 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4369 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4371 struct mdt_thread_info *info;
4372 struct obd_device *obd;
4373 const char *dev = lustre_cfg_string(cfg, 0);
4374 const char *num = lustre_cfg_string(cfg, 2);
4375 struct lustre_mount_info *lmi = NULL;
4376 struct lustre_sb_info *lsi;
4378 struct seq_server_site *ss_site;
4379 const char *identity_upcall = "NONE";
4380 struct md_device *next;
4386 lu_device_init(&m->mdt_lu_dev, ldt);
4388 * Environment (env) might be missing mdt_thread_key values at that
4389 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4392 * Usually device allocation path doesn't use module key values, but
4393 * mdt has to do a lot of work here, so allocate key value.
4395 rc = lu_env_refill((struct lu_env *)env);
4399 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4400 LASSERT(info != NULL);
4402 obd = class_name2obd(dev);
4403 LASSERT(obd != NULL);
4405 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4407 m->mdt_som_conf = 0;
4409 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4411 /* default is coordinator off, it is started through conf_param
4413 m->mdt_opts.mo_coordinator = 0;
4415 lmi = server_get_mount(dev);
4417 CERROR("Cannot get mount info for %s!\n", dev);
4420 lsi = s2lsi(lmi->lmi_sb);
4421 /* CMD is supported only in IAM mode */
4423 node_id = simple_strtol(num, NULL, 10);
4424 obd->u.obt.obt_magic = OBT_MAGIC;
4427 spin_lock_init(&m->mdt_ioepoch_lock);
4428 m->mdt_capa_timeout = CAPA_TIMEOUT;
4429 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4430 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4431 m->mdt_squash_uid = 0;
4432 m->mdt_squash_gid = 0;
4433 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4434 m->mdt_nosquash_str = NULL;
4435 m->mdt_nosquash_strlen = 0;
4436 init_rwsem(&m->mdt_squash_sem);
4437 spin_lock_init(&m->mdt_osfs_lock);
4438 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4439 m->mdt_enable_remote_dir = 0;
4440 m->mdt_enable_remote_dir_gid = 0;
4442 m->mdt_lu_dev.ld_ops = &mdt_lu_ops;
4443 m->mdt_lu_dev.ld_obd = obd;
4444 /* Set this lu_device to obd for error handling purposes. */
4445 obd->obd_lu_dev = &m->mdt_lu_dev;
4447 /* init the stack */
4448 rc = mdt_stack_init((struct lu_env *)env, m, cfg);
4450 CERROR("%s: Can't init device stack, rc %d\n",
4451 mdt_obd_name(m), rc);
4456 ss_site = mdt_seq_site(m);
4457 s->ld_seq_site = ss_site;
4460 /* set server index */
4461 ss_site->ss_node_id = node_id;
4463 /* failover is the default
4464 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4465 * assumed whose ss_node_id == 0 XXX
4467 obd->obd_replayable = 1;
4468 /* No connection accepted until configurations will finish */
4469 obd->obd_no_conn = 1;
4471 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4472 char *str = lustre_cfg_string(cfg, 4);
4473 if (strchr(str, 'n')) {
4474 CWARN("%s: recovery disabled\n", mdt_obd_name(m));
4475 obd->obd_replayable = 0;
4479 rc = mdt_fld_init(env, mdt_obd_name(m), m);
4481 GOTO(err_fini_stack, rc);
4483 rc = mdt_seq_init(env, m);
4485 GOTO(err_fini_fld, rc);
4487 snprintf(info->mti_u.ns_name, sizeof(info->mti_u.ns_name), "%s-%s",
4488 LUSTRE_MDT_NAME, obd->obd_uuid.uuid);
4489 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4490 LDLM_NAMESPACE_SERVER,
4491 LDLM_NAMESPACE_GREEDY,
4493 if (m->mdt_namespace == NULL)
4494 GOTO(err_fini_seq, rc = -ENOMEM);
4496 m->mdt_namespace->ns_lvbp = m;
4497 m->mdt_namespace->ns_lvbo = &mdt_lvbo;
4499 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4500 /* set obd_namespace for compatibility with old code */
4501 obd->obd_namespace = m->mdt_namespace;
4503 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4505 rc = mdt_hsm_cdt_init(m);
4507 CERROR("%s: error initializing coordinator, rc %d\n",
4508 mdt_obd_name(m), rc);
4509 GOTO(err_free_ns, rc);
4512 rc = mdt_ck_thread_start(m);
4514 GOTO(err_free_hsm, rc);
4516 rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom, mdt_common_slice,
4517 OBD_FAIL_MDS_ALL_REQUEST_NET,
4518 OBD_FAIL_MDS_ALL_REPLY_NET);
4522 rc = mdt_fs_setup(env, m, obd, lsi);
4526 tgt_adapt_sptlrpc_conf(&m->mdt_lut, 1);
4528 next = m->mdt_child;
4529 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4532 GOTO(err_fs_cleanup, rc);
4534 if (mntopts & MNTOPT_USERXATTR)
4535 m->mdt_opts.mo_user_xattr = 1;
4537 m->mdt_opts.mo_user_xattr = 0;
4539 rc = next->md_ops->mdo_maxeasize_get(env, next, &m->mdt_max_ea_size);
4541 GOTO(err_fs_cleanup, rc);
4543 if (mntopts & MNTOPT_ACL)
4544 m->mdt_opts.mo_acl = 1;
4546 m->mdt_opts.mo_acl = 0;
4548 /* XXX: to support suppgid for ACL, we enable identity_upcall
4549 * by default, otherwise, maybe got unexpected -EACCESS. */
4550 if (m->mdt_opts.mo_acl)
4551 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4553 m->mdt_identity_cache = upcall_cache_init(mdt_obd_name(m),
4555 &mdt_identity_upcall_cache_ops);
4556 if (IS_ERR(m->mdt_identity_cache)) {
4557 rc = PTR_ERR(m->mdt_identity_cache);
4558 m->mdt_identity_cache = NULL;
4559 GOTO(err_fs_cleanup, rc);
4562 rc = mdt_procfs_init(m, dev);
4564 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4565 GOTO(err_recovery, rc);
4568 rc = mdt_quota_init(env, m, cfg);
4570 GOTO(err_procfs, rc);
4572 m->mdt_ldlm_client = &mdt2obd_dev(m)->obd_ldlm_client;
4573 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
4574 "mdt_ldlm_client", m->mdt_ldlm_client);
4576 ping_evictor_start();
4578 /* recovery will be started upon mdt_prepare()
4579 * when the whole stack is complete and ready
4580 * to serve the requests */
4582 mdt_init_capa_ctxt(env, m);
4584 /* Reduce the initial timeout on an MDS because it doesn't need such
4585 * a long timeout as an OST does. Adaptive timeouts will adjust this
4586 * value appropriately. */
4587 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4588 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4594 target_recovery_fini(obd);
4595 upcall_cache_cleanup(m->mdt_identity_cache);
4596 m->mdt_identity_cache = NULL;
4598 mdt_fs_cleanup(env, m);
4600 tgt_fini(env, &m->mdt_lut);
4602 cfs_timer_disarm(&m->mdt_ck_timer);
4603 mdt_ck_thread_stop(m);
4605 mdt_hsm_cdt_fini(m);
4607 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4608 obd->obd_namespace = m->mdt_namespace = NULL;
4610 mdt_seq_fini(env, m);
4612 mdt_fld_fini(env, m);
4614 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4617 server_put_mount(dev);
4621 /* For interoperability, the left element is old parameter, the right one
4622 * is the new version of the parameter, if some parameter is deprecated,
4623 * the new version should be set as NULL. */
4624 static struct cfg_interop_param mdt_interop_param[] = {
4625 { "mdt.group_upcall", NULL },
4626 { "mdt.quota_type", NULL },
4627 { "mdd.quota_type", NULL },
4628 { "mdt.rootsquash", "mdt.root_squash" },
4629 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
4633 /* used by MGS to process specific configurations */
4634 static int mdt_process_config(const struct lu_env *env,
4635 struct lu_device *d, struct lustre_cfg *cfg)
4637 struct mdt_device *m = mdt_dev(d);
4638 struct md_device *md_next = m->mdt_child;
4639 struct lu_device *next = md2lu_dev(md_next);
4643 switch (cfg->lcfg_command) {
4645 struct lprocfs_static_vars lvars;
4646 struct obd_device *obd = d->ld_obd;
4648 /* For interoperability */
4649 struct cfg_interop_param *ptr = NULL;
4650 struct lustre_cfg *old_cfg = NULL;
4653 param = lustre_cfg_string(cfg, 1);
4654 if (param == NULL) {
4655 CERROR("param is empty\n");
4660 ptr = class_find_old_param(param, mdt_interop_param);
4662 if (ptr->new_param == NULL) {
4664 CWARN("For interoperability, skip this %s."
4665 " It is obsolete.\n", ptr->old_param);
4669 CWARN("Found old param %s, changed it to %s.\n",
4670 ptr->old_param, ptr->new_param);
4673 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
4680 lprocfs_mdt_init_vars(&lvars);
4681 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4683 if (rc > 0 || rc == -ENOSYS) {
4684 /* is it an HSM var ? */
4685 rc = class_process_proc_param(PARAM_HSM,
4686 hsm_cdt_get_proc_vars(),
4688 if (rc > 0 || rc == -ENOSYS)
4689 /* we don't understand; pass it on */
4690 rc = next->ld_ops->ldo_process_config(env, next,
4694 if (old_cfg != NULL)
4695 lustre_cfg_free(cfg);
4700 /* others are passed further */
4701 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4707 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4708 const struct lu_object_header *hdr,
4709 struct lu_device *d)
4711 struct mdt_object *mo;
4715 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, GFP_NOFS);
4717 struct lu_object *o;
4718 struct lu_object_header *h;
4721 h = &mo->mot_header;
4722 lu_object_header_init(h);
4723 lu_object_init(o, h, d);
4724 lu_object_add_top(h, o);
4725 o->lo_ops = &mdt_obj_ops;
4726 mutex_init(&mo->mot_ioepoch_mutex);
4727 mutex_init(&mo->mot_lov_mutex);
4728 init_rwsem(&mo->mot_open_sem);
4734 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4735 const struct lu_object_conf *unused)
4737 struct mdt_device *d = mdt_dev(o->lo_dev);
4738 struct lu_device *under;
4739 struct lu_object *below;
4743 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4744 PFID(lu_object_fid(o)));
4746 under = &d->mdt_child->md_lu_dev;
4747 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4748 if (below != NULL) {
4749 lu_object_add(o, below);
4756 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4758 struct mdt_object *mo = mdt_obj(o);
4759 struct lu_object_header *h;
4763 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4764 PFID(lu_object_fid(o)));
4766 LASSERT(atomic_read(&mo->mot_open_count) == 0);
4767 LASSERT(atomic_read(&mo->mot_lease_count) == 0);
4770 lu_object_header_fini(h);
4771 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
4776 static int mdt_object_print(const struct lu_env *env, void *cookie,
4777 lu_printer_t p, const struct lu_object *o)
4779 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4780 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4781 "flags="LPX64", epochcount=%d, writecount=%d)",
4782 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4783 mdto->mot_ioepoch_count, mdto->mot_writecount);
4786 static int mdt_prepare(const struct lu_env *env,
4787 struct lu_device *pdev,
4788 struct lu_device *cdev)
4790 struct mdt_device *mdt = mdt_dev(cdev);
4791 struct lu_device *next = &mdt->mdt_child->md_lu_dev;
4792 struct obd_device *obd = cdev->ld_obd;
4793 struct lfsck_start_param lsp;
4800 rc = next->ld_ops->ldo_prepare(env, cdev, next);
4804 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_CHANGELOG_ORIG_CTXT);
4808 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_AGENT_ORIG_CTXT);
4812 rc = lfsck_register_namespace(env, mdt->mdt_bottom, mdt->mdt_namespace);
4813 /* The LFSCK instance is registered just now, so it must be there when
4814 * register the namespace to such instance. */
4815 LASSERTF(rc == 0, "register namespace failed: rc = %d\n", rc);
4817 lsp.lsp_start = NULL;
4818 lsp.lsp_index_valid = 0;
4819 rc = mdt->mdt_child->md_ops->mdo_iocontrol(env, mdt->mdt_child,
4820 OBD_IOC_START_LFSCK,
4823 CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
4824 mdt_obd_name(mdt), rc);
4828 if (mdt->mdt_seq_site.ss_node_id == 0) {
4829 rc = mdt->mdt_child->md_ops->mdo_root_get(env, mdt->mdt_child,
4830 &mdt->mdt_md_root_fid);
4835 LASSERT(!test_bit(MDT_FL_CFGLOG, &mdt->mdt_state));
4836 target_recovery_init(&mdt->mdt_lut, tgt_request_handle);
4837 set_bit(MDT_FL_CFGLOG, &mdt->mdt_state);
4838 LASSERT(obd->obd_no_conn);
4839 spin_lock(&obd->obd_dev_lock);
4840 obd->obd_no_conn = 0;
4841 spin_unlock(&obd->obd_dev_lock);
4843 if (obd->obd_recovering == 0)
4844 mdt_postrecov(env, mdt);
4849 const struct lu_device_operations mdt_lu_ops = {
4850 .ldo_object_alloc = mdt_object_alloc,
4851 .ldo_process_config = mdt_process_config,
4852 .ldo_prepare = mdt_prepare,
4855 static const struct lu_object_operations mdt_obj_ops = {
4856 .loo_object_init = mdt_object_init,
4857 .loo_object_free = mdt_object_free,
4858 .loo_object_print = mdt_object_print
4861 static int mdt_obd_set_info_async(const struct lu_env *env,
4862 struct obd_export *exp,
4863 __u32 keylen, void *key,
4864 __u32 vallen, void *val,
4865 struct ptlrpc_request_set *set)
4871 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4872 rc = tgt_adapt_sptlrpc_conf(class_exp2tgt(exp), 0);
4880 * Match client and server connection feature flags.
4882 * Compute the compatibility flags for a connection request based on
4883 * features mutually supported by client and server.
4885 * The obd_export::exp_connect_data.ocd_connect_flags field in \a exp
4886 * must not be updated here, otherwise a partially initialized value may
4887 * be exposed. After the connection request is successfully processed,
4888 * the top-level MDT connect request handler atomically updates the export
4889 * connect flags from the obd_connect_data::ocd_connect_flags field of the
4890 * reply. \see mdt_connect().
4892 * \param exp the obd_export associated with this client/target pair
4893 * \param mdt the target device for the connection
4894 * \param data stores data for this connect request
4897 * \retval -EPROTO \a data unexpectedly has zero obd_connect_data::ocd_brw_size
4898 * \retval -EBADE client and server feature requirements are incompatible
4900 static int mdt_connect_internal(struct obd_export *exp,
4901 struct mdt_device *mdt,
4902 struct obd_connect_data *data)
4904 LASSERT(data != NULL);
4906 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4907 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4909 /* If no known bits (which should not happen, probably,
4910 as everybody should support LOOKUP and UPDATE bits at least)
4911 revert to compat mode with plain locks. */
4912 if (!data->ocd_ibits_known &&
4913 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4914 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4916 if (!mdt->mdt_opts.mo_acl)
4917 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4919 if (!mdt->mdt_opts.mo_user_xattr)
4920 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4922 if (!mdt->mdt_som_conf)
4923 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4925 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4926 data->ocd_brw_size = min(data->ocd_brw_size,
4927 (__u32)MD_MAX_BRW_SIZE);
4928 if (data->ocd_brw_size == 0) {
4929 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4930 " ocd_version: %x ocd_grant: %d "
4931 "ocd_index: %u ocd_brw_size is "
4932 "unexpectedly zero, network data "
4933 "corruption? Refusing connection of this"
4936 exp->exp_client_uuid.uuid,
4937 exp, data->ocd_connect_flags, data->ocd_version,
4938 data->ocd_grant, data->ocd_index);
4943 /* NB: Disregard the rule against updating
4944 * exp_connect_data.ocd_connect_flags in this case, since
4945 * tgt_client_new() needs to know if this is a lightweight
4946 * connection, and it is safe to expose this flag before
4947 * connection processing completes. */
4948 if (data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) {
4949 spin_lock(&exp->exp_lock);
4950 *exp_connect_flags_ptr(exp) |= OBD_CONNECT_LIGHTWEIGHT;
4951 spin_unlock(&exp->exp_lock);
4954 data->ocd_version = LUSTRE_VERSION_CODE;
4956 if ((data->ocd_connect_flags & OBD_CONNECT_FID) == 0) {
4957 CWARN("%s: MDS requires FID support, but client not\n",
4962 if (mdt->mdt_som_conf &&
4963 !(data->ocd_connect_flags & (OBD_CONNECT_LIGHTWEIGHT |
4964 OBD_CONNECT_MDS_MDS |
4965 OBD_CONNECT_SOM))) {
4966 CWARN("%s: MDS has SOM enabled, but client does not support "
4967 "it\n", mdt_obd_name(mdt));
4971 if (OCD_HAS_FLAG(data, PINGLESS)) {
4972 if (ptlrpc_pinger_suppress_pings()) {
4973 spin_lock(&exp->exp_obd->obd_dev_lock);
4974 list_del_init(&exp->exp_obd_chain_timed);
4975 spin_unlock(&exp->exp_obd->obd_dev_lock);
4977 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
4981 data->ocd_max_easize = mdt->mdt_max_ea_size;
4986 /* mds_connect copy */
4987 static int mdt_obd_connect(const struct lu_env *env,
4988 struct obd_export **exp, struct obd_device *obd,
4989 struct obd_uuid *cluuid,
4990 struct obd_connect_data *data,
4993 struct obd_export *lexp;
4994 struct lustre_handle conn = { 0 };
4995 struct mdt_device *mdt;
4999 LASSERT(env != NULL);
5000 if (!exp || !obd || !cluuid)
5003 mdt = mdt_dev(obd->obd_lu_dev);
5006 * first, check whether the stack is ready to handle requests
5007 * XXX: probably not very appropriate method is used now
5008 * at some point we should find a better one
5010 if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) && data != NULL &&
5011 !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) {
5012 rc = obd_get_info(env, mdt->mdt_child_exp,
5013 sizeof(KEY_OSP_CONNECTED),
5014 KEY_OSP_CONNECTED, NULL, NULL, NULL);
5017 set_bit(MDT_FL_SYNCED, &mdt->mdt_state);
5020 rc = class_connect(&conn, obd, cluuid);
5024 lexp = class_conn2export(&conn);
5025 LASSERT(lexp != NULL);
5027 rc = mdt_connect_internal(lexp, mdt, data);
5029 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5032 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5033 rc = tgt_client_new(env, lexp);
5035 mdt_export_stats_init(obd, lexp, localdata);
5037 /* For phase I, sync for cross-ref operation. */
5038 lexp->exp_keep_sync = 1;
5042 class_disconnect(lexp);
5051 static int mdt_obd_reconnect(const struct lu_env *env,
5052 struct obd_export *exp, struct obd_device *obd,
5053 struct obd_uuid *cluuid,
5054 struct obd_connect_data *data,
5060 if (exp == NULL || obd == NULL || cluuid == NULL)
5063 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5065 mdt_export_stats_init(obd, exp, localdata);
5070 static int mdt_ctxt_add_dirty_flag(struct lu_env *env,
5071 struct mdt_thread_info *info,
5072 struct mdt_file_data *mfd)
5074 struct lu_context ses;
5078 rc = lu_context_init(&ses, LCT_SERVER_SESSION);
5083 lu_context_enter(&ses);
5085 mdt_ucred(info)->uc_valid = UCRED_OLD;
5086 rc = mdt_add_dirty_flag(info, mfd->mfd_object, &info->mti_attr);
5088 lu_context_exit(&ses);
5089 lu_context_fini(&ses);
5095 static int mdt_export_cleanup(struct obd_export *exp)
5097 struct mdt_export_data *med = &exp->exp_mdt_data;
5098 struct obd_device *obd = exp->exp_obd;
5099 struct mdt_device *mdt;
5100 struct mdt_thread_info *info;
5102 CFS_LIST_HEAD(closing_list);
5103 struct mdt_file_data *mfd, *n;
5107 spin_lock(&med->med_open_lock);
5108 while (!cfs_list_empty(&med->med_open_head)) {
5109 cfs_list_t *tmp = med->med_open_head.next;
5110 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5112 /* Remove mfd handle so it can't be found again.
5113 * We are consuming the mfd_list reference here. */
5114 class_handle_unhash(&mfd->mfd_handle);
5115 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5117 spin_unlock(&med->med_open_lock);
5118 mdt = mdt_dev(obd->obd_lu_dev);
5119 LASSERT(mdt != NULL);
5121 rc = lu_env_init(&env, LCT_MD_THREAD);
5125 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5126 LASSERT(info != NULL);
5127 memset(info, 0, sizeof *info);
5128 info->mti_env = &env;
5129 info->mti_mdt = mdt;
5130 info->mti_exp = exp;
5132 if (!cfs_list_empty(&closing_list)) {
5133 struct md_attr *ma = &info->mti_attr;
5135 /* Close any open files (which may also cause orphan unlinking). */
5136 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5137 cfs_list_del_init(&mfd->mfd_list);
5138 ma->ma_need = ma->ma_valid = 0;
5140 /* This file is being closed due to an eviction, it
5141 * could have been modified and now dirty regarding to
5142 * HSM archive, check this!
5143 * The logic here is to mark a file dirty if there's a
5144 * chance it was dirtied before the client was evicted,
5145 * so that we don't have to wait for a release attempt
5146 * before finding out the file was actually dirty and
5147 * fail the release. Aggressively marking it dirty here
5148 * will cause the policy engine to attempt to
5149 * re-archive it; when rearchiving, we can compare the
5150 * current version to the HSM data_version and make the
5151 * archive request into a noop if it's not actually
5154 if (mfd->mfd_mode & (FMODE_WRITE|MDS_FMODE_TRUNC))
5155 rc = mdt_ctxt_add_dirty_flag(&env, info, mfd);
5157 /* Don't unlink orphan on failover umount, LU-184 */
5158 if (exp->exp_flags & OBD_OPT_FAILOVER) {
5159 ma->ma_valid = MA_FLAGS;
5160 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5162 mdt_mfd_close(info, mfd);
5165 info->mti_mdt = NULL;
5166 /* cleanup client slot early */
5167 /* Do not erase record for recoverable client. */
5168 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5169 tgt_client_del(&env, exp);
5175 static int mdt_obd_disconnect(struct obd_export *exp)
5181 class_export_get(exp);
5183 rc = server_disconnect_export(exp);
5185 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5187 rc = mdt_export_cleanup(exp);
5188 class_export_put(exp);
5192 /* FIXME: Can we avoid using these two interfaces? */
5193 static int mdt_init_export(struct obd_export *exp)
5195 struct mdt_export_data *med = &exp->exp_mdt_data;
5199 CFS_INIT_LIST_HEAD(&med->med_open_head);
5200 spin_lock_init(&med->med_open_lock);
5201 mutex_init(&med->med_idmap_mutex);
5202 med->med_idmap = NULL;
5203 spin_lock(&exp->exp_lock);
5204 exp->exp_connecting = 1;
5205 spin_unlock(&exp->exp_lock);
5207 /* self-export doesn't need client data and ldlm initialization */
5208 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5209 &exp->exp_client_uuid)))
5212 rc = tgt_client_alloc(exp);
5216 rc = ldlm_init_export(exp);
5223 tgt_client_free(exp);
5225 CERROR("%s: Failed to initialize export: rc = %d\n",
5226 exp->exp_obd->obd_name, rc);
5230 static int mdt_destroy_export(struct obd_export *exp)
5234 if (exp_connect_rmtclient(exp))
5235 mdt_cleanup_idmap(&exp->exp_mdt_data);
5237 target_destroy_export(exp);
5238 /* destroy can be called from failed obd_setup, so
5239 * checking uuid is safer than obd_self_export */
5240 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5241 &exp->exp_client_uuid)))
5244 ldlm_destroy_export(exp);
5245 tgt_client_free(exp);
5247 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5248 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5253 /** The maximum depth that fid2path() will search.
5254 * This is limited only because we want to store the fids for
5255 * historical path lookup purposes.
5257 #define MAX_PATH_DEPTH 100
5259 /** mdt_path() lookup structure. */
5260 struct path_lookup_info {
5261 __u64 pli_recno; /**< history point */
5262 __u64 pli_currec; /**< current record */
5263 struct lu_fid pli_fid;
5264 struct lu_fid pli_fids[MAX_PATH_DEPTH]; /**< path, in fids */
5265 struct mdt_object *pli_mdt_obj;
5266 char *pli_path; /**< full path */
5268 int pli_linkno; /**< which hardlink to follow */
5269 int pli_fidcount; /**< number of \a pli_fids */
5272 int mdt_links_read(struct mdt_thread_info *info, struct mdt_object *mdt_obj,
5273 struct linkea_data *ldata)
5277 LASSERT(ldata->ld_buf->lb_buf != NULL);
5279 if (!mdt_object_exists(mdt_obj))
5282 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5283 ldata->ld_buf, XATTR_NAME_LINK);
5284 if (rc == -ERANGE) {
5285 /* Buf was too small, figure out what we need. */
5286 lu_buf_free(ldata->ld_buf);
5287 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5288 ldata->ld_buf, XATTR_NAME_LINK);
5291 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
5292 if (ldata->ld_buf->lb_buf == NULL)
5294 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5295 ldata->ld_buf, XATTR_NAME_LINK);
5300 return linkea_init(ldata);
5303 static int mdt_path_current(struct mdt_thread_info *info,
5304 struct path_lookup_info *pli)
5306 struct mdt_device *mdt = info->mti_mdt;
5307 struct mdt_object *mdt_obj;
5308 struct link_ea_header *leh;
5309 struct link_ea_entry *lee;
5310 struct lu_name *tmpname = &info->mti_name;
5311 struct lu_fid *tmpfid = &info->mti_tmp_fid1;
5312 struct lu_buf *buf = &info->mti_big_buf;
5315 struct linkea_data ldata = { 0 };
5319 /* temp buffer for path element, the buffer will be finally freed
5320 * in mdt_thread_info_fini */
5321 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
5322 if (buf->lb_buf == NULL)
5326 ptr = pli->pli_path + pli->pli_pathlen - 1;
5329 pli->pli_fidcount = 0;
5330 pli->pli_fids[0] = *(struct lu_fid *)mdt_object_fid(pli->pli_mdt_obj);
5332 /* root FID only exists on MDT0, and fid2path should also ends at MDT0,
5333 * so checking root_fid can only happen on MDT0. */
5334 while (!lu_fid_eq(&mdt->mdt_md_root_fid,
5335 &pli->pli_fids[pli->pli_fidcount])) {
5336 mdt_obj = mdt_object_find(info->mti_env, mdt,
5337 &pli->pli_fids[pli->pli_fidcount]);
5338 if (IS_ERR(mdt_obj))
5339 GOTO(out, rc = PTR_ERR(mdt_obj));
5340 if (mdt_object_remote(mdt_obj)) {
5341 mdt_object_put(info->mti_env, mdt_obj);
5342 GOTO(remote_out, rc = -EREMOTE);
5344 if (!mdt_object_exists(mdt_obj)) {
5345 mdt_object_put(info->mti_env, mdt_obj);
5346 GOTO(out, rc = -ENOENT);
5349 rc = mdt_links_read(info, mdt_obj, &ldata);
5350 mdt_object_put(info->mti_env, mdt_obj);
5355 lee = (struct link_ea_entry *)(leh + 1); /* link #0 */
5356 linkea_entry_unpack(lee, &reclen, tmpname, tmpfid);
5357 /* If set, use link #linkno for path lookup, otherwise use
5358 link #0. Only do this for the final path element. */
5359 if (pli->pli_fidcount == 0 &&
5360 pli->pli_linkno < leh->leh_reccount) {
5362 for (count = 0; count < pli->pli_linkno; count++) {
5363 lee = (struct link_ea_entry *)
5364 ((char *)lee + reclen);
5365 linkea_entry_unpack(lee, &reclen, tmpname,
5368 if (pli->pli_linkno < leh->leh_reccount - 1)
5369 /* indicate to user there are more links */
5373 /* Pack the name in the end of the buffer */
5374 ptr -= tmpname->ln_namelen;
5375 if (ptr - 1 <= pli->pli_path)
5376 GOTO(out, rc = -EOVERFLOW);
5377 strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
5380 /* Store the parent fid for historic lookup */
5381 if (++pli->pli_fidcount >= MAX_PATH_DEPTH)
5382 GOTO(out, rc = -EOVERFLOW);
5383 pli->pli_fids[pli->pli_fidcount] = *tmpfid;
5387 ptr++; /* skip leading / */
5388 memmove(pli->pli_path, ptr, pli->pli_path + pli->pli_pathlen - ptr);
5395 /* Returns the full path to this fid, as of changelog record recno. */
5396 static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
5397 char *path, int pathlen, __u64 *recno, int *linkno,
5400 struct mdt_device *mdt = info->mti_mdt;
5401 struct path_lookup_info *pli;
5409 if (lu_fid_eq(&mdt->mdt_md_root_fid, mdt_object_fid(obj))) {
5418 pli->pli_mdt_obj = obj;
5419 pli->pli_recno = *recno;
5420 pli->pli_path = path;
5421 pli->pli_pathlen = pathlen;
5422 pli->pli_linkno = *linkno;
5424 /* Retry multiple times in case file is being moved */
5425 while (tries-- && rc == -EAGAIN)
5426 rc = mdt_path_current(info, pli);
5428 /* return the last resolved fids to the client, so the client will
5429 * build the left path on another MDT for remote object */
5430 *fid = pli->pli_fids[pli->pli_fidcount];
5432 *recno = pli->pli_currec;
5433 /* Return next link index to caller */
5434 *linkno = pli->pli_linkno;
5441 static int mdt_fid2path(struct mdt_thread_info *info,
5442 struct getinfo_fid2path *fp)
5444 struct mdt_device *mdt = info->mti_mdt;
5445 struct mdt_object *obj;
5449 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5450 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5452 if (!fid_is_sane(&fp->gf_fid))
5455 if (!fid_is_namespace_visible(&fp->gf_fid)) {
5456 CWARN("%s: "DFID" is invalid, sequence should be "
5457 ">= "LPX64"\n", mdt_obd_name(mdt),
5458 PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
5462 obj = mdt_object_find(info->mti_env, mdt, &fp->gf_fid);
5463 if (obj == NULL || IS_ERR(obj)) {
5464 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5469 if (mdt_object_remote(obj))
5471 else if (!mdt_object_exists(obj))
5477 mdt_object_put(info->mti_env, obj);
5478 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5479 PFID(&fp->gf_fid), rc);
5483 rc = mdt_path(info, obj, fp->gf_path, fp->gf_pathlen, &fp->gf_recno,
5484 &fp->gf_linkno, &fp->gf_fid);
5486 CDEBUG(D_INFO, "fid "DFID", path %s recno "LPX64" linkno %u\n",
5487 PFID(&fp->gf_fid), fp->gf_path, fp->gf_recno, fp->gf_linkno);
5489 mdt_object_put(info->mti_env, obj);
5494 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5495 void *val, int vallen)
5497 struct getinfo_fid2path *fpout, *fpin;
5500 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5503 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5504 lustre_swab_fid2path(fpin);
5506 memcpy(fpout, fpin, sizeof(*fpin));
5507 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5510 rc = mdt_fid2path(info, fpout);
5514 int mdt_get_info(struct tgt_session_info *tsi)
5524 key = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_KEY);
5526 CDEBUG(D_IOCTL, "No GETINFO key");
5527 RETURN(err_serious(-EFAULT));
5529 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_GETINFO_KEY,
5532 vallen = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_VALLEN);
5533 if (vallen == NULL) {
5534 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5535 RETURN(err_serious(-EFAULT));
5538 req_capsule_set_size(tsi->tsi_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5540 rc = req_capsule_server_pack(tsi->tsi_pill);
5542 RETURN(err_serious(rc));
5544 valout = req_capsule_server_get(tsi->tsi_pill, &RMF_GETINFO_VAL);
5545 if (valout == NULL) {
5546 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5547 RETURN(err_serious(-EFAULT));
5550 if (KEY_IS(KEY_FID2PATH)) {
5551 struct mdt_thread_info *info = tsi2mdt_info(tsi);
5553 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5554 mdt_thread_info_fini(info);
5561 /* Pass the ioc down */
5562 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5563 unsigned int cmd, int len, void *data)
5565 struct lu_context ioctl_session;
5566 struct md_device *next = mdt->mdt_child;
5570 rc = lu_context_init(&ioctl_session, LCT_SERVER_SESSION);
5573 ioctl_session.lc_thread = (struct ptlrpc_thread *)current;
5574 lu_context_enter(&ioctl_session);
5575 env->le_ses = &ioctl_session;
5577 LASSERT(next->md_ops->mdo_iocontrol);
5578 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5580 lu_context_exit(&ioctl_session);
5581 lu_context_fini(&ioctl_session);
5585 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5587 struct obd_ioctl_data *data = karg;
5590 struct mdt_object *obj;
5591 struct mdt_lock_handle *lh;
5595 if (data->ioc_inlbuf1 == NULL || data->ioc_inllen1 != sizeof(*fid) ||
5596 data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
5599 fid = (struct lu_fid *)data->ioc_inlbuf1;
5601 if (!fid_is_sane(fid))
5604 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5606 lh = &mti->mti_lh[MDT_LH_PARENT];
5607 mdt_lock_reg_init(lh, LCK_CR);
5609 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5611 RETURN(PTR_ERR(obj));
5613 if (mdt_object_remote(obj)) {
5616 * before calling version get the correct MDS should be
5617 * fid, this is error to find remote object here
5619 CERROR("nonlocal object "DFID"\n", PFID(fid));
5620 } else if (!mdt_object_exists(obj)) {
5621 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5624 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5625 *(__u64 *)data->ioc_inlbuf2 = version;
5628 mdt_object_unlock_put(mti, obj, lh, 1);
5632 /* ioctls on obd dev */
5633 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5634 void *karg, void *uarg)
5637 struct obd_device *obd = exp->exp_obd;
5638 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5639 struct dt_device *dt = mdt->mdt_bottom;
5643 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5644 rc = lu_env_init(&env, LCT_MD_THREAD);
5650 rc = mdt_device_sync(&env, mdt);
5652 case OBD_IOC_SET_READONLY:
5653 rc = dt->dd_ops->dt_ro(&env, dt);
5655 case OBD_IOC_ABORT_RECOVERY:
5656 CERROR("%s: Aborting recovery for device\n", mdt_obd_name(mdt));
5657 target_stop_recovery_thread(obd);
5660 case OBD_IOC_CHANGELOG_REG:
5661 case OBD_IOC_CHANGELOG_DEREG:
5662 case OBD_IOC_CHANGELOG_CLEAR:
5663 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5665 case OBD_IOC_START_LFSCK: {
5666 struct md_device *next = mdt->mdt_child;
5667 struct obd_ioctl_data *data = karg;
5668 struct lfsck_start_param lsp;
5670 if (unlikely(data == NULL)) {
5675 lsp.lsp_start = (struct lfsck_start *)(data->ioc_inlbuf1);
5676 lsp.lsp_index_valid = 0;
5677 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, &lsp);
5680 case OBD_IOC_STOP_LFSCK: {
5681 struct md_device *next = mdt->mdt_child;
5682 struct obd_ioctl_data *data = karg;
5683 struct lfsck_stop stop;
5685 stop.ls_status = LS_STOPPED;
5686 /* Old lfsck utils may pass NULL @stop. */
5687 if (data->ioc_inlbuf1 == NULL)
5691 ((struct lfsck_stop *)(data->ioc_inlbuf1))->ls_flags;
5693 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, &stop);
5696 case OBD_IOC_GET_OBJ_VERSION: {
5697 struct mdt_thread_info *mti;
5698 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5699 memset(mti, 0, sizeof *mti);
5700 mti->mti_env = &env;
5704 rc = mdt_ioc_version_get(mti, karg);
5707 case OBD_IOC_CATLOGLIST: {
5708 struct mdt_thread_info *mti;
5710 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5711 lu_local_obj_fid(&mti->mti_tmp_fid1, LLOG_CATALOGS_OID);
5712 rc = llog_catalog_list(&env, mdt->mdt_bottom, 0, karg,
5713 &mti->mti_tmp_fid1);
5718 CERROR("%s: Not supported cmd = %d, rc = %d\n",
5719 mdt_obd_name(mdt), cmd, rc);
5726 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5728 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5732 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5736 int mdt_obd_postrecov(struct obd_device *obd)
5741 rc = lu_env_init(&env, LCT_MD_THREAD);
5744 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5749 static struct obd_ops mdt_obd_device_ops = {
5750 .o_owner = THIS_MODULE,
5751 .o_set_info_async = mdt_obd_set_info_async,
5752 .o_connect = mdt_obd_connect,
5753 .o_reconnect = mdt_obd_reconnect,
5754 .o_disconnect = mdt_obd_disconnect,
5755 .o_init_export = mdt_init_export,
5756 .o_destroy_export = mdt_destroy_export,
5757 .o_iocontrol = mdt_iocontrol,
5758 .o_postrecov = mdt_obd_postrecov,
5761 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5762 struct lu_device *d)
5764 struct mdt_device *m = mdt_dev(d);
5771 static struct lu_device *mdt_device_free(const struct lu_env *env,
5772 struct lu_device *d)
5774 struct mdt_device *m = mdt_dev(d);
5777 lu_device_fini(&m->mdt_lu_dev);
5783 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5784 struct lu_device_type *t,
5785 struct lustre_cfg *cfg)
5787 struct lu_device *l;
5788 struct mdt_device *m;
5795 rc = mdt_init0(env, m, t, cfg);
5797 mdt_device_free(env, l);
5802 l = ERR_PTR(-ENOMEM);
5806 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5807 LU_KEY_INIT(mdt, struct mdt_thread_info);
5809 static void mdt_key_fini(const struct lu_context *ctx,
5810 struct lu_context_key *key, void* data)
5812 struct mdt_thread_info *info = data;
5814 if (info->mti_big_lmm) {
5815 OBD_FREE_LARGE(info->mti_big_lmm, info->mti_big_lmmsize);
5816 info->mti_big_lmm = NULL;
5817 info->mti_big_lmmsize = 0;
5822 /* context key: mdt_thread_key */
5823 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5825 struct lu_ucred *mdt_ucred(const struct mdt_thread_info *info)
5827 return lu_ucred(info->mti_env);
5830 struct lu_ucred *mdt_ucred_check(const struct mdt_thread_info *info)
5832 return lu_ucred_check(info->mti_env);
5836 * Enable/disable COS (Commit On Sharing).
5838 * Set/Clear the COS flag in mdt options.
5840 * \param mdt mdt device
5841 * \param val 0 disables COS, other values enable COS
5843 void mdt_enable_cos(struct mdt_device *mdt, int val)
5848 mdt->mdt_opts.mo_cos = !!val;
5849 rc = lu_env_init(&env, LCT_LOCAL);
5850 if (unlikely(rc != 0)) {
5851 CWARN("lu_env initialization failed with rc = %d,"
5852 "cannot sync\n", rc);
5855 mdt_device_sync(&env, mdt);
5860 * Check COS (Commit On Sharing) status.
5862 * Return COS flag status.
5864 * \param mdt mdt device
5866 int mdt_cos_is_enabled(struct mdt_device *mdt)
5868 return mdt->mdt_opts.mo_cos != 0;
5871 static struct lu_device_type_operations mdt_device_type_ops = {
5872 .ldto_device_alloc = mdt_device_alloc,
5873 .ldto_device_free = mdt_device_free,
5874 .ldto_device_fini = mdt_device_fini
5877 static struct lu_device_type mdt_device_type = {
5878 .ldt_tags = LU_DEVICE_MD,
5879 .ldt_name = LUSTRE_MDT_NAME,
5880 .ldt_ops = &mdt_device_type_ops,
5881 .ldt_ctx_tags = LCT_MD_THREAD
5884 static int __init mdt_mod_init(void)
5886 struct lprocfs_static_vars lvars;
5889 CLASSERT(sizeof("0x0123456789ABCDEF:0x01234567:0x01234567") ==
5890 FID_NOBRACE_LEN + 1);
5891 CLASSERT(sizeof("[0x0123456789ABCDEF:0x01234567:0x01234567]") ==
5893 rc = lu_kmem_init(mdt_caches);
5897 rc = mds_mod_init();
5901 lprocfs_mdt_init_vars(&lvars);
5902 rc = class_register_type(&mdt_obd_device_ops, NULL, NULL,
5903 #ifndef HAVE_ONLY_PROCFS_SEQ
5906 LUSTRE_MDT_NAME, &mdt_device_type);
5911 lu_kmem_fini(mdt_caches);
5918 static void __exit mdt_mod_exit(void)
5920 class_unregister_type(LUSTRE_MDT_NAME);
5922 lu_kmem_fini(mdt_caches);
5925 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
5926 MODULE_DESCRIPTION("Lustre Metadata Target ("LUSTRE_MDT_NAME")");
5927 MODULE_LICENSE("GPL");
5929 cfs_module(mdt, LUSTRE_VERSION_STRING, mdt_mod_init, mdt_mod_exit);