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 #include <lustre_ioctl.h>
57 /* struct ptlrpc_request */
58 #include <lustre_net.h>
59 /* struct obd_export */
60 #include <lustre_export.h>
61 /* struct obd_device */
64 #include <dt_object.h>
65 #include <lustre_mds.h>
66 #include <lustre_log.h>
67 #include "mdt_internal.h"
68 #include <lustre_acl.h>
69 #include <lustre_param.h>
70 #include <lustre_quota.h>
71 #include <lustre_lfsck.h>
73 mdl_mode_t mdt_mdl_lock_modes[] = {
74 [LCK_MINMODE] = MDL_MINMODE,
81 [LCK_GROUP] = MDL_GROUP
84 ldlm_mode_t mdt_dlm_lock_modes[] = {
85 [MDL_MINMODE] = LCK_MINMODE,
92 [MDL_GROUP] = LCK_GROUP
95 static struct mdt_device *mdt_dev(struct lu_device *d);
96 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
98 static const struct lu_object_operations mdt_obj_ops;
100 /* Slab for MDT object allocation */
101 static struct kmem_cache *mdt_object_kmem;
103 /* For HSM restore handles */
104 struct kmem_cache *mdt_hsm_cdt_kmem;
106 /* For HSM request handles */
107 struct kmem_cache *mdt_hsm_car_kmem;
109 static struct lu_kmem_descr mdt_caches[] = {
111 .ckd_cache = &mdt_object_kmem,
112 .ckd_name = "mdt_obj",
113 .ckd_size = sizeof(struct mdt_object)
116 .ckd_cache = &mdt_hsm_cdt_kmem,
117 .ckd_name = "mdt_cdt_restore_handle",
118 .ckd_size = sizeof(struct cdt_restore_handle)
121 .ckd_cache = &mdt_hsm_car_kmem,
122 .ckd_name = "mdt_cdt_agent_req",
123 .ckd_size = sizeof(struct cdt_agent_req)
130 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
134 return (rep->lock_policy_res1 & flag);
137 void mdt_clear_disposition(struct mdt_thread_info *info,
138 struct ldlm_reply *rep, int flag)
141 info->mti_opdata &= ~flag;
142 tgt_opdata_clear(info->mti_env, flag);
145 rep->lock_policy_res1 &= ~flag;
148 void mdt_set_disposition(struct mdt_thread_info *info,
149 struct ldlm_reply *rep, int flag)
152 info->mti_opdata |= flag;
153 tgt_opdata_set(info->mti_env, flag);
156 rep->lock_policy_res1 |= flag;
159 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
161 lh->mlh_pdo_hash = 0;
162 lh->mlh_reg_mode = lm;
163 lh->mlh_rreg_mode = lm;
164 lh->mlh_type = MDT_REG_LOCK;
167 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lock_mode,
168 const struct lu_name *lname)
170 lh->mlh_reg_mode = lock_mode;
171 lh->mlh_rreg_mode = lock_mode;
172 lh->mlh_type = MDT_PDO_LOCK;
174 if (lu_name_is_valid(lname)) {
175 lh->mlh_pdo_hash = full_name_hash(lname->ln_name,
177 /* XXX Workaround for LU-2856
179 * Zero is a valid return value of full_name_hash, but
180 * several users of mlh_pdo_hash assume a non-zero
181 * hash value. We therefore map zero onto an
182 * arbitrary, but consistent value (1) to avoid
183 * problems further down the road. */
184 if (unlikely(lh->mlh_pdo_hash == 0))
185 lh->mlh_pdo_hash = 1;
187 lh->mlh_pdo_hash = 0;
191 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
192 struct mdt_lock_handle *lh)
198 * Any dir access needs couple of locks:
200 * 1) on part of dir we gonna take lookup/modify;
202 * 2) on whole dir to protect it from concurrent splitting and/or to
203 * flush client's cache for readdir().
205 * so, for a given mode and object this routine decides what lock mode
206 * to use for lock #2:
208 * 1) if caller's gonna lookup in dir then we need to protect dir from
209 * being splitted only - LCK_CR
211 * 2) if caller's gonna modify dir then we need to protect dir from
212 * being splitted and to flush cache - LCK_CW
214 * 3) if caller's gonna modify dir and that dir seems ready for
215 * splitting then we need to protect it from any type of access
216 * (lookup/modify/split) - LCK_EX --bzzz
219 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
220 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
223 * Ask underlaying level its opinion about preferable PDO lock mode
224 * having access type passed as regular lock mode:
226 * - MDL_MINMODE means that lower layer does not want to specify lock
229 * - MDL_NL means that no PDO lock should be taken. This is used in some
230 * cases. Say, for non-splittable directories no need to use PDO locks
233 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
234 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
236 if (mode != MDL_MINMODE) {
237 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
240 * Lower layer does not want to specify locking mode. We do it
241 * our selves. No special protection is needed, just flush
242 * client's cache on modification and allow concurrent
245 switch (lh->mlh_reg_mode) {
247 lh->mlh_pdo_mode = LCK_EX;
250 lh->mlh_pdo_mode = LCK_CR;
253 lh->mlh_pdo_mode = LCK_CW;
256 CERROR("Not expected lock type (0x%x)\n",
257 (int)lh->mlh_reg_mode);
262 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
266 static int mdt_getstatus(struct tgt_session_info *tsi)
268 struct mdt_thread_info *info = tsi2mdt_info(tsi);
269 struct mdt_device *mdt = info->mti_mdt;
270 struct mdt_body *repbody;
275 rc = mdt_check_ucred(info);
277 GOTO(out, rc = err_serious(rc));
279 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
280 GOTO(out, rc = err_serious(-ENOMEM));
282 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
283 repbody->mbo_fid1 = mdt->mdt_md_root_fid;
284 repbody->mbo_valid |= OBD_MD_FLID;
286 if (tsi->tsi_tgt->lut_mds_capa &&
287 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
288 struct mdt_object *root;
289 struct lustre_capa *capa;
291 root = mdt_object_find(info->mti_env, mdt, &repbody->mbo_fid1);
293 GOTO(out, rc = PTR_ERR(root));
295 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
297 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
298 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
300 mdt_object_put(info->mti_env, root);
302 repbody->mbo_valid |= OBD_MD_FLMDSCAPA;
306 mdt_thread_info_fini(info);
310 static int mdt_statfs(struct tgt_session_info *tsi)
312 struct ptlrpc_request *req = tgt_ses_req(tsi);
313 struct mdt_thread_info *info = tsi2mdt_info(tsi);
314 struct md_device *next = info->mti_mdt->mdt_child;
315 struct ptlrpc_service_part *svcpt;
316 struct obd_statfs *osfs;
321 svcpt = req->rq_rqbd->rqbd_svcpt;
323 /* This will trigger a watchdog timeout */
324 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
325 (MDT_SERVICE_WATCHDOG_FACTOR *
326 at_get(&svcpt->scp_at_estimate)) + 1);
328 rc = mdt_check_ucred(info);
330 GOTO(out, rc = err_serious(rc));
332 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
333 GOTO(out, rc = err_serious(-ENOMEM));
335 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
337 GOTO(out, rc = -EPROTO);
339 /** statfs information are cached in the mdt_device */
340 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
341 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
342 /** statfs data is too old, get up-to-date one */
343 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
346 spin_lock(&info->mti_mdt->mdt_osfs_lock);
347 info->mti_mdt->mdt_osfs = *osfs;
348 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
349 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
351 /** use cached statfs data */
352 spin_lock(&info->mti_mdt->mdt_osfs_lock);
353 *osfs = info->mti_mdt->mdt_osfs;
354 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
358 mdt_counter_incr(req, LPROC_MDT_STATFS);
360 mdt_thread_info_fini(info);
365 * Pack SOM attributes into the reply.
366 * Call under a DLM UPDATE lock.
368 static void mdt_pack_size2body(struct mdt_thread_info *info,
369 struct mdt_object *mo)
372 struct md_attr *ma = &info->mti_attr;
374 LASSERT(ma->ma_attr.la_valid & LA_MODE);
375 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
377 /* Check if Size-on-MDS is supported, if this is a regular file,
378 * if SOM is enabled on the object and if SOM cache exists and valid.
379 * Otherwise do not pack Size-on-MDS attributes to the reply. */
380 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
381 !S_ISREG(ma->ma_attr.la_mode) ||
382 !mdt_object_is_som_enabled(mo) ||
383 !(ma->ma_valid & MA_SOM))
386 b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
387 b->mbo_size = ma->ma_som->msd_size;
388 b->mbo_blocks = ma->ma_som->msd_blocks;
391 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
392 const struct lu_attr *attr, const struct lu_fid *fid)
394 struct md_attr *ma = &info->mti_attr;
396 LASSERT(ma->ma_valid & MA_INODE);
398 b->mbo_atime = attr->la_atime;
399 b->mbo_mtime = attr->la_mtime;
400 b->mbo_ctime = attr->la_ctime;
401 b->mbo_mode = attr->la_mode;
402 b->mbo_size = attr->la_size;
403 b->mbo_blocks = attr->la_blocks;
404 b->mbo_uid = attr->la_uid;
405 b->mbo_gid = attr->la_gid;
406 b->mbo_flags = attr->la_flags;
407 b->mbo_nlink = attr->la_nlink;
408 b->mbo_rdev = attr->la_rdev;
410 /* XXX should pack the reply body according to lu_valid */
411 b->mbo_valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
412 OBD_MD_FLGID | OBD_MD_FLTYPE |
413 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
414 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
416 if (!S_ISREG(attr->la_mode)) {
417 b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
418 } else if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV)) {
419 /* means no objects are allocated on osts. */
420 LASSERT(!(ma->ma_valid & MA_LOV));
421 /* just ignore blocks occupied by extend attributes on MDS */
423 /* if no object is allocated on osts, the size on mds is valid.
425 b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
426 } else if ((ma->ma_valid & MA_LOV) && ma->ma_lmm != NULL &&
427 ma->ma_lmm->lmm_pattern & LOV_PATTERN_F_RELEASED) {
428 /* A released file stores its size on MDS. */
429 /* But return 1 block for released file, unless tools like tar
430 * will consider it fully sparse. (LU-3864)
432 if (unlikely(b->mbo_size == 0))
436 b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
441 b->mbo_valid |= OBD_MD_FLID;
442 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
443 PFID(fid), b->mbo_nlink,
444 b->mbo_mode, b->mbo_size);
448 mdt_body_reverse_idmap(info, b);
450 if (fid != NULL && (b->mbo_valid & OBD_MD_FLSIZE))
451 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
452 PFID(fid), (unsigned long long)b->mbo_size);
455 static inline int mdt_body_has_lov(const struct lu_attr *la,
456 const struct mdt_body *body)
458 return (S_ISREG(la->la_mode) && (body->mbo_valid & OBD_MD_FLEASIZE)) ||
459 (S_ISDIR(la->la_mode) && (body->mbo_valid & OBD_MD_FLDIREA));
462 void mdt_client_compatibility(struct mdt_thread_info *info)
464 struct mdt_body *body;
465 struct ptlrpc_request *req = mdt_info_req(info);
466 struct obd_export *exp = req->rq_export;
467 struct md_attr *ma = &info->mti_attr;
468 struct lu_attr *la = &ma->ma_attr;
471 if (exp_connect_layout(exp))
472 /* the client can deal with 16-bit lmm_stripe_count */
475 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
477 if (!mdt_body_has_lov(la, body))
480 /* now we have a reply with a lov for a client not compatible with the
481 * layout lock so we have to clean the layout generation number */
482 if (S_ISREG(la->la_mode))
483 ma->ma_lmm->lmm_layout_gen = 0;
487 int mdt_attr_get_eabuf_size(struct mdt_thread_info *info, struct mdt_object *o)
489 const struct lu_env *env = info->mti_env;
492 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL,
501 /* Is it a directory? Let's check for the LMV as well */
502 if (S_ISDIR(lu_object_attr(&mdt_object_child(o)->mo_lu))) {
503 rc2 = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL,
507 rc2 = mo_xattr_get(env, mdt_object_child(o),
509 XATTR_NAME_DEFAULT_LMV);
511 if ((rc2 < 0 && rc2 != -ENODATA) || (rc2 > rc))
519 int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o,
522 const struct lu_env *env = info->mti_env;
526 LASSERT(info->mti_big_lmm_used == 0);
527 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL, name);
531 /* big_lmm may need to be grown */
532 if (info->mti_big_lmmsize < rc) {
533 int size = size_roundup_power2(rc);
535 if (info->mti_big_lmmsize > 0) {
536 /* free old buffer */
537 LASSERT(info->mti_big_lmm);
538 OBD_FREE_LARGE(info->mti_big_lmm,
539 info->mti_big_lmmsize);
540 info->mti_big_lmm = NULL;
541 info->mti_big_lmmsize = 0;
544 OBD_ALLOC_LARGE(info->mti_big_lmm, size);
545 if (info->mti_big_lmm == NULL)
547 info->mti_big_lmmsize = size;
549 LASSERT(info->mti_big_lmmsize >= rc);
551 info->mti_buf.lb_buf = info->mti_big_lmm;
552 info->mti_buf.lb_len = info->mti_big_lmmsize;
553 rc = mo_xattr_get(env, mdt_object_child(o), &info->mti_buf, name);
558 int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o,
559 struct md_attr *ma, const char *name)
561 struct md_object *next = mdt_object_child(o);
562 struct lu_buf *buf = &info->mti_buf;
565 if (strcmp(name, XATTR_NAME_LOV) == 0) {
566 buf->lb_buf = ma->ma_lmm;
567 buf->lb_len = ma->ma_lmm_size;
568 LASSERT(!(ma->ma_valid & MA_LOV));
569 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
570 buf->lb_buf = ma->ma_lmv;
571 buf->lb_len = ma->ma_lmv_size;
572 LASSERT(!(ma->ma_valid & MA_LMV));
573 } else if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) {
574 buf->lb_buf = ma->ma_lmv;
575 buf->lb_len = ma->ma_lmv_size;
576 LASSERT(!(ma->ma_valid & MA_LMV_DEF));
581 rc = mo_xattr_get(info->mti_env, next, buf, name);
585 if (strcmp(name, XATTR_NAME_LOV) == 0) {
586 if (info->mti_big_lmm_used)
587 ma->ma_lmm = info->mti_big_lmm;
589 /* NOT return LOV EA with hole to old client. */
590 if (unlikely(le32_to_cpu(ma->ma_lmm->lmm_pattern) &
591 LOV_PATTERN_F_HOLE) &&
592 !(exp_connect_flags(info->mti_exp) &
593 OBD_CONNECT_LFSCK)) {
596 ma->ma_lmm_size = rc;
597 ma->ma_valid |= MA_LOV;
599 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
600 if (info->mti_big_lmm_used)
601 ma->ma_lmv = info->mti_big_lmm;
603 ma->ma_lmv_size = rc;
604 ma->ma_valid |= MA_LMV;
605 } else if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) {
606 ma->ma_lmv_size = rc;
607 ma->ma_valid |= MA_LMV_DEF;
610 /* Update mdt_max_mdsize so all clients will be aware that */
611 if (info->mti_mdt->mdt_max_mdsize < rc)
612 info->mti_mdt->mdt_max_mdsize = rc;
615 } else if (rc == -ENODATA) {
618 } else if (rc == -ERANGE) {
619 /* Default LMV has fixed size, so it must be able to fit
620 * in the original buffer */
621 if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)
623 rc = mdt_big_xattr_get(info, o, name);
625 info->mti_big_lmm_used = 1;
633 static int mdt_attr_get_pfid(struct mdt_thread_info *info,
634 struct mdt_object *o, struct lu_fid *pfid)
636 struct lu_buf *buf = &info->mti_buf;
637 struct link_ea_header *leh;
638 struct link_ea_entry *lee;
642 buf->lb_buf = info->mti_big_lmm;
643 buf->lb_len = info->mti_big_lmmsize;
644 rc = mo_xattr_get(info->mti_env, mdt_object_child(o),
645 buf, XATTR_NAME_LINK);
646 /* ignore errors, MA_PFID won't be set and it is
647 * up to the caller to treat this as an error */
648 if (rc == -ERANGE || buf->lb_len == 0) {
649 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LINK);
650 buf->lb_buf = info->mti_big_lmm;
651 buf->lb_len = info->mti_big_lmmsize;
656 if (rc < sizeof(*leh)) {
657 CERROR("short LinkEA on "DFID": rc = %d\n",
658 PFID(mdt_object_fid(o)), rc);
662 leh = (struct link_ea_header *) buf->lb_buf;
663 lee = (struct link_ea_entry *)(leh + 1);
664 if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) {
665 leh->leh_magic = LINK_EA_MAGIC;
666 leh->leh_reccount = __swab32(leh->leh_reccount);
667 leh->leh_len = __swab64(leh->leh_len);
669 if (leh->leh_magic != LINK_EA_MAGIC)
671 if (leh->leh_reccount == 0)
674 memcpy(pfid, &lee->lee_parent_fid, sizeof(*pfid));
675 fid_be_to_cpu(pfid, pfid);
680 int mdt_attr_get_complex(struct mdt_thread_info *info,
681 struct mdt_object *o, struct md_attr *ma)
683 const struct lu_env *env = info->mti_env;
684 struct md_object *next = mdt_object_child(o);
685 struct lu_buf *buf = &info->mti_buf;
686 u32 mode = lu_object_attr(&next->mo_lu);
687 int need = ma->ma_need;
693 if (need & MA_INODE) {
694 ma->ma_need = MA_INODE;
695 rc = mo_attr_get(env, next, ma);
698 ma->ma_valid |= MA_INODE;
701 if (need & MA_PFID) {
702 rc = mdt_attr_get_pfid(info, o, &ma->ma_pfid);
704 ma->ma_valid |= MA_PFID;
705 /* ignore this error, parent fid is not mandatory */
709 if (need & MA_LOV && (S_ISREG(mode) || S_ISDIR(mode))) {
710 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LOV);
715 if (need & MA_LMV && S_ISDIR(mode)) {
716 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LMV);
721 if (need & MA_LMV_DEF && S_ISDIR(mode)) {
722 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_DEFAULT_LMV);
727 if (need & MA_SOM && S_ISREG(mode)) {
728 buf->lb_buf = info->mti_xattr_buf;
729 buf->lb_len = sizeof(info->mti_xattr_buf);
730 CLASSERT(sizeof(struct som_attrs) <=
731 sizeof(info->mti_xattr_buf));
732 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_SOM);
733 rc2 = lustre_buf2som(info->mti_xattr_buf, rc2, ma->ma_som);
735 ma->ma_valid |= MA_SOM;
736 else if (rc2 < 0 && rc2 != -ENODATA)
740 if (need & MA_HSM && S_ISREG(mode)) {
741 buf->lb_buf = info->mti_xattr_buf;
742 buf->lb_len = sizeof(info->mti_xattr_buf);
743 CLASSERT(sizeof(struct hsm_attrs) <=
744 sizeof(info->mti_xattr_buf));
745 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_HSM);
746 rc2 = lustre_buf2hsm(info->mti_xattr_buf, rc2, &ma->ma_hsm);
748 ma->ma_valid |= MA_HSM;
749 else if (rc2 < 0 && rc2 != -ENODATA)
753 #ifdef CONFIG_FS_POSIX_ACL
754 if (need & MA_ACL_DEF && S_ISDIR(mode)) {
755 buf->lb_buf = ma->ma_acl;
756 buf->lb_len = ma->ma_acl_size;
757 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_DEFAULT);
759 ma->ma_acl_size = rc2;
760 ma->ma_valid |= MA_ACL_DEF;
761 } else if (rc2 == -ENODATA) {
770 CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = "LPX64" ma_lmm=%p\n",
771 rc, ma->ma_valid, ma->ma_lmm);
775 static int mdt_getattr_internal(struct mdt_thread_info *info,
776 struct mdt_object *o, int ma_need)
778 struct md_object *next = mdt_object_child(o);
779 const struct mdt_body *reqbody = info->mti_body;
780 struct ptlrpc_request *req = mdt_info_req(info);
781 struct md_attr *ma = &info->mti_attr;
782 struct lu_attr *la = &ma->ma_attr;
783 struct req_capsule *pill = info->mti_pill;
784 const struct lu_env *env = info->mti_env;
785 struct mdt_body *repbody;
786 struct lu_buf *buffer = &info->mti_buf;
791 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
792 RETURN(err_serious(-ENOMEM));
794 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
798 if (mdt_object_remote(o)) {
799 /* This object is located on remote node.*/
800 /* Return -ENOTSUPP for old client */
801 if (!mdt_is_dne_client(req->rq_export))
802 GOTO(out, rc = -ENOTSUPP);
804 repbody->mbo_fid1 = *mdt_object_fid(o);
805 repbody->mbo_valid = OBD_MD_FLID | OBD_MD_MDS;
809 if (reqbody->mbo_eadatasize > 0) {
810 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
811 if (buffer->lb_buf == NULL)
812 GOTO(out, rc = -EPROTO);
813 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD,
816 buffer->lb_buf = NULL;
818 ma_need &= ~(MA_LOV | MA_LMV);
819 CDEBUG(D_INFO, "%s: RPC from %s: does not need LOVEA.\n",
820 mdt_obd_name(info->mti_mdt),
821 req->rq_export->exp_client_uuid.uuid);
824 /* If it is dir object and client require MEA, then we got MEA */
825 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
826 (reqbody->mbo_valid & (OBD_MD_MEA | OBD_MD_DEFAULT_MEA))) {
827 /* Assumption: MDT_MD size is enough for lmv size. */
828 ma->ma_lmv = buffer->lb_buf;
829 ma->ma_lmv_size = buffer->lb_len;
830 ma->ma_need = MA_INODE;
831 if (ma->ma_lmv_size > 0) {
832 if (reqbody->mbo_valid & OBD_MD_MEA)
833 ma->ma_need |= MA_LMV;
834 else if (reqbody->mbo_valid & OBD_MD_DEFAULT_MEA)
835 ma->ma_need |= MA_LMV_DEF;
838 ma->ma_lmm = buffer->lb_buf;
839 ma->ma_lmm_size = buffer->lb_len;
840 ma->ma_need = MA_INODE | MA_HSM;
841 if (ma->ma_lmm_size > 0)
842 ma->ma_need |= MA_LOV;
845 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
846 reqbody->mbo_valid & OBD_MD_FLDIREA &&
847 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
848 /* get default stripe info for this dir. */
849 ma->ma_need |= MA_LOV_DEF;
851 ma->ma_need |= ma_need;
852 if (ma->ma_need & MA_SOM)
853 ma->ma_som = &info->mti_u.som.data;
855 rc = mdt_attr_get_complex(info, o, ma);
857 CERROR("%s: getattr error for "DFID": rc = %d\n",
858 mdt_obd_name(info->mti_mdt),
859 PFID(mdt_object_fid(o)), rc);
863 /* if file is released, check if a restore is running */
864 if ((ma->ma_valid & MA_HSM) && (ma->ma_hsm.mh_flags & HS_RELEASED) &&
865 mdt_hsm_restore_is_running(info, mdt_object_fid(o))) {
866 repbody->mbo_t_state = MS_RESTORE;
867 repbody->mbo_valid |= OBD_MD_TSTATE;
870 is_root = lu_fid_eq(mdt_object_fid(o), &info->mti_mdt->mdt_md_root_fid);
872 /* the Lustre protocol supposes to return default striping
873 * on the user-visible root if explicitly requested */
874 if ((ma->ma_valid & MA_LOV) == 0 && S_ISDIR(la->la_mode) &&
875 (ma->ma_need & MA_LOV_DEF && is_root) && ma->ma_need & MA_LOV) {
876 struct lu_fid rootfid;
877 struct mdt_object *root;
878 struct mdt_device *mdt = info->mti_mdt;
880 rc = dt_root_get(env, mdt->mdt_bottom, &rootfid);
883 root = mdt_object_find(env, mdt, &rootfid);
885 RETURN(PTR_ERR(root));
886 rc = mdt_stripe_get(info, root, ma, XATTR_NAME_LOV);
887 mdt_object_put(info->mti_env, root);
889 CERROR("%s: getattr error for "DFID": rc = %d\n",
890 mdt_obd_name(info->mti_mdt),
891 PFID(mdt_object_fid(o)), rc);
896 if (likely(ma->ma_valid & MA_INODE))
897 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
901 if (mdt_body_has_lov(la, reqbody)) {
902 if (ma->ma_valid & MA_LOV) {
903 LASSERT(ma->ma_lmm_size);
904 repbody->mbo_eadatasize = ma->ma_lmm_size;
905 if (S_ISDIR(la->la_mode))
906 repbody->mbo_valid |= OBD_MD_FLDIREA;
908 repbody->mbo_valid |= OBD_MD_FLEASIZE;
909 mdt_dump_lmm(D_INFO, ma->ma_lmm, repbody->mbo_valid);
911 if (ma->ma_valid & MA_LMV) {
912 /* Return -ENOTSUPP for old client */
913 if (!mdt_is_striped_client(req->rq_export))
916 LASSERT(S_ISDIR(la->la_mode));
917 mdt_dump_lmv(D_INFO, ma->ma_lmv);
918 repbody->mbo_eadatasize = ma->ma_lmv_size;
919 repbody->mbo_valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
921 if (ma->ma_valid & MA_LMV_DEF) {
922 /* Return -ENOTSUPP for old client */
923 if (!mdt_is_striped_client(req->rq_export))
925 LASSERT(S_ISDIR(la->la_mode));
926 repbody->mbo_eadatasize = ma->ma_lmv_size;
927 repbody->mbo_valid |= (OBD_MD_FLDIREA |
930 } else if (S_ISLNK(la->la_mode) &&
931 reqbody->mbo_valid & OBD_MD_LINKNAME) {
932 buffer->lb_buf = ma->ma_lmm;
933 /* eadatasize from client includes NULL-terminator, so
934 * there is no need to read it */
935 buffer->lb_len = reqbody->mbo_eadatasize - 1;
936 rc = mo_readlink(env, next, buffer);
937 if (unlikely(rc <= 0)) {
938 CERROR("%s: readlink failed for "DFID": rc = %d\n",
939 mdt_obd_name(info->mti_mdt),
940 PFID(mdt_object_fid(o)), rc);
943 int print_limit = min_t(int, PAGE_CACHE_SIZE - 128, rc);
945 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
947 repbody->mbo_valid |= OBD_MD_LINKNAME;
948 /* we need to report back size with NULL-terminator
949 * because client expects that */
950 repbody->mbo_eadatasize = rc + 1;
951 if (repbody->mbo_eadatasize != reqbody->mbo_eadatasize)
952 CDEBUG(D_INODE, "%s: Read shorter symlink %d "
953 "on "DFID ", expected %d\n",
954 mdt_obd_name(info->mti_mdt),
955 rc, PFID(mdt_object_fid(o)),
956 reqbody->mbo_eadatasize - 1);
958 ((char *)ma->ma_lmm)[rc] = 0;
960 /* If the total CDEBUG() size is larger than a page, it
961 * will print a warning to the console, avoid this by
962 * printing just the last part of the symlink. */
963 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
964 print_limit < rc ? "..." : "", print_limit,
965 (char *)ma->ma_lmm + rc - print_limit, rc);
970 if (reqbody->mbo_valid & OBD_MD_FLMODEASIZE) {
971 repbody->mbo_max_cookiesize = 0;
972 repbody->mbo_max_mdsize = info->mti_mdt->mdt_max_mdsize;
973 repbody->mbo_valid |= OBD_MD_FLMODEASIZE;
974 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
975 "MAX_COOKIE to : %d:%d\n", repbody->mbo_max_mdsize,
976 repbody->mbo_max_cookiesize);
979 if (exp_connect_rmtclient(info->mti_exp) &&
980 reqbody->mbo_valid & OBD_MD_FLRMTPERM) {
981 void *buf = req_capsule_server_get(pill, &RMF_ACL);
983 /* mdt_getattr_lock only */
984 rc = mdt_pack_remote_perm(info, o, buf);
986 repbody->mbo_valid &= ~OBD_MD_FLRMTPERM;
987 repbody->mbo_aclsize = 0;
990 repbody->mbo_valid |= OBD_MD_FLRMTPERM;
991 repbody->mbo_aclsize = sizeof(struct mdt_remote_perm);
994 #ifdef CONFIG_FS_POSIX_ACL
995 else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
996 (reqbody->mbo_valid & OBD_MD_FLACL)) {
997 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
998 buffer->lb_len = req_capsule_get_size(pill,
999 &RMF_ACL, RCL_SERVER);
1000 if (buffer->lb_len > 0) {
1001 rc = mo_xattr_get(env, next, buffer,
1002 XATTR_NAME_ACL_ACCESS);
1004 if (rc == -ENODATA) {
1005 repbody->mbo_aclsize = 0;
1006 repbody->mbo_valid |= OBD_MD_FLACL;
1008 } else if (rc == -EOPNOTSUPP) {
1011 CERROR("%s: unable to read "DFID
1013 mdt_obd_name(info->mti_mdt),
1014 PFID(mdt_object_fid(o)), rc);
1017 repbody->mbo_aclsize = rc;
1018 repbody->mbo_valid |= OBD_MD_FLACL;
1025 if (reqbody->mbo_valid & OBD_MD_FLMDSCAPA &&
1026 info->mti_mdt->mdt_lut.lut_mds_capa &&
1027 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
1028 struct lustre_capa *capa;
1030 capa = req_capsule_server_get(pill, &RMF_CAPA1);
1032 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
1033 rc = mo_capa_get(env, next, capa, 0);
1036 repbody->mbo_valid |= OBD_MD_FLMDSCAPA;
1041 mdt_counter_incr(req, LPROC_MDT_GETATTR);
1046 static int mdt_renew_capa(struct mdt_thread_info *info)
1048 struct mdt_object *obj = info->mti_object;
1049 struct mdt_body *body;
1050 struct lustre_capa *capa, *c;
1054 /* if object doesn't exist, or server has disabled capability,
1055 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
1058 if (!obj || !info->mti_mdt->mdt_lut.lut_oss_capa ||
1059 !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA))
1062 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1063 LASSERT(body != NULL);
1065 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
1068 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
1072 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
1074 body->mbo_valid |= OBD_MD_FLOSSCAPA;
1078 static int mdt_getattr(struct tgt_session_info *tsi)
1080 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1081 struct mdt_object *obj = info->mti_object;
1082 struct req_capsule *pill = info->mti_pill;
1083 struct mdt_body *reqbody;
1084 struct mdt_body *repbody;
1088 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
1091 if (reqbody->mbo_valid & OBD_MD_FLOSSCAPA) {
1092 rc = req_capsule_server_pack(pill);
1094 RETURN(err_serious(rc));
1095 rc = mdt_renew_capa(info);
1096 GOTO(out_shrink, rc);
1099 LASSERT(obj != NULL);
1100 LASSERT(lu_object_assert_exists(&obj->mot_obj));
1102 /* Unlike intent case where we need to pre-fill out buffers early on
1103 * in intent policy for ldlm reasons, here we can have a much better
1104 * guess at EA size by just reading it from disk.
1105 * Exceptions are readdir and (missing) directory striping */
1107 if (reqbody->mbo_valid & OBD_MD_LINKNAME) {
1108 /* No easy way to know how long is the symlink, but it cannot
1109 * be more than PATH_MAX, so we allocate +1 */
1112 /* A special case for fs ROOT: getattr there might fetch
1113 * default EA for entire fs, not just for this dir!
1115 } else if (lu_fid_eq(mdt_object_fid(obj),
1116 &info->mti_mdt->mdt_md_root_fid) &&
1117 (reqbody->mbo_valid & OBD_MD_FLDIREA) &&
1118 (lustre_msg_get_opc(mdt_info_req(info)->rq_reqmsg) ==
1120 /* Should the default strping be bigger, mdt_fix_reply
1121 * will reallocate */
1122 rc = DEF_REP_MD_SIZE;
1124 /* Read the actual EA size from disk */
1125 rc = mdt_attr_get_eabuf_size(info, obj);
1129 GOTO(out_shrink, rc);
1131 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, rc);
1133 rc = req_capsule_server_pack(pill);
1134 if (unlikely(rc != 0))
1135 GOTO(out, rc = err_serious(rc));
1137 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1138 LASSERT(repbody != NULL);
1139 repbody->mbo_eadatasize = 0;
1140 repbody->mbo_aclsize = 0;
1142 if (reqbody->mbo_valid & OBD_MD_FLRMTPERM)
1143 rc = mdt_init_ucred(info, reqbody);
1145 rc = mdt_check_ucred(info);
1147 GOTO(out_shrink, rc);
1149 info->mti_cross_ref = !!(reqbody->mbo_valid & OBD_MD_FLCROSSREF);
1152 * Don't check capability at all, because rename might getattr for
1153 * remote obj, and at that time no capability is available.
1155 mdt_set_capainfo(info, 1, &reqbody->mbo_fid1, BYPASS_CAPA);
1156 rc = mdt_getattr_internal(info, obj, 0);
1157 if (reqbody->mbo_valid & OBD_MD_FLRMTPERM)
1158 mdt_exit_ucred(info);
1161 mdt_client_compatibility(info);
1162 rc2 = mdt_fix_reply(info);
1166 mdt_thread_info_fini(info);
1170 static int mdt_swap_layouts(struct tgt_session_info *tsi)
1172 struct mdt_thread_info *info;
1173 struct ptlrpc_request *req = tgt_ses_req(tsi);
1174 struct obd_export *exp = req->rq_export;
1175 struct mdt_object *o1, *o2, *o;
1176 struct mdt_lock_handle *lh1, *lh2;
1177 struct mdc_swap_layouts *msl;
1181 /* client does not support layout lock, so layout swaping
1183 * FIXME: there is a problem for old clients which don't support
1184 * layout lock yet. If those clients have already opened the file
1185 * they won't be notified at all so that old layout may still be
1186 * used to do IO. This can be fixed after file release is landed by
1187 * doing exclusive open and taking full EX ibits lock. - Jinshan */
1188 if (!exp_connect_layout(exp))
1189 RETURN(-EOPNOTSUPP);
1191 info = tsi2mdt_info(tsi);
1193 if (info->mti_dlm_req != NULL)
1194 ldlm_request_cancel(req, info->mti_dlm_req, 0);
1196 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT))
1197 mdt_set_capainfo(info, 0, &info->mti_body->mbo_fid1,
1198 req_capsule_client_get(info->mti_pill,
1201 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA2, RCL_CLIENT))
1202 mdt_set_capainfo(info, 1, &info->mti_body->mbo_fid2,
1203 req_capsule_client_get(info->mti_pill,
1206 o1 = info->mti_object;
1207 o = o2 = mdt_object_find(info->mti_env, info->mti_mdt,
1208 &info->mti_body->mbo_fid2);
1210 GOTO(out, rc = PTR_ERR(o));
1212 if (mdt_object_remote(o) || !mdt_object_exists(o)) /* remote object */
1213 GOTO(put, rc = -ENOENT);
1215 rc = lu_fid_cmp(&info->mti_body->mbo_fid1, &info->mti_body->mbo_fid2);
1216 if (unlikely(rc == 0)) /* same file, you kidding me? no-op. */
1222 /* permission check. Make sure the calling process having permission
1223 * to write both files. */
1224 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o1), NULL,
1229 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o2), NULL,
1234 msl = req_capsule_client_get(info->mti_pill, &RMF_SWAP_LAYOUTS);
1236 GOTO(put, rc = -EPROTO);
1238 lh1 = &info->mti_lh[MDT_LH_NEW];
1239 mdt_lock_reg_init(lh1, LCK_EX);
1240 lh2 = &info->mti_lh[MDT_LH_OLD];
1241 mdt_lock_reg_init(lh2, LCK_EX);
1243 rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT |
1244 MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
1248 rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT |
1249 MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
1253 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
1254 mdt_object_child(o2), msl->msl_flags);
1257 mdt_object_unlock(info, o2, lh2, rc);
1259 mdt_object_unlock(info, o1, lh1, rc);
1261 mdt_object_put(info->mti_env, o);
1263 mdt_thread_info_fini(info);
1267 static int mdt_raw_lookup(struct mdt_thread_info *info,
1268 struct mdt_object *parent,
1269 const struct lu_name *lname,
1270 struct ldlm_reply *ldlm_rep)
1272 struct md_object *next = mdt_object_child(info->mti_object);
1273 const struct mdt_body *reqbody = info->mti_body;
1274 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1275 struct mdt_body *repbody;
1279 if (reqbody->mbo_valid != OBD_MD_FLID)
1282 LASSERT(!info->mti_cross_ref);
1284 /* Only got the fid of this obj by name */
1285 fid_zero(child_fid);
1286 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1289 /* XXX is raw_lookup possible as intent operation? */
1292 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1295 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1297 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1300 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1301 repbody->mbo_fid1 = *child_fid;
1302 repbody->mbo_valid = OBD_MD_FLID;
1308 * UPDATE lock should be taken against parent, and be release before exit;
1309 * child_bits lock should be taken against child, and be returned back:
1310 * (1)normal request should release the child lock;
1311 * (2)intent request will grant the lock to client.
1313 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
1314 struct mdt_lock_handle *lhc,
1316 struct ldlm_reply *ldlm_rep)
1318 struct ptlrpc_request *req = mdt_info_req(info);
1319 struct mdt_body *reqbody = NULL;
1320 struct mdt_object *parent = info->mti_object;
1321 struct mdt_object *child;
1322 struct md_object *next = mdt_object_child(parent);
1323 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1324 struct lu_name *lname = NULL;
1325 struct mdt_lock_handle *lhp = NULL;
1326 struct ldlm_lock *lock;
1333 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
1334 LASSERT(ergo(is_resent,
1335 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
1337 LASSERT(parent != NULL);
1339 if (info->mti_cross_ref) {
1340 /* Only getattr on the child. Parent is on another node. */
1341 mdt_set_disposition(info, ldlm_rep,
1342 DISP_LOOKUP_EXECD | DISP_LOOKUP_POS);
1344 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
1346 PFID(mdt_object_fid(child)), ldlm_rep);
1348 rc = mdt_check_resent_lock(info, child, lhc);
1351 } else if (rc > 0) {
1352 mdt_lock_handle_init(lhc);
1353 mdt_lock_reg_init(lhc, LCK_PR);
1356 * Object's name is on another MDS, no lookup or layout
1357 * lock is needed here but update lock is.
1359 child_bits &= ~(MDS_INODELOCK_LOOKUP |
1360 MDS_INODELOCK_LAYOUT);
1361 child_bits |= MDS_INODELOCK_PERM | MDS_INODELOCK_UPDATE;
1363 rc = mdt_object_lock(info, child, lhc, child_bits,
1369 /* Finally, we can get attr for child. */
1370 if (!mdt_object_exists(child)) {
1371 LU_OBJECT_DEBUG(D_INFO, info->mti_env,
1373 "remote object doesn't exist.\n");
1374 mdt_object_unlock(info, child, lhc, 1);
1378 mdt_set_capainfo(info, 0, mdt_object_fid(child), BYPASS_CAPA);
1379 rc = mdt_getattr_internal(info, child, 0);
1380 if (unlikely(rc != 0))
1381 mdt_object_unlock(info, child, lhc, 1);
1386 lname = &info->mti_name;
1387 mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON);
1389 if (lu_name_is_valid(lname)) {
1390 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", "
1391 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
1392 PNAME(lname), ldlm_rep);
1394 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1395 if (unlikely(reqbody == NULL))
1396 RETURN(err_serious(-EPROTO));
1398 *child_fid = reqbody->mbo_fid2;
1400 if (unlikely(!fid_is_sane(child_fid)))
1401 RETURN(err_serious(-EINVAL));
1403 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
1405 PFID(mdt_object_fid(parent)),
1406 PFID(&reqbody->mbo_fid2), ldlm_rep);
1409 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
1411 if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) {
1412 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1414 "Parent doesn't exist!\n");
1418 if (mdt_object_remote(parent)) {
1419 CERROR("%s: parent "DFID" is on remote target\n",
1420 mdt_obd_name(info->mti_mdt),
1421 PFID(mdt_object_fid(parent)));
1425 if (lu_name_is_valid(lname)) {
1426 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
1433 /* step 1: lock parent only if parent is a directory */
1434 if (S_ISDIR(lu_object_attr(&parent->mot_obj))) {
1435 lhp = &info->mti_lh[MDT_LH_PARENT];
1436 mdt_lock_pdo_init(lhp, LCK_PR, lname);
1437 rc = mdt_object_lock(info, parent, lhp,
1438 MDS_INODELOCK_UPDATE,
1440 if (unlikely(rc != 0))
1444 /* step 2: lookup child's fid by name */
1445 fid_zero(child_fid);
1446 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1449 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1452 GOTO(out_parent, rc);
1455 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1458 *step 3: find the child object by fid & lock it.
1459 * regardless if it is local or remote.
1461 *Note: LU-3240 (commit 762f2114d282a98ebfa4dbbeea9298a8088ad24e)
1462 * set parent dir fid the same as child fid in getattr by fid case
1463 * we should not lu_object_find() the object again, could lead
1464 * to hung if there is a concurrent unlink destroyed the object.
1466 if (lu_fid_eq(mdt_object_fid(parent), child_fid)) {
1467 mdt_object_get(info->mti_env, parent);
1470 child = mdt_object_find(info->mti_env, info->mti_mdt,
1474 if (unlikely(IS_ERR(child)))
1475 GOTO(out_parent, rc = PTR_ERR(child));
1477 rc = mdt_check_resent_lock(info, child, lhc);
1479 GOTO(out_child, rc);
1480 } else if (rc > 0) {
1481 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1482 mdt_lock_handle_init(lhc);
1483 mdt_lock_reg_init(lhc, LCK_PR);
1486 if (!mdt_object_exists(child)) {
1487 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1489 "Object doesn't exist!\n");
1490 GOTO(out_child, rc = -ENOENT);
1493 if (!(child_bits & MDS_INODELOCK_UPDATE) &&
1494 mdt_object_exists(child) && !mdt_object_remote(child)) {
1495 struct md_attr *ma = &info->mti_attr;
1498 ma->ma_need = MA_INODE;
1499 rc = mdt_attr_get_complex(info, child, ma);
1500 if (unlikely(rc != 0))
1501 GOTO(out_child, rc);
1503 /* If the file has not been changed for some time, we
1504 * return not only a LOOKUP lock, but also an UPDATE
1505 * lock and this might save us RPC on later STAT. For
1506 * directories, it also let negative dentry cache start
1507 * working for this dir. */
1508 if (ma->ma_valid & MA_INODE &&
1509 ma->ma_attr.la_valid & LA_CTIME &&
1510 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1511 ma->ma_attr.la_ctime < cfs_time_current_sec())
1512 child_bits |= MDS_INODELOCK_UPDATE;
1515 /* layout lock must be granted in a best-effort way
1516 * for IT operations */
1517 LASSERT(!(child_bits & MDS_INODELOCK_LAYOUT));
1518 if (!OBD_FAIL_CHECK(OBD_FAIL_MDS_NO_LL_GETATTR) &&
1519 exp_connect_layout(info->mti_exp) &&
1520 S_ISREG(lu_object_attr(&child->mot_obj)) &&
1521 !mdt_object_remote(child) && ldlm_rep != NULL) {
1522 /* try to grant layout lock for regular file. */
1528 child_bits |= MDS_INODELOCK_LAYOUT;
1529 /* try layout lock, it may fail to be granted due to
1530 * contention at LOOKUP or UPDATE */
1531 if (!mdt_object_lock_try(info, child, lhc, child_bits,
1533 child_bits &= ~MDS_INODELOCK_LAYOUT;
1534 LASSERT(child_bits != 0);
1535 rc = mdt_object_lock(info, child, lhc,
1536 child_bits, MDT_CROSS_LOCK);
1541 /* Do not enqueue the UPDATE lock from MDT(cross-MDT),
1542 * client will enqueue the lock to the remote MDT */
1543 if (mdt_object_remote(child))
1544 child_bits &= ~MDS_INODELOCK_UPDATE;
1545 rc = mdt_object_lock(info, child, lhc, child_bits,
1548 if (unlikely(rc != 0))
1549 GOTO(out_child, rc);
1552 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1553 /* Get MA_SOM attributes if update lock is given. */
1555 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1556 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1559 /* finally, we can get attr for child. */
1560 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1561 rc = mdt_getattr_internal(info, child, ma_need);
1562 if (unlikely(rc != 0)) {
1563 mdt_object_unlock(info, child, lhc, 1);
1565 /* Debugging code. */
1566 LDLM_DEBUG(lock, "Returning lock to client");
1567 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1568 &lock->l_resource->lr_name),
1569 "Lock res_id: "DLDLMRES", fid: "DFID"\n",
1570 PLDLMRES(lock->l_resource),
1571 PFID(mdt_object_fid(child)));
1572 if (mdt_object_exists(child) && !mdt_object_remote(child))
1573 mdt_pack_size2body(info, child);
1576 LDLM_LOCK_PUT(lock);
1580 mdt_object_put(info->mti_env, child);
1583 mdt_object_unlock(info, parent, lhp, 1);
1587 /* normal handler: should release the child lock */
1588 static int mdt_getattr_name(struct tgt_session_info *tsi)
1590 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1591 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1592 struct mdt_body *reqbody;
1593 struct mdt_body *repbody;
1597 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1598 LASSERT(reqbody != NULL);
1599 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1600 LASSERT(repbody != NULL);
1602 info->mti_cross_ref = !!(reqbody->mbo_valid & OBD_MD_FLCROSSREF);
1603 repbody->mbo_eadatasize = 0;
1604 repbody->mbo_aclsize = 0;
1606 rc = mdt_init_ucred(info, reqbody);
1608 GOTO(out_shrink, rc);
1610 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1611 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1612 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1613 lhc->mlh_reg_lh.cookie = 0;
1615 mdt_exit_ucred(info);
1618 mdt_client_compatibility(info);
1619 rc2 = mdt_fix_reply(info);
1622 mdt_thread_info_fini(info);
1626 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1627 void *karg, void *uarg);
1629 static int mdt_set_info(struct tgt_session_info *tsi)
1631 struct ptlrpc_request *req = tgt_ses_req(tsi);
1634 int keylen, vallen, rc = 0;
1638 key = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_KEY);
1640 DEBUG_REQ(D_HA, req, "no set_info key");
1641 RETURN(err_serious(-EFAULT));
1644 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_KEY,
1647 val = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_VAL);
1649 DEBUG_REQ(D_HA, req, "no set_info val");
1650 RETURN(err_serious(-EFAULT));
1653 vallen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_VAL,
1656 /* Swab any part of val you need to here */
1657 if (KEY_IS(KEY_READ_ONLY)) {
1658 spin_lock(&req->rq_export->exp_lock);
1660 *exp_connect_flags_ptr(req->rq_export) |=
1663 *exp_connect_flags_ptr(req->rq_export) &=
1664 ~OBD_CONNECT_RDONLY;
1665 spin_unlock(&req->rq_export->exp_lock);
1666 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1667 struct changelog_setinfo *cs = val;
1669 if (vallen != sizeof(*cs)) {
1670 CERROR("%s: bad changelog_clear setinfo size %d\n",
1671 tgt_name(tsi->tsi_tgt), vallen);
1674 if (ptlrpc_req_need_swab(req)) {
1675 __swab64s(&cs->cs_recno);
1676 __swab32s(&cs->cs_id);
1679 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, req->rq_export,
1687 static int mdt_readpage(struct tgt_session_info *tsi)
1689 struct mdt_thread_info *info = mdt_th_info(tsi->tsi_env);
1690 struct mdt_object *object = mdt_obj(tsi->tsi_corpus);
1691 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1692 const struct mdt_body *reqbody = tsi->tsi_mdt_body;
1693 struct mdt_body *repbody;
1699 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1700 RETURN(err_serious(-ENOMEM));
1702 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_MDT_BODY);
1703 if (repbody == NULL || reqbody == NULL)
1704 RETURN(err_serious(-EFAULT));
1707 * prepare @rdpg before calling lower layers and transfer itself. Here
1708 * reqbody->size contains offset of where to start to read and
1709 * reqbody->nlink contains number bytes to read.
1711 rdpg->rp_hash = reqbody->mbo_size;
1712 if (rdpg->rp_hash != reqbody->mbo_size) {
1713 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1714 rdpg->rp_hash, reqbody->mbo_size);
1718 rdpg->rp_attrs = reqbody->mbo_mode;
1719 if (exp_connect_flags(tsi->tsi_exp) & OBD_CONNECT_64BITHASH)
1720 rdpg->rp_attrs |= LUDA_64BITHASH;
1721 rdpg->rp_count = min_t(unsigned int, reqbody->mbo_nlink,
1722 exp_max_brw_size(tsi->tsi_exp));
1723 rdpg->rp_npages = (rdpg->rp_count + PAGE_CACHE_SIZE - 1) >>
1725 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1726 if (rdpg->rp_pages == NULL)
1729 for (i = 0; i < rdpg->rp_npages; ++i) {
1730 rdpg->rp_pages[i] = alloc_page(GFP_IOFS);
1731 if (rdpg->rp_pages[i] == NULL)
1732 GOTO(free_rdpg, rc = -ENOMEM);
1735 /* call lower layers to fill allocated pages with directory data */
1736 rc = mo_readpage(tsi->tsi_env, mdt_object_child(object), rdpg);
1738 GOTO(free_rdpg, rc);
1740 /* send pages to client */
1741 rc = tgt_sendpage(tsi, rdpg, rc);
1746 for (i = 0; i < rdpg->rp_npages; i++)
1747 if (rdpg->rp_pages[i] != NULL)
1748 __free_page(rdpg->rp_pages[i]);
1749 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1751 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1757 static int mdt_reint_internal(struct mdt_thread_info *info,
1758 struct mdt_lock_handle *lhc,
1761 struct req_capsule *pill = info->mti_pill;
1762 struct mdt_body *repbody;
1767 rc = mdt_reint_unpack(info, op);
1769 CERROR("Can't unpack reint, rc %d\n", rc);
1770 RETURN(err_serious(rc));
1773 /* for replay (no_create) lmm is not needed, client has it already */
1774 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1775 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1778 /* llog cookies are always 0, the field is kept for compatibility */
1779 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1780 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, 0);
1782 rc = req_capsule_server_pack(pill);
1784 CERROR("Can't pack response, rc %d\n", rc);
1785 RETURN(err_serious(rc));
1788 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1789 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1791 repbody->mbo_eadatasize = 0;
1792 repbody->mbo_aclsize = 0;
1795 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1797 /* for replay no cookkie / lmm need, because client have this already */
1798 if (info->mti_spec.no_create)
1799 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1800 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1802 rc = mdt_init_ucred_reint(info);
1804 GOTO(out_shrink, rc);
1806 rc = mdt_fix_attr_ucred(info, op);
1808 GOTO(out_ucred, rc = err_serious(rc));
1810 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1811 DEBUG_REQ(D_INODE, mdt_info_req(info), "resent opt.");
1812 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1813 GOTO(out_ucred, rc);
1815 rc = mdt_reint_rec(info, lhc);
1818 mdt_exit_ucred(info);
1820 mdt_client_compatibility(info);
1821 rc2 = mdt_fix_reply(info);
1827 static long mdt_reint_opcode(struct ptlrpc_request *req,
1828 const struct req_format **fmt)
1830 struct mdt_device *mdt;
1831 struct mdt_rec_reint *rec;
1834 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
1836 opc = rec->rr_opcode;
1837 DEBUG_REQ(D_INODE, req, "reint opt = %ld", opc);
1838 if (opc < REINT_MAX && fmt[opc] != NULL)
1839 req_capsule_extend(&req->rq_pill, fmt[opc]);
1841 mdt = mdt_exp2dev(req->rq_export);
1842 CERROR("%s: Unsupported opcode '%ld' from client '%s':"
1843 " rc = %d\n", req->rq_export->exp_obd->obd_name,
1844 opc, mdt->mdt_ldlm_client->cli_name, -EFAULT);
1845 opc = err_serious(-EFAULT);
1848 opc = err_serious(-EFAULT);
1853 static int mdt_reint(struct tgt_session_info *tsi)
1857 static const struct req_format *reint_fmts[REINT_MAX] = {
1858 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1859 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1860 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1861 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1862 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1863 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1864 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR,
1865 [REINT_RMENTRY] = &RQF_MDS_REINT_UNLINK,
1866 [REINT_MIGRATE] = &RQF_MDS_REINT_RENAME
1871 opc = mdt_reint_opcode(tgt_ses_req(tsi), reint_fmts);
1873 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1875 * No lock possible here from client to pass it to reint code
1878 rc = mdt_reint_internal(info, NULL, opc);
1879 mdt_thread_info_fini(info);
1884 tsi->tsi_reply_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1888 /* this should sync the whole device */
1889 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1891 struct dt_device *dt = mdt->mdt_bottom;
1895 rc = dt->dd_ops->dt_sync(env, dt);
1899 /* this should sync this object */
1900 static int mdt_object_sync(struct mdt_thread_info *info)
1902 struct md_object *next;
1906 if (!mdt_object_exists(info->mti_object)) {
1907 CWARN("%s: non existing object "DFID": rc = %d\n",
1908 mdt_obd_name(info->mti_mdt),
1909 PFID(mdt_object_fid(info->mti_object)), -ESTALE);
1912 next = mdt_object_child(info->mti_object);
1913 rc = mo_object_sync(info->mti_env, next);
1918 static int mdt_sync(struct tgt_session_info *tsi)
1920 struct ptlrpc_request *req = tgt_ses_req(tsi);
1921 struct req_capsule *pill = tsi->tsi_pill;
1922 struct mdt_body *body;
1927 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1928 RETURN(err_serious(-ENOMEM));
1930 if (fid_seq(&tsi->tsi_mdt_body->mbo_fid1) == 0) {
1931 rc = mdt_device_sync(tsi->tsi_env, mdt_exp2dev(tsi->tsi_exp));
1933 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1935 /* sync an object */
1936 rc = mdt_object_sync(info);
1938 const struct lu_fid *fid;
1939 struct lu_attr *la = &info->mti_attr.ma_attr;
1941 info->mti_attr.ma_need = MA_INODE;
1942 info->mti_attr.ma_valid = 0;
1943 rc = mdt_attr_get_complex(info, info->mti_object,
1946 body = req_capsule_server_get(pill,
1948 fid = mdt_object_fid(info->mti_object);
1949 mdt_pack_attr2body(info, body, la, fid);
1952 mdt_thread_info_fini(info);
1955 mdt_counter_incr(req, LPROC_MDT_SYNC);
1961 * Handle quota control requests to consult current usage/limit, but also
1962 * to configure quota enforcement
1964 static int mdt_quotactl(struct tgt_session_info *tsi)
1966 struct obd_export *exp = tsi->tsi_exp;
1967 struct req_capsule *pill = tsi->tsi_pill;
1968 struct obd_quotactl *oqctl, *repoqc;
1970 struct mdt_device *mdt = mdt_exp2dev(exp);
1971 struct lu_device *qmt = mdt->mdt_qmt_dev;
1974 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1976 RETURN(err_serious(-EPROTO));
1978 rc = req_capsule_server_pack(pill);
1980 RETURN(err_serious(rc));
1982 switch (oqctl->qc_cmd) {
1984 case LUSTRE_Q_INVALIDATE:
1985 case LUSTRE_Q_FINVALIDATE:
1989 /* deprecated, not used any more */
1990 RETURN(-EOPNOTSUPP);
1991 /* master quotactl */
1997 RETURN(-EOPNOTSUPP);
1998 /* slave quotactl */
2003 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2007 /* map uid/gid for remote client */
2009 if (exp_connect_rmtclient(exp)) {
2010 struct lustre_idmap_table *idmap;
2012 idmap = exp->exp_mdt_data.med_idmap;
2014 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
2015 oqctl->qc_cmd != Q_GETINFO))
2018 if (oqctl->qc_type == USRQUOTA)
2019 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
2021 else if (oqctl->qc_type == GRPQUOTA)
2022 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
2027 if (id == CFS_IDMAP_NOTFOUND) {
2028 CDEBUG(D_QUOTA, "no mapping for id %u\n", oqctl->qc_id);
2033 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
2035 RETURN(err_serious(-EFAULT));
2037 if (oqctl->qc_id != id)
2038 swap(oqctl->qc_id, id);
2040 switch (oqctl->qc_cmd) {
2046 /* forward quotactl request to QMT */
2047 rc = qmt_hdls.qmth_quotactl(tsi->tsi_env, qmt, oqctl);
2052 /* slave quotactl */
2053 rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom,
2058 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2062 if (oqctl->qc_id != id)
2063 swap(oqctl->qc_id, id);
2069 /** clone llog ctxt from child (mdd)
2070 * This allows remote llog (replicator) access.
2071 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
2072 * context was originally set up, or we can handle them directly.
2073 * I choose the latter, but that means I need any llog
2074 * contexts set up by child to be accessable by the mdt. So we clone the
2075 * context into our context list here.
2077 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
2080 struct md_device *next = mdt->mdt_child;
2081 struct llog_ctxt *ctxt;
2084 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
2087 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
2088 if (rc || ctxt == NULL) {
2092 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2094 CERROR("Can't set mdt ctxt %d\n", rc);
2099 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2100 struct mdt_device *mdt, int idx)
2102 struct llog_ctxt *ctxt;
2104 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2107 /* Put once for the get we just did, and once for the clone */
2108 llog_ctxt_put(ctxt);
2109 llog_ctxt_put(ctxt);
2114 * sec context handlers
2116 static int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
2120 rc = mdt_handle_idmap(tsi);
2122 struct ptlrpc_request *req = tgt_ses_req(tsi);
2125 opc = lustre_msg_get_opc(req->rq_reqmsg);
2126 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2127 sptlrpc_svc_ctx_invalidate(req);
2130 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2136 * quota request handlers
2138 static int mdt_quota_dqacq(struct tgt_session_info *tsi)
2140 struct mdt_device *mdt = mdt_exp2dev(tsi->tsi_exp);
2141 struct lu_device *qmt = mdt->mdt_qmt_dev;
2146 RETURN(err_serious(-EOPNOTSUPP));
2148 rc = qmt_hdls.qmth_dqacq(tsi->tsi_env, qmt, tgt_ses_req(tsi));
2152 struct mdt_object *mdt_object_new(const struct lu_env *env,
2153 struct mdt_device *d,
2154 const struct lu_fid *f)
2156 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2157 struct lu_object *o;
2158 struct mdt_object *m;
2161 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2162 o = lu_object_find(env, &d->mdt_lu_dev, f, &conf);
2163 if (unlikely(IS_ERR(o)))
2164 m = (struct mdt_object *)o;
2170 struct mdt_object *mdt_object_find(const struct lu_env *env,
2171 struct mdt_device *d,
2172 const struct lu_fid *f)
2174 struct lu_object *o;
2175 struct mdt_object *m;
2178 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2179 o = lu_object_find(env, &d->mdt_lu_dev, f, NULL);
2180 if (unlikely(IS_ERR(o)))
2181 m = (struct mdt_object *)o;
2189 * Asyncronous commit for mdt device.
2191 * Pass asynchonous commit call down the MDS stack.
2193 * \param env environment
2194 * \param mdt the mdt device
2196 static void mdt_device_commit_async(const struct lu_env *env,
2197 struct mdt_device *mdt)
2199 struct dt_device *dt = mdt->mdt_bottom;
2202 rc = dt->dd_ops->dt_commit_async(env, dt);
2203 if (unlikely(rc != 0))
2204 CWARN("%s: async commit start failed: rc = %d\n",
2205 mdt_obd_name(mdt), rc);
2209 * Mark the lock as "synchonous".
2211 * Mark the lock to deffer transaction commit to the unlock time.
2213 * \param lock the lock to mark as "synchonous"
2215 * \see mdt_is_lock_sync
2216 * \see mdt_save_lock
2218 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2220 lock->l_ast_data = (void*)1;
2224 * Check whehter the lock "synchonous" or not.
2226 * \param lock the lock to check
2227 * \retval 1 the lock is "synchonous"
2228 * \retval 0 the lock isn't "synchronous"
2230 * \see mdt_set_lock_sync
2231 * \see mdt_save_lock
2233 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2235 return lock->l_ast_data != NULL;
2239 * Blocking AST for mdt locks.
2241 * Starts transaction commit if in case of COS lock conflict or
2242 * deffers such a commit to the mdt_save_lock.
2244 * \param lock the lock which blocks a request or cancelling lock
2245 * \param desc unused
2246 * \param data unused
2247 * \param flag indicates whether this cancelling or blocking callback
2249 * \see ldlm_blocking_ast_nocheck
2251 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2252 void *data, int flag)
2254 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2255 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2259 if (flag == LDLM_CB_CANCELING)
2261 lock_res_and_lock(lock);
2262 if (lock->l_blocking_ast != mdt_blocking_ast) {
2263 unlock_res_and_lock(lock);
2266 if (mdt_cos_is_enabled(mdt) &&
2267 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2268 lock->l_blocking_lock != NULL &&
2269 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2270 mdt_set_lock_sync(lock);
2272 rc = ldlm_blocking_ast_nocheck(lock);
2274 /* There is no lock conflict if l_blocking_lock == NULL,
2275 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2276 * when the last reference to a local lock was released */
2277 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2280 rc = lu_env_init(&env, LCT_LOCAL);
2281 if (unlikely(rc != 0))
2282 CWARN("%s: lu_env initialization failed, cannot "
2283 "start asynchronous commit: rc = %d\n",
2286 mdt_device_commit_async(&env, mdt);
2292 /* Used for cross-MDT lock */
2293 int mdt_remote_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2294 void *data, int flag)
2296 struct lustre_handle lockh;
2300 case LDLM_CB_BLOCKING:
2301 ldlm_lock2handle(lock, &lockh);
2302 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
2304 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
2308 case LDLM_CB_CANCELING:
2309 LDLM_DEBUG(lock, "Revoke remote lock\n");
2317 int mdt_check_resent_lock(struct mdt_thread_info *info,
2318 struct mdt_object *mo,
2319 struct mdt_lock_handle *lhc)
2321 /* the lock might already be gotten in ldlm_handle_enqueue() */
2322 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
2323 struct ptlrpc_request *req = mdt_info_req(info);
2324 struct ldlm_lock *lock;
2326 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
2327 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
2328 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
2329 lhc->mlh_reg_lh.cookie);
2331 if (!fid_res_name_eq(mdt_object_fid(mo),
2332 &lock->l_resource->lr_name)) {
2333 CWARN("%s: Although resent, but still not "
2334 "get child lock:"DFID"\n",
2335 info->mti_exp->exp_obd->obd_name,
2336 PFID(mdt_object_fid(mo)));
2337 LDLM_LOCK_PUT(lock);
2340 LDLM_LOCK_PUT(lock);
2346 int mdt_remote_object_lock(struct mdt_thread_info *mti,
2347 struct mdt_object *o, const struct lu_fid *fid,
2348 struct lustre_handle *lh, ldlm_mode_t mode,
2351 struct ldlm_enqueue_info *einfo = &mti->mti_einfo;
2352 ldlm_policy_data_t *policy = &mti->mti_policy;
2353 struct ldlm_res_id *res_id = &mti->mti_res_id;
2357 LASSERT(mdt_object_remote(o));
2359 LASSERT(ibits == MDS_INODELOCK_UPDATE);
2361 fid_build_reg_res_name(fid, res_id);
2363 memset(einfo, 0, sizeof(*einfo));
2364 einfo->ei_type = LDLM_IBITS;
2365 einfo->ei_mode = mode;
2366 einfo->ei_cb_bl = mdt_remote_blocking_ast;
2367 einfo->ei_cb_cp = ldlm_completion_ast;
2368 einfo->ei_enq_slave = 0;
2369 einfo->ei_res_id = res_id;
2371 memset(policy, 0, sizeof(*policy));
2372 policy->l_inodebits.bits = ibits;
2374 rc = mo_object_lock(mti->mti_env, mdt_object_child(o), lh, einfo,
2379 static int mdt_object_local_lock(struct mdt_thread_info *info,
2380 struct mdt_object *o,
2381 struct mdt_lock_handle *lh, __u64 ibits,
2382 bool nonblock, int locality)
2384 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2385 ldlm_policy_data_t *policy = &info->mti_policy;
2386 struct ldlm_res_id *res_id = &info->mti_res_id;
2391 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2392 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2393 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2394 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2396 /* Only enqueue LOOKUP lock for remote object */
2397 if (mdt_object_remote(o))
2398 LASSERT(ibits == MDS_INODELOCK_LOOKUP);
2400 if (lh->mlh_type == MDT_PDO_LOCK) {
2401 /* check for exists after object is locked */
2402 if (mdt_object_exists(o) == 0) {
2403 /* Non-existent object shouldn't have PDO lock */
2406 /* Non-dir object shouldn't have PDO lock */
2407 if (!S_ISDIR(lu_object_attr(&o->mot_obj)))
2412 memset(policy, 0, sizeof(*policy));
2413 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2415 dlmflags = LDLM_FL_ATOMIC_CB;
2417 dlmflags |= LDLM_FL_BLOCK_NOWAIT;
2420 * Take PDO lock on whole directory and build correct @res_id for lock
2421 * on part of directory.
2423 if (lh->mlh_pdo_hash != 0) {
2424 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2425 mdt_lock_pdo_mode(info, o, lh);
2426 if (lh->mlh_pdo_mode != LCK_NL) {
2428 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2429 * is never going to be sent to client and we do not
2430 * want it slowed down due to possible cancels.
2432 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2433 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2434 policy, res_id, dlmflags,
2435 info->mti_exp == NULL ? NULL :
2436 &info->mti_exp->exp_handle.h_cookie);
2442 * Finish res_id initializing by name hash marking part of
2443 * directory which is taking modification.
2445 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2448 policy->l_inodebits.bits = ibits;
2451 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2452 * going to be sent to client. If it is - mdt_intent_policy() path will
2453 * fix it up and turn FL_LOCAL flag off.
2455 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2456 res_id, LDLM_FL_LOCAL_ONLY | dlmflags,
2457 info->mti_exp == NULL ? NULL :
2458 &info->mti_exp->exp_handle.h_cookie);
2460 mdt_object_unlock(info, o, lh, 1);
2461 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2462 lh->mlh_pdo_hash != 0 &&
2463 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2464 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2471 mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o,
2472 struct mdt_lock_handle *lh, __u64 ibits,
2473 bool nonblock, int locality)
2478 if (!mdt_object_remote(o))
2479 return mdt_object_local_lock(info, o, lh, ibits, nonblock,
2482 if (locality == MDT_LOCAL_LOCK) {
2483 CERROR("%s: try to get local lock for remote object"
2484 DFID".\n", mdt_obd_name(info->mti_mdt),
2485 PFID(mdt_object_fid(o)));
2489 /* XXX do not support PERM/LAYOUT/XATTR lock for remote object yet */
2490 ibits &= ~(MDS_INODELOCK_PERM | MDS_INODELOCK_LAYOUT |
2491 MDS_INODELOCK_XATTR);
2492 if (ibits & MDS_INODELOCK_UPDATE) {
2493 /* Sigh, PDO needs to enqueue 2 locks right now, but
2494 * enqueue RPC can only request 1 lock, to avoid extra
2495 * RPC, so it will instead enqueue EX lock for remote
2496 * object anyway XXX*/
2497 if (lh->mlh_type == MDT_PDO_LOCK &&
2498 lh->mlh_pdo_hash != 0) {
2499 CDEBUG(D_INFO, "%s: "DFID" convert PDO lock to"
2500 "EX lock.\n", mdt_obd_name(info->mti_mdt),
2501 PFID(mdt_object_fid(o)));
2502 lh->mlh_pdo_hash = 0;
2503 lh->mlh_rreg_mode = LCK_EX;
2504 lh->mlh_type = MDT_REG_LOCK;
2506 rc = mdt_remote_object_lock(info, o, mdt_object_fid(o),
2509 MDS_INODELOCK_UPDATE);
2514 /* Only enqueue LOOKUP lock for remote object */
2515 if (ibits & MDS_INODELOCK_LOOKUP) {
2516 rc = mdt_object_local_lock(info, o, lh,
2517 MDS_INODELOCK_LOOKUP,
2518 nonblock, locality);
2526 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2527 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2529 return mdt_object_lock_internal(info, o, lh, ibits, false, locality);
2532 int mdt_object_lock_try(struct mdt_thread_info *info, struct mdt_object *o,
2533 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2535 struct mdt_lock_handle tmp = *lh;
2538 rc = mdt_object_lock_internal(info, o, &tmp, ibits, true, locality);
2546 * Save a lock within request object.
2548 * Keep the lock referenced until whether client ACK or transaction
2549 * commit happens or release the lock immediately depending on input
2550 * parameters. If COS is ON, a write lock is converted to COS lock
2553 * \param info thead info object
2554 * \param h lock handle
2555 * \param mode lock mode
2556 * \param decref force immediate lock releasing
2559 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2560 ldlm_mode_t mode, int decref)
2564 if (lustre_handle_is_used(h)) {
2565 if (decref || !info->mti_has_trans ||
2566 !(mode & (LCK_PW | LCK_EX))){
2567 mdt_fid_unlock(h, mode);
2569 struct mdt_device *mdt = info->mti_mdt;
2570 struct ldlm_lock *lock = ldlm_handle2lock(h);
2571 struct ptlrpc_request *req = mdt_info_req(info);
2574 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2576 /* there is no request if mdt_object_unlock() is called
2577 * from mdt_export_cleanup()->mdt_add_dirty_flag() */
2578 if (likely(req != NULL)) {
2579 CDEBUG(D_HA, "request = %p reply state = %p"
2580 " transno = "LPD64"\n", req,
2581 req->rq_reply_state, req->rq_transno);
2582 if (mdt_cos_is_enabled(mdt)) {
2584 ldlm_lock_downgrade(lock, LCK_COS);
2587 ptlrpc_save_lock(req, h, mode, no_ack);
2589 ldlm_lock_decref(h, mode);
2591 if (mdt_is_lock_sync(lock)) {
2592 CDEBUG(D_HA, "found sync-lock,"
2593 " async commit started\n");
2594 mdt_device_commit_async(info->mti_env,
2597 LDLM_LOCK_PUT(lock);
2606 * Unlock mdt object.
2608 * Immeditely release the regular lock and the PDO lock or save the
2609 * lock in reqeuest and keep them referenced until client ACK or
2610 * transaction commit.
2612 * \param info thread info object
2613 * \param o mdt object
2614 * \param lh mdt lock handle referencing regular and PDO locks
2615 * \param decref force immediate lock releasing
2617 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2618 struct mdt_lock_handle *lh, int decref)
2622 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2623 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2625 if (lustre_handle_is_used(&lh->mlh_rreg_lh))
2626 ldlm_lock_decref(&lh->mlh_rreg_lh, lh->mlh_rreg_mode);
2631 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2632 const struct lu_fid *f,
2633 struct mdt_lock_handle *lh,
2636 struct mdt_object *o;
2638 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2642 rc = mdt_object_lock(info, o, lh, ibits,
2645 mdt_object_put(info->mti_env, o);
2652 void mdt_object_unlock_put(struct mdt_thread_info * info,
2653 struct mdt_object * o,
2654 struct mdt_lock_handle *lh,
2657 mdt_object_unlock(info, o, lh, decref);
2658 mdt_object_put(info->mti_env, o);
2662 * Generic code handling requests that have struct mdt_body passed in:
2664 * - extract mdt_body from request and save it in @info, if present;
2666 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2669 * - if HABEO_CORPUS flag is set for this request type check whether object
2670 * actually exists on storage (lu_object_exists()).
2673 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2675 const struct mdt_body *body;
2676 struct mdt_object *obj;
2677 const struct lu_env *env;
2678 struct req_capsule *pill;
2682 env = info->mti_env;
2683 pill = info->mti_pill;
2685 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2689 if (!(body->mbo_valid & OBD_MD_FLID))
2692 if (!fid_is_sane(&body->mbo_fid1)) {
2693 CERROR("Invalid fid: "DFID"\n", PFID(&body->mbo_fid1));
2698 * Do not get size or any capa fields before we check that request
2699 * contains capa actually. There are some requests which do not, for
2700 * instance MDS_IS_SUBDIR.
2702 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2703 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2704 mdt_set_capainfo(info, 0, &body->mbo_fid1,
2705 req_capsule_client_get(pill, &RMF_CAPA1));
2707 obj = mdt_object_find(env, info->mti_mdt, &body->mbo_fid1);
2709 if ((flags & HABEO_CORPUS) &&
2710 !mdt_object_exists(obj)) {
2711 mdt_object_put(env, obj);
2712 /* for capability renew ENOENT will be handled in
2714 if (body->mbo_valid & OBD_MD_FLOSSCAPA)
2719 info->mti_object = obj;
2728 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2730 struct req_capsule *pill = info->mti_pill;
2734 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2735 rc = mdt_body_unpack(info, flags);
2739 if (rc == 0 && (flags & HABEO_REFERO)) {
2741 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2742 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2744 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2745 req_capsule_set_size(pill, &RMF_LOGCOOKIES,
2748 rc = req_capsule_server_pack(pill);
2753 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2755 struct md_device *next = m->mdt_child;
2757 return next->md_ops->mdo_init_capa_ctxt(env, next,
2758 m->mdt_lut.lut_mds_capa,
2759 m->mdt_capa_timeout,
2764 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2766 lh->mlh_type = MDT_NUL_LOCK;
2767 lh->mlh_reg_lh.cookie = 0ull;
2768 lh->mlh_reg_mode = LCK_MINMODE;
2769 lh->mlh_pdo_lh.cookie = 0ull;
2770 lh->mlh_pdo_mode = LCK_MINMODE;
2771 lh->mlh_rreg_lh.cookie = 0ull;
2772 lh->mlh_rreg_mode = LCK_MINMODE;
2775 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2777 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2778 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2782 * Initialize fields of struct mdt_thread_info. Other fields are left in
2783 * uninitialized state, because it's too expensive to zero out whole
2784 * mdt_thread_info (> 1K) on each request arrival.
2786 void mdt_thread_info_init(struct ptlrpc_request *req,
2787 struct mdt_thread_info *info)
2791 info->mti_pill = &req->rq_pill;
2794 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2795 mdt_lock_handle_init(&info->mti_lh[i]);
2797 /* mdt device: it can be NULL while CONNECT */
2798 if (req->rq_export) {
2799 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2800 info->mti_exp = req->rq_export;
2802 info->mti_mdt = NULL;
2803 info->mti_env = req->rq_svc_thread->t_env;
2804 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2806 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2807 info->mti_big_buf = LU_BUF_NULL;
2808 info->mti_body = NULL;
2809 info->mti_object = NULL;
2810 info->mti_dlm_req = NULL;
2811 info->mti_has_trans = 0;
2812 info->mti_cross_ref = 0;
2813 info->mti_opdata = 0;
2814 info->mti_big_lmm_used = 0;
2816 info->mti_spec.no_create = 0;
2817 info->mti_spec.sp_rm_entry = 0;
2819 info->mti_spec.u.sp_ea.eadata = NULL;
2820 info->mti_spec.u.sp_ea.eadatalen = 0;
2823 void mdt_thread_info_fini(struct mdt_thread_info *info)
2827 if (info->mti_object != NULL) {
2828 mdt_object_put(info->mti_env, info->mti_object);
2829 info->mti_object = NULL;
2832 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2833 mdt_lock_handle_fini(&info->mti_lh[i]);
2834 info->mti_env = NULL;
2835 info->mti_pill = NULL;
2836 info->mti_exp = NULL;
2838 if (unlikely(info->mti_big_buf.lb_buf != NULL))
2839 lu_buf_free(&info->mti_big_buf);
2842 struct mdt_thread_info *tsi2mdt_info(struct tgt_session_info *tsi)
2844 struct mdt_thread_info *mti;
2845 struct lustre_capa *lc;
2847 mti = mdt_th_info(tsi->tsi_env);
2848 LASSERT(mti != NULL);
2850 mdt_thread_info_init(tgt_ses_req(tsi), mti);
2851 if (tsi->tsi_corpus != NULL) {
2852 struct req_capsule *pill = tsi->tsi_pill;
2854 mti->mti_object = mdt_obj(tsi->tsi_corpus);
2855 lu_object_get(tsi->tsi_corpus);
2858 * XXX: must be part of tgt_mdt_body_unpack but moved here
2859 * due to mdt_set_capainfo().
2861 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2862 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT) > 0) {
2863 lc = req_capsule_client_get(pill, &RMF_CAPA1);
2864 mdt_set_capainfo(mti, 0, &tsi->tsi_mdt_body->mbo_fid1,
2868 mti->mti_body = tsi->tsi_mdt_body;
2869 mti->mti_dlm_req = tsi->tsi_dlm_req;
2874 static int mdt_tgt_connect(struct tgt_session_info *tsi)
2876 struct ptlrpc_request *req = tgt_ses_req(tsi);
2881 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_DELAY_CONDITIONAL) &&
2883 tsi2mdt_info(tsi)->mti_mdt->mdt_seq_site.ss_node_id)
2884 schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE, HZ * 3);
2886 rc = tgt_connect(tsi);
2890 rc = mdt_init_idmap(tsi);
2895 obd_disconnect(class_export_get(req->rq_export));
2914 static int mdt_intent_getattr(enum mdt_it_code opcode,
2915 struct mdt_thread_info *info,
2916 struct ldlm_lock **,
2919 static int mdt_intent_getxattr(enum mdt_it_code opcode,
2920 struct mdt_thread_info *info,
2921 struct ldlm_lock **lockp,
2924 static int mdt_intent_layout(enum mdt_it_code opcode,
2925 struct mdt_thread_info *info,
2926 struct ldlm_lock **,
2928 static int mdt_intent_reint(enum mdt_it_code opcode,
2929 struct mdt_thread_info *info,
2930 struct ldlm_lock **,
2933 static struct mdt_it_flavor {
2934 const struct req_format *it_fmt;
2936 int (*it_act)(enum mdt_it_code ,
2937 struct mdt_thread_info *,
2938 struct ldlm_lock **,
2941 } mdt_it_flavor[] = {
2943 .it_fmt = &RQF_LDLM_INTENT,
2944 /*.it_flags = HABEO_REFERO,*/
2946 .it_act = mdt_intent_reint,
2947 .it_reint = REINT_OPEN
2950 .it_fmt = &RQF_LDLM_INTENT,
2952 * OCREAT is not a MUTABOR request as if the file
2954 * We do the extra check of OBD_CONNECT_RDONLY in
2955 * mdt_reint_open() when we really need to create
2959 .it_act = mdt_intent_reint,
2960 .it_reint = REINT_OPEN
2963 .it_fmt = &RQF_LDLM_INTENT,
2964 .it_flags = MUTABOR,
2965 .it_act = mdt_intent_reint,
2966 .it_reint = REINT_CREATE
2968 [MDT_IT_GETATTR] = {
2969 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2970 .it_flags = HABEO_REFERO,
2971 .it_act = mdt_intent_getattr
2973 [MDT_IT_READDIR] = {
2979 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2980 .it_flags = HABEO_REFERO,
2981 .it_act = mdt_intent_getattr
2984 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2985 .it_flags = MUTABOR,
2987 .it_reint = REINT_UNLINK
2991 .it_flags = MUTABOR,
2994 [MDT_IT_GETXATTR] = {
2995 .it_fmt = &RQF_LDLM_INTENT_GETXATTR,
2996 .it_flags = HABEO_CORPUS,
2997 .it_act = mdt_intent_getxattr
3000 .it_fmt = &RQF_LDLM_INTENT_LAYOUT,
3002 .it_act = mdt_intent_layout
3007 mdt_intent_lock_replace(struct mdt_thread_info *info,
3008 struct ldlm_lock **lockp,
3009 struct mdt_lock_handle *lh,
3012 struct ptlrpc_request *req = mdt_info_req(info);
3013 struct ldlm_lock *lock = *lockp;
3014 struct ldlm_lock *new_lock;
3016 /* If possible resent found a lock, @lh is set to its handle */
3017 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3019 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3020 lh->mlh_reg_lh.cookie = 0;
3024 LASSERTF(new_lock != NULL,
3025 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3028 * If we've already given this lock to a client once, then we should
3029 * have no readers or writers. Otherwise, we should have one reader
3030 * _or_ writer ref (which will be zeroed below) before returning the
3033 if (new_lock->l_export == req->rq_export) {
3034 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3036 LASSERT(new_lock->l_export == NULL);
3037 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3042 if (new_lock->l_export == req->rq_export) {
3044 * Already gave this to the client, which means that we
3045 * reconstructed a reply.
3047 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3050 LDLM_LOCK_RELEASE(new_lock);
3051 lh->mlh_reg_lh.cookie = 0;
3052 RETURN(ELDLM_LOCK_REPLACED);
3056 * Fixup the lock to be given to the client.
3058 lock_res_and_lock(new_lock);
3059 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3060 * possible blocking AST. */
3061 while (new_lock->l_readers > 0) {
3062 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3063 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3064 new_lock->l_readers--;
3066 while (new_lock->l_writers > 0) {
3067 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3068 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3069 new_lock->l_writers--;
3072 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3073 new_lock->l_blocking_ast = lock->l_blocking_ast;
3074 new_lock->l_completion_ast = lock->l_completion_ast;
3075 new_lock->l_remote_handle = lock->l_remote_handle;
3076 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3078 unlock_res_and_lock(new_lock);
3080 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3081 &new_lock->l_remote_handle,
3082 &new_lock->l_exp_hash);
3084 LDLM_LOCK_RELEASE(new_lock);
3085 lh->mlh_reg_lh.cookie = 0;
3087 RETURN(ELDLM_LOCK_REPLACED);
3090 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3091 struct ldlm_lock *new_lock,
3092 struct mdt_lock_handle *lh,
3095 struct ptlrpc_request *req = mdt_info_req(info);
3096 struct ldlm_request *dlmreq;
3098 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3101 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3103 /* Check if this is a resend case (MSG_RESENT is set on RPC) and a
3104 * lock was found by ldlm_handle_enqueue(); if so @lh must be
3106 if (flags & LDLM_FL_RESENT) {
3107 lh->mlh_reg_lh.cookie = new_lock->l_handle.h_cookie;
3108 lh->mlh_reg_mode = new_lock->l_granted_mode;
3110 LDLM_DEBUG(new_lock, "Restoring lock cookie");
3111 DEBUG_REQ(D_DLMTRACE, req, "restoring lock cookie "LPX64,
3112 lh->mlh_reg_lh.cookie);
3117 * If the xid matches, then we know this is a resent request, and allow
3118 * it. (It's probably an OPEN, for which we don't send a lock.
3120 if (req_xid_is_last(req))
3124 * This remote handle isn't enqueued, so we never received or processed
3125 * this request. Clear MSG_RESENT, because it can be handled like any
3126 * normal request now.
3128 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3130 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3131 dlmreq->lock_handle[0].cookie);
3134 static int mdt_intent_getxattr(enum mdt_it_code opcode,
3135 struct mdt_thread_info *info,
3136 struct ldlm_lock **lockp,
3139 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3140 struct ldlm_reply *ldlm_rep = NULL;
3144 * Initialize lhc->mlh_reg_lh either from a previously granted lock
3145 * (for the resend case) or a new lock. Below we will use it to
3146 * replace the original lock.
3148 mdt_intent_fixup_resent(info, *lockp, lhc, flags);
3149 if (!lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3150 mdt_lock_reg_init(lhc, (*lockp)->l_req_mode);
3151 rc = mdt_object_lock(info, info->mti_object, lhc,
3152 MDS_INODELOCK_XATTR,
3158 grc = mdt_getxattr(info);
3160 rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
3162 if (mdt_info_req(info)->rq_repmsg != NULL)
3163 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3164 if (ldlm_rep == NULL)
3165 RETURN(err_serious(-EFAULT));
3167 ldlm_rep->lock_policy_res2 = grc;
3172 static int mdt_intent_getattr(enum mdt_it_code opcode,
3173 struct mdt_thread_info *info,
3174 struct ldlm_lock **lockp,
3177 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3179 struct ldlm_reply *ldlm_rep;
3180 struct mdt_body *reqbody;
3181 struct mdt_body *repbody;
3185 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3188 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3191 info->mti_cross_ref = !!(reqbody->mbo_valid & OBD_MD_FLCROSSREF);
3192 repbody->mbo_eadatasize = 0;
3193 repbody->mbo_aclsize = 0;
3197 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
3199 case MDT_IT_GETATTR:
3200 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
3204 CERROR("Unsupported intent (%d)\n", opcode);
3205 GOTO(out_shrink, rc = -EINVAL);
3208 rc = mdt_init_ucred(info, reqbody);
3210 GOTO(out_shrink, rc);
3212 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3213 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3215 /* Get lock from request for possible resent case. */
3216 mdt_intent_fixup_resent(info, *lockp, lhc, flags);
3218 rc = mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3219 ldlm_rep->lock_policy_res2 = clear_serious(rc);
3221 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3222 ldlm_rep->lock_policy_res2 = 0;
3223 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3224 ldlm_rep->lock_policy_res2) {
3225 lhc->mlh_reg_lh.cookie = 0ull;
3226 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3229 rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
3232 mdt_exit_ucred(info);
3234 mdt_client_compatibility(info);
3235 rc2 = mdt_fix_reply(info);
3241 static int mdt_intent_layout(enum mdt_it_code opcode,
3242 struct mdt_thread_info *info,
3243 struct ldlm_lock **lockp,
3246 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_LAYOUT];
3247 struct layout_intent *layout;
3249 struct mdt_object *obj = NULL;
3253 if (opcode != MDT_IT_LAYOUT) {
3254 CERROR("%s: Unknown intent (%d)\n", mdt_obd_name(info->mti_mdt),
3259 fid = &info->mti_tmp_fid2;
3260 fid_extract_from_res_name(fid, &(*lockp)->l_resource->lr_name);
3262 /* Get lock from request for possible resent case. */
3263 mdt_intent_fixup_resent(info, *lockp, lhc, flags);
3265 obj = mdt_object_find(info->mti_env, info->mti_mdt, fid);
3267 RETURN(PTR_ERR(obj));
3269 if (mdt_object_exists(obj) && !mdt_object_remote(obj)) {
3270 /* get the length of lsm */
3271 rc = mdt_attr_get_eabuf_size(info, obj);
3273 mdt_object_put(info->mti_env, obj);
3277 if (rc > info->mti_mdt->mdt_max_mdsize)
3278 info->mti_mdt->mdt_max_mdsize = rc;
3281 mdt_object_put(info->mti_env, obj);
3283 (*lockp)->l_lvb_type = LVB_T_LAYOUT;
3284 req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER, rc);
3285 rc = req_capsule_server_pack(info->mti_pill);
3289 if (lustre_handle_is_used(&lhc->mlh_reg_lh))
3290 rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
3292 layout = req_capsule_client_get(info->mti_pill, &RMF_LAYOUT_INTENT);
3293 LASSERT(layout != NULL);
3294 if (layout->li_opc == LAYOUT_INTENT_ACCESS)
3295 /* return to normal/resent ldlm handling */
3298 CERROR("%s: Unsupported layout intent (%d)\n",
3299 mdt_obd_name(info->mti_mdt), layout->li_opc);
3303 static int mdt_intent_reint(enum mdt_it_code opcode,
3304 struct mdt_thread_info *info,
3305 struct ldlm_lock **lockp,
3308 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3309 struct ldlm_reply *rep = NULL;
3313 static const struct req_format *intent_fmts[REINT_MAX] = {
3314 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3315 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3320 opc = mdt_reint_opcode(mdt_info_req(info), intent_fmts);
3324 if (mdt_it_flavor[opcode].it_reint != opc) {
3325 CERROR("Reint code %ld doesn't match intent: %d\n",
3327 RETURN(err_serious(-EPROTO));
3330 /* Get lock from request for possible resent case. */
3331 mdt_intent_fixup_resent(info, *lockp, lhc, flags);
3333 rc = mdt_reint_internal(info, lhc, opc);
3335 /* Check whether the reply has been packed successfully. */
3336 if (mdt_info_req(info)->rq_repmsg != NULL)
3337 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3339 RETURN(err_serious(-EFAULT));
3341 /* MDC expects this in any case */
3343 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3345 /* the open lock or the lock for cross-ref object should be
3346 * returned to the client */
3347 if (rc == -EREMOTE || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
3348 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3349 rep->lock_policy_res2 = 0;
3350 rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
3354 rep->lock_policy_res2 = clear_serious(rc);
3356 if (rep->lock_policy_res2 == -ENOENT &&
3357 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3358 rep->lock_policy_res2 = 0;
3360 if (rc == -ENOTCONN || rc == -ENODEV ||
3361 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3363 * If it is the disconnect error (ENODEV & ENOCONN), the error
3364 * will be returned by rq_status, and client at ptlrpc layer
3365 * will detect this, then disconnect, reconnect the import
3366 * immediately, instead of impacting the following the rpc.
3368 lhc->mlh_reg_lh.cookie = 0ull;
3372 * For other cases, the error will be returned by intent.
3373 * and client will retrieve the result from intent.
3376 * FIXME: when open lock is finished, that should be
3379 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3380 LASSERTF(rc == 0, "Error occurred but lock handle "
3381 "is still in use, rc = %d\n", rc);
3382 rep->lock_policy_res2 = 0;
3383 rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
3386 lhc->mlh_reg_lh.cookie = 0ull;
3387 RETURN(ELDLM_LOCK_ABORTED);
3392 static int mdt_intent_code(long itcode)
3400 case IT_OPEN|IT_CREAT:
3407 rc = MDT_IT_READDIR;
3410 rc = MDT_IT_GETATTR;
3422 rc = MDT_IT_GETXATTR;
3427 case IT_QUOTA_DQACQ:
3432 CERROR("Unknown intent opcode: %ld\n", itcode);
3439 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3440 struct ldlm_lock **lockp, __u64 flags)
3442 struct req_capsule *pill;
3443 struct mdt_it_flavor *flv;
3448 opc = mdt_intent_code(itopc);
3452 pill = info->mti_pill;
3454 if (opc == MDT_IT_QUOTA) {
3455 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
3458 RETURN(-EOPNOTSUPP);
3460 (*lockp)->l_lvb_type = LVB_T_LQUOTA;
3461 /* pass the request to quota master */
3462 rc = qmt_hdls.qmth_intent_policy(info->mti_env, qmt,
3463 mdt_info_req(info), lockp,
3468 flv = &mdt_it_flavor[opc];
3469 if (flv->it_fmt != NULL)
3470 req_capsule_extend(pill, flv->it_fmt);
3472 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3474 struct ptlrpc_request *req = mdt_info_req(info);
3475 if (flv->it_flags & MUTABOR &&
3476 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
3479 if (rc == 0 && flv->it_act != NULL) {
3480 struct ldlm_reply *rep;
3482 /* execute policy */
3483 rc = flv->it_act(opc, info, lockp, flags);
3485 /* Check whether the reply has been packed successfully. */
3486 if (mdt_info_req(info)->rq_repmsg != NULL) {
3487 rep = req_capsule_server_get(info->mti_pill,
3489 rep->lock_policy_res2 =
3490 ptlrpc_status_hton(rep->lock_policy_res2);
3498 static int mdt_intent_policy(struct ldlm_namespace *ns,
3499 struct ldlm_lock **lockp, void *req_cookie,
3500 ldlm_mode_t mode, __u64 flags, void *data)
3502 struct tgt_session_info *tsi;
3503 struct mdt_thread_info *info;
3504 struct ptlrpc_request *req = req_cookie;
3505 struct ldlm_intent *it;
3506 struct req_capsule *pill;
3511 LASSERT(req != NULL);
3513 tsi = tgt_ses_info(req->rq_svc_thread->t_env);
3515 info = tsi2mdt_info(tsi);
3516 LASSERT(info != NULL);
3517 pill = info->mti_pill;
3518 LASSERT(pill->rc_req == req);
3520 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3521 req_capsule_extend(pill, &RQF_LDLM_INTENT_BASIC);
3522 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3524 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3528 /* Lock without inodebits makes no sense and will oops
3529 * later in ldlm. Let's check it now to see if we have
3530 * ibits corrupted somewhere in mdt_intent_opc().
3531 * The case for client miss to set ibits has been
3532 * processed by others. */
3533 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3534 lr_type == LDLM_IBITS,
3535 info->mti_dlm_req->lock_desc.\
3536 l_policy_data.l_inodebits.bits != 0));
3538 rc = err_serious(-EFAULT);
3540 /* No intent was provided */
3541 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3542 req_capsule_set_size(pill, &RMF_DLM_LVB, RCL_SERVER, 0);
3543 rc = req_capsule_server_pack(pill);
3545 rc = err_serious(rc);
3547 mdt_thread_info_fini(info);
3551 static void mdt_deregister_seq_exp(struct mdt_device *mdt)
3553 struct seq_server_site *ss = mdt_seq_site(mdt);
3555 if (ss->ss_node_id == 0)
3558 if (ss->ss_client_seq != NULL) {
3559 lustre_deregister_lwp_item(&ss->ss_client_seq->lcs_exp);
3560 ss->ss_client_seq->lcs_exp = NULL;
3563 if (ss->ss_server_fld != NULL) {
3564 lustre_deregister_lwp_item(&ss->ss_server_fld->lsf_control_exp);
3565 ss->ss_server_fld->lsf_control_exp = NULL;
3569 static void mdt_seq_fini_cli(struct mdt_device *mdt)
3571 struct seq_server_site *ss = mdt_seq_site(mdt);
3576 if (ss->ss_server_seq != NULL)
3577 seq_server_set_cli(NULL, ss->ss_server_seq, NULL);
3580 static int mdt_seq_fini(const struct lu_env *env, struct mdt_device *mdt)
3582 mdt_seq_fini_cli(mdt);
3583 mdt_deregister_seq_exp(mdt);
3585 return seq_site_fini(env, mdt_seq_site(mdt));
3589 * It will retrieve its FLDB entries from MDT0, and it only happens
3590 * when upgrading existent FS to 2.6 or when local FLDB is corrupted,
3591 * and it needs to refresh FLDB from the MDT0.
3593 static int mdt_register_lwp_callback(void *data)
3596 struct mdt_device *mdt = data;
3597 struct lu_server_fld *fld = mdt_seq_site(mdt)->ss_server_fld;
3601 LASSERT(mdt_seq_site(mdt)->ss_node_id != 0);
3603 if (!likely(fld->lsf_new))
3606 rc = lu_env_init(&env, LCT_MD_THREAD);
3608 CERROR("%s: cannot init env: rc = %d\n", mdt_obd_name(mdt), rc);
3612 rc = fld_update_from_controller(&env, fld);
3614 CERROR("%s: cannot update controller: rc = %d\n",
3615 mdt_obd_name(mdt), rc);
3623 static int mdt_register_seq_exp(struct mdt_device *mdt)
3625 struct seq_server_site *ss = mdt_seq_site(mdt);
3626 char *lwp_name = NULL;
3629 if (ss->ss_node_id == 0)
3632 OBD_ALLOC(lwp_name, MAX_OBD_NAME);
3633 if (lwp_name == NULL)
3634 GOTO(out_free, rc = -ENOMEM);
3636 rc = tgt_name2lwp_name(mdt_obd_name(mdt), lwp_name, MAX_OBD_NAME, 0);
3640 rc = lustre_register_lwp_item(lwp_name, &ss->ss_client_seq->lcs_exp,
3645 rc = lustre_register_lwp_item(lwp_name,
3646 &ss->ss_server_fld->lsf_control_exp,
3647 mdt_register_lwp_callback, mdt);
3649 lustre_deregister_lwp_item(&ss->ss_client_seq->lcs_exp);
3650 ss->ss_client_seq->lcs_exp = NULL;
3654 if (lwp_name != NULL)
3655 OBD_FREE(lwp_name, MAX_OBD_NAME);
3661 * Init client sequence manager which is used by local MDS to talk to sequence
3662 * controller on remote node.
3664 static int mdt_seq_init_cli(const struct lu_env *env, struct mdt_device *mdt)
3666 struct seq_server_site *ss = mdt_seq_site(mdt);
3671 /* check if this is adding the first MDC and controller is not yet
3673 OBD_ALLOC_PTR(ss->ss_client_seq);
3674 if (ss->ss_client_seq == NULL)
3677 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3678 if (prefix == NULL) {
3679 OBD_FREE_PTR(ss->ss_client_seq);
3680 ss->ss_client_seq = NULL;
3684 /* Note: seq_client_fini will be called in seq_site_fini */
3685 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s", mdt_obd_name(mdt));
3686 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_METADATA,
3687 prefix, ss->ss_node_id == 0 ? ss->ss_control_seq :
3689 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3691 OBD_FREE_PTR(ss->ss_client_seq);
3692 ss->ss_client_seq = NULL;
3696 rc = seq_server_set_cli(env, ss->ss_server_seq, ss->ss_client_seq);
3701 static int mdt_seq_init(const struct lu_env *env, struct mdt_device *mdt)
3703 struct seq_server_site *ss;
3707 ss = mdt_seq_site(mdt);
3708 /* init sequence controller server(MDT0) */
3709 if (ss->ss_node_id == 0) {
3710 OBD_ALLOC_PTR(ss->ss_control_seq);
3711 if (ss->ss_control_seq == NULL)
3714 rc = seq_server_init(env, ss->ss_control_seq, mdt->mdt_bottom,
3715 mdt_obd_name(mdt), LUSTRE_SEQ_CONTROLLER,
3718 GOTO(out_seq_fini, rc);
3721 /* Init normal sequence server */
3722 OBD_ALLOC_PTR(ss->ss_server_seq);
3723 if (ss->ss_server_seq == NULL)
3724 GOTO(out_seq_fini, rc = -ENOMEM);
3726 rc = seq_server_init(env, ss->ss_server_seq, mdt->mdt_bottom,
3727 mdt_obd_name(mdt), LUSTRE_SEQ_SERVER, ss);
3729 GOTO(out_seq_fini, rc);
3731 /* init seq client for seq server to talk to seq controller(MDT0) */
3732 rc = mdt_seq_init_cli(env, mdt);
3734 GOTO(out_seq_fini, rc);
3736 if (ss->ss_node_id != 0)
3737 /* register controler export through lwp */
3738 rc = mdt_register_seq_exp(mdt);
3743 mdt_seq_fini(env, mdt);
3751 static int mdt_fld_fini(const struct lu_env *env,
3752 struct mdt_device *m)
3754 struct seq_server_site *ss = mdt_seq_site(m);
3757 if (ss && ss->ss_server_fld) {
3758 fld_server_fini(env, ss->ss_server_fld);
3759 OBD_FREE_PTR(ss->ss_server_fld);
3760 ss->ss_server_fld = NULL;
3766 static int mdt_fld_init(const struct lu_env *env,
3768 struct mdt_device *m)
3770 struct seq_server_site *ss;
3774 ss = mdt_seq_site(m);
3776 OBD_ALLOC_PTR(ss->ss_server_fld);
3777 if (ss->ss_server_fld == NULL)
3778 RETURN(rc = -ENOMEM);
3780 rc = fld_server_init(env, ss->ss_server_fld, m->mdt_bottom, uuid,
3783 OBD_FREE_PTR(ss->ss_server_fld);
3784 ss->ss_server_fld = NULL;
3791 static void mdt_stack_pre_fini(const struct lu_env *env,
3792 struct mdt_device *m, struct lu_device *top)
3794 struct lustre_cfg_bufs *bufs;
3795 struct lustre_cfg *lcfg;
3796 struct mdt_thread_info *info;
3801 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3802 LASSERT(info != NULL);
3804 bufs = &info->mti_u.bufs;
3806 LASSERT(m->mdt_child_exp);
3807 LASSERT(m->mdt_child_exp->exp_obd);
3809 /* process cleanup, pass mdt obd name to get obd umount flags */
3810 /* XXX: this is needed because all layers are referenced by
3811 * objects (some of them are pinned by osd, for example *
3812 * the proper solution should be a model where object used
3813 * by osd only doesn't have mdt/mdd slices -bzzz */
3814 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
3815 lustre_cfg_bufs_set_string(bufs, 1, NULL);
3816 lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
3818 CERROR("%s: cannot alloc lcfg\n", mdt_obd_name(m));
3821 top->ld_ops->ldo_process_config(env, top, lcfg);
3822 lustre_cfg_free(lcfg);
3826 static void mdt_stack_fini(const struct lu_env *env,
3827 struct mdt_device *m, struct lu_device *top)
3829 struct obd_device *obd = mdt2obd_dev(m);
3830 struct lustre_cfg_bufs *bufs;
3831 struct lustre_cfg *lcfg;
3832 struct mdt_thread_info *info;
3836 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3837 LASSERT(info != NULL);
3839 lu_dev_del_linkage(top->ld_site, top);
3841 lu_site_purge(env, top->ld_site, -1);
3843 bufs = &info->mti_u.bufs;
3844 /* process cleanup, pass mdt obd name to get obd umount flags */
3845 /* another purpose is to let all layers to release their objects */
3846 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
3851 lustre_cfg_bufs_set_string(bufs, 1, flags);
3852 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3854 CERROR("Cannot alloc lcfg!\n");
3858 top->ld_ops->ldo_process_config(env, top, lcfg);
3859 lustre_cfg_free(lcfg);
3861 lu_site_purge(env, top->ld_site, -1);
3863 m->mdt_child = NULL;
3864 m->mdt_bottom = NULL;
3866 obd_disconnect(m->mdt_child_exp);
3867 m->mdt_child_exp = NULL;
3869 obd_disconnect(m->mdt_bottom_exp);
3870 m->mdt_child_exp = NULL;
3873 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
3874 const char *next, struct obd_export **exp)
3876 struct obd_connect_data *data = NULL;
3877 struct obd_device *obd;
3881 OBD_ALLOC_PTR(data);
3883 GOTO(out, rc = -ENOMEM);
3885 obd = class_name2obd(next);
3887 CERROR("%s: can't locate next device: %s\n",
3888 mdt_obd_name(m), next);
3889 GOTO(out, rc = -ENOTCONN);
3892 data->ocd_connect_flags = OBD_CONNECT_VERSION;
3893 data->ocd_version = LUSTRE_VERSION_CODE;
3895 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
3897 CERROR("%s: cannot connect to next dev %s (%d)\n",
3898 mdt_obd_name(m), next, rc);
3908 static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
3909 struct lustre_cfg *cfg)
3911 char *dev = lustre_cfg_string(cfg, 0);
3912 int rc, name_size, uuid_size;
3913 char *name, *uuid, *p;
3914 struct lustre_cfg_bufs *bufs;
3915 struct lustre_cfg *lcfg;
3916 struct obd_device *obd;
3917 struct lustre_profile *lprof;
3918 struct lu_site *site;
3921 /* in 1.8 we had the only device in the stack - MDS.
3922 * 2.0 introduces MDT, MDD, OSD; MDT starts others internally.
3923 * in 2.3 OSD is instantiated by obd_mount.c, so we need
3924 * to generate names and setup MDT, MDD. MDT will be using
3925 * generated name to connect to MDD. for MDD the next device
3926 * will be LOD with name taken from so called "profile" which
3927 * is generated by mount_option line
3929 * 1.8 MGS generates config. commands like this:
3930 * #06 (104)mount_option 0: 1:lustre-MDT0000 2:lustre-mdtlov
3931 * #08 (120)setup 0:lustre-MDT0000 1:dev 2:type 3:lustre-MDT0000
3932 * 2.0 MGS generates config. commands like this:
3933 * #07 (112)mount_option 0: 1:lustre-MDT0000 2:lustre-MDT0000-mdtlov
3934 * #08 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
3935 * 3:lustre-MDT0000-mdtlov 4:f
3937 * we generate MDD name from MDT one, just replacing T with D
3939 * after all the preparations, the logical equivalent will be
3940 * #01 (160)setup 0:lustre-MDD0000 1:lustre-MDD0000_UUID 2:0
3941 * 3:lustre-MDT0000-mdtlov 4:f
3942 * #02 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
3943 * 3:lustre-MDD0000 4:f
3945 * notice we build the stack from down to top: MDD first, then MDT */
3947 name_size = MAX_OBD_NAME;
3948 uuid_size = MAX_OBD_NAME;
3950 OBD_ALLOC(name, name_size);
3951 OBD_ALLOC(uuid, uuid_size);
3952 if (name == NULL || uuid == NULL)
3953 GOTO(cleanup_mem, rc = -ENOMEM);
3955 OBD_ALLOC_PTR(bufs);
3957 GOTO(cleanup_mem, rc = -ENOMEM);
3960 p = strstr(name, "-MDT");
3962 GOTO(free_bufs, rc = -ENOMEM);
3965 snprintf(uuid, MAX_OBD_NAME, "%s_UUID", name);
3967 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
3968 if (lprof == NULL || lprof->lp_dt == NULL) {
3969 CERROR("can't find the profile: %s\n",
3970 lustre_cfg_string(cfg, 0));
3971 GOTO(free_bufs, rc = -EINVAL);
3974 lustre_cfg_bufs_reset(bufs, name);
3975 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_MDD_NAME);
3976 lustre_cfg_bufs_set_string(bufs, 2, uuid);
3977 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
3979 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
3981 GOTO(free_bufs, rc = -ENOMEM);
3983 rc = class_attach(lcfg);
3985 GOTO(lcfg_cleanup, rc);
3987 obd = class_name2obd(name);
3989 CERROR("Can not find obd %s (%s in config)\n",
3990 MDD_OBD_NAME, lustre_cfg_string(cfg, 0));
3991 GOTO(class_detach, rc = -EINVAL);
3994 lustre_cfg_free(lcfg);
3996 lustre_cfg_bufs_reset(bufs, name);
3997 lustre_cfg_bufs_set_string(bufs, 1, uuid);
3998 lustre_cfg_bufs_set_string(bufs, 2, dev);
3999 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4001 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4003 rc = class_setup(obd, lcfg);
4005 GOTO(class_detach, rc);
4007 /* connect to MDD we just setup */
4008 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_child_exp);
4010 GOTO(class_detach, rc);
4012 site = mdt->mdt_child_exp->exp_obd->obd_lu_dev->ld_site;
4014 LASSERT(mdt_lu_site(mdt) == NULL);
4015 mdt->mdt_lu_dev.ld_site = site;
4016 site->ls_top_dev = &mdt->mdt_lu_dev;
4017 mdt->mdt_child = lu2md_dev(mdt->mdt_child_exp->exp_obd->obd_lu_dev);
4019 /* now connect to bottom OSD */
4020 snprintf(name, MAX_OBD_NAME, "%s-osd", dev);
4021 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_bottom_exp);
4023 GOTO(class_detach, rc);
4025 lu2dt_dev(mdt->mdt_bottom_exp->exp_obd->obd_lu_dev);
4027 rc = lu_env_refill((struct lu_env *)env);
4029 CERROR("Failure to refill session: '%d'\n", rc);
4031 lu_dev_add_linkage(site, &mdt->mdt_lu_dev);
4036 class_detach(obd, lcfg);
4038 lustre_cfg_free(lcfg);
4043 OBD_FREE(name, name_size);
4045 OBD_FREE(uuid, uuid_size);
4049 /* setup quota master target on MDT0 */
4050 static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
4051 struct lustre_cfg *cfg)
4053 struct obd_device *obd;
4054 char *dev = lustre_cfg_string(cfg, 0);
4055 char *qmtname, *uuid, *p;
4056 struct lustre_cfg_bufs *bufs;
4057 struct lustre_cfg *lcfg;
4058 struct lustre_profile *lprof;
4059 struct obd_connect_data *data;
4063 LASSERT(mdt->mdt_qmt_exp == NULL);
4064 LASSERT(mdt->mdt_qmt_dev == NULL);
4066 /* quota master is on MDT0 only for now */
4067 if (mdt->mdt_seq_site.ss_node_id != 0)
4070 /* MGS generates config commands which look as follows:
4071 * #01 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4072 * 3:lustre-MDT0000-mdtlov 4:f
4074 * We generate the QMT name from the MDT one, just replacing MD with QM
4075 * after all the preparations, the logical equivalent will be:
4076 * #01 (160)setup 0:lustre-QMT0000 1:lustre-QMT0000_UUID 2:0
4077 * 3:lustre-MDT0000-osd 4:f */
4078 OBD_ALLOC(qmtname, MAX_OBD_NAME);
4079 OBD_ALLOC(uuid, UUID_MAX);
4080 OBD_ALLOC_PTR(bufs);
4081 OBD_ALLOC_PTR(data);
4082 if (qmtname == NULL || uuid == NULL || bufs == NULL || data == NULL)
4083 GOTO(cleanup_mem, rc = -ENOMEM);
4085 strcpy(qmtname, dev);
4086 p = strstr(qmtname, "-MDT");
4088 GOTO(cleanup_mem, rc = -ENOMEM);
4089 /* replace MD with QM */
4093 snprintf(uuid, UUID_MAX, "%s_UUID", qmtname);
4095 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4096 if (lprof == NULL || lprof->lp_dt == NULL) {
4097 CERROR("can't find profile for %s\n",
4098 lustre_cfg_string(cfg, 0));
4099 GOTO(cleanup_mem, rc = -EINVAL);
4102 lustre_cfg_bufs_reset(bufs, qmtname);
4103 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_QMT_NAME);
4104 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4105 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4107 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4109 GOTO(cleanup_mem, rc = -ENOMEM);
4111 rc = class_attach(lcfg);
4113 GOTO(lcfg_cleanup, rc);
4115 obd = class_name2obd(qmtname);
4117 CERROR("Can not find obd %s (%s in config)\n", qmtname,
4118 lustre_cfg_string(cfg, 0));
4119 GOTO(class_detach, rc = -EINVAL);
4122 lustre_cfg_free(lcfg);
4124 lustre_cfg_bufs_reset(bufs, qmtname);
4125 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4126 lustre_cfg_bufs_set_string(bufs, 2, dev);
4128 /* for quota, the next device should be the OSD device */
4129 lustre_cfg_bufs_set_string(bufs, 3,
4130 mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
4132 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4134 rc = class_setup(obd, lcfg);
4136 GOTO(class_detach, rc);
4138 mdt->mdt_qmt_dev = obd->obd_lu_dev;
4140 /* configure local quota objects */
4141 rc = mdt->mdt_qmt_dev->ld_ops->ldo_prepare(env,
4145 GOTO(class_cleanup, rc);
4147 /* connect to quota master target */
4148 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4149 data->ocd_version = LUSTRE_VERSION_CODE;
4150 rc = obd_connect(NULL, &mdt->mdt_qmt_exp, obd, &obd->obd_uuid,
4153 CERROR("cannot connect to quota master device %s (%d)\n",
4155 GOTO(class_cleanup, rc);
4161 class_manual_cleanup(obd);
4162 mdt->mdt_qmt_dev = NULL;
4166 class_detach(obd, lcfg);
4168 lustre_cfg_free(lcfg);
4173 OBD_FREE(qmtname, MAX_OBD_NAME);
4175 OBD_FREE(uuid, UUID_MAX);
4181 /* Shutdown quota master target associated with mdt */
4182 static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt)
4186 if (mdt->mdt_qmt_exp == NULL)
4188 LASSERT(mdt->mdt_qmt_dev != NULL);
4190 /* the qmt automatically shuts down when the mdt disconnects */
4191 obd_disconnect(mdt->mdt_qmt_exp);
4192 mdt->mdt_qmt_exp = NULL;
4193 mdt->mdt_qmt_dev = NULL;
4197 /* mdt_getxattr() is used from mdt_intent_getxattr(), use this wrapper
4198 * for now. This will be removed along with converting rest of MDT code
4199 * to use tgt_session_info */
4200 int mdt_tgt_getxattr(struct tgt_session_info *tsi)
4202 struct mdt_thread_info *info = tsi2mdt_info(tsi);
4205 rc = mdt_getxattr(info);
4207 mdt_thread_info_fini(info);
4211 static struct tgt_handler mdt_tgt_handlers[] = {
4212 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4213 0, MDS_CONNECT, mdt_tgt_connect,
4214 &RQF_CONNECT, LUSTRE_OBD_VERSION),
4215 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4216 0, MDS_DISCONNECT, tgt_disconnect,
4217 &RQF_MDS_DISCONNECT, LUSTRE_OBD_VERSION),
4218 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4219 HABEO_REFERO, MDS_SET_INFO, mdt_set_info,
4220 &RQF_OBD_SET_INFO, LUSTRE_MDS_VERSION),
4221 TGT_MDT_HDL(0, MDS_GET_INFO, mdt_get_info),
4222 TGT_MDT_HDL(0 | HABEO_REFERO, MDS_GETSTATUS, mdt_getstatus),
4223 TGT_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr),
4224 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME,
4226 TGT_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_tgt_getxattr),
4227 TGT_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs),
4228 TGT_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint),
4229 TGT_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
4230 TGT_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING,
4232 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_READPAGE, mdt_readpage),
4233 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_SYNC, mdt_sync),
4234 TGT_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl),
4235 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_PROGRESS,
4237 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_CT_REGISTER,
4238 mdt_hsm_ct_register),
4239 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_CT_UNREGISTER,
4240 mdt_hsm_ct_unregister),
4241 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_STATE_GET,
4243 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_STATE_SET,
4245 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_ACTION, mdt_hsm_action),
4246 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_REQUEST,
4248 TGT_MDT_HDL(HABEO_CLAVIS | HABEO_CORPUS | HABEO_REFERO | MUTABOR,
4253 static struct tgt_handler mdt_sec_ctx_ops[] = {
4254 TGT_SEC_HDL_VAR(0, SEC_CTX_INIT, mdt_sec_ctx_handle),
4255 TGT_SEC_HDL_VAR(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle),
4256 TGT_SEC_HDL_VAR(0, SEC_CTX_FINI, mdt_sec_ctx_handle)
4259 static struct tgt_handler mdt_quota_ops[] = {
4260 TGT_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq),
4263 static struct tgt_opc_slice mdt_common_slice[] = {
4265 .tos_opc_start = MDS_FIRST_OPC,
4266 .tos_opc_end = MDS_LAST_OPC,
4267 .tos_hs = mdt_tgt_handlers
4270 .tos_opc_start = OBD_FIRST_OPC,
4271 .tos_opc_end = OBD_LAST_OPC,
4272 .tos_hs = tgt_obd_handlers
4275 .tos_opc_start = LDLM_FIRST_OPC,
4276 .tos_opc_end = LDLM_LAST_OPC,
4277 .tos_hs = tgt_dlm_handlers
4280 .tos_opc_start = SEC_FIRST_OPC,
4281 .tos_opc_end = SEC_LAST_OPC,
4282 .tos_hs = mdt_sec_ctx_ops
4285 .tos_opc_start = OUT_UPDATE_FIRST_OPC,
4286 .tos_opc_end = OUT_UPDATE_LAST_OPC,
4287 .tos_hs = tgt_out_handlers
4290 .tos_opc_start = FLD_FIRST_OPC,
4291 .tos_opc_end = FLD_LAST_OPC,
4292 .tos_hs = fld_handlers
4295 .tos_opc_start = SEQ_FIRST_OPC,
4296 .tos_opc_end = SEQ_LAST_OPC,
4297 .tos_hs = seq_handlers
4300 .tos_opc_start = QUOTA_DQACQ,
4301 .tos_opc_end = QUOTA_LAST_OPC,
4302 .tos_hs = mdt_quota_ops
4305 .tos_opc_start = LLOG_FIRST_OPC,
4306 .tos_opc_end = LLOG_LAST_OPC,
4307 .tos_hs = tgt_llog_handlers
4310 .tos_opc_start = LFSCK_FIRST_OPC,
4311 .tos_opc_end = LFSCK_LAST_OPC,
4312 .tos_hs = tgt_lfsck_handlers
4320 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4322 struct md_device *next = m->mdt_child;
4323 struct lu_device *d = &m->mdt_lu_dev;
4324 struct obd_device *obd = mdt2obd_dev(m);
4325 struct lfsck_stop stop;
4328 stop.ls_status = LS_PAUSED;
4330 next->md_ops->mdo_iocontrol(env, next, OBD_IOC_STOP_LFSCK, 0, &stop);
4332 target_recovery_fini(obd);
4333 ping_evictor_stop();
4334 mdt_stack_pre_fini(env, m, md2lu_dev(m->mdt_child));
4336 if (m->mdt_opts.mo_coordinator)
4337 mdt_hsm_cdt_stop(m);
4339 mdt_hsm_cdt_fini(m);
4341 mdt_llog_ctxt_unclone(env, m, LLOG_AGENT_ORIG_CTXT);
4342 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4343 obd_exports_barrier(obd);
4344 obd_zombie_barrier();
4348 tgt_fini(env, &m->mdt_lut);
4349 mdt_fs_cleanup(env, m);
4350 upcall_cache_cleanup(m->mdt_identity_cache);
4351 m->mdt_identity_cache = NULL;
4353 if (m->mdt_namespace != NULL) {
4354 ldlm_namespace_free(m->mdt_namespace, NULL,
4355 d->ld_obd->obd_force);
4356 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4359 mdt_quota_fini(env, m);
4361 cfs_free_nidlist(&m->mdt_squash.rsi_nosquash_nids);
4363 mdt_seq_fini(env, m);
4364 mdt_fld_fini(env, m);
4366 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4367 cfs_timer_disarm(&m->mdt_ck_timer);
4368 mdt_ck_thread_stop(m);
4373 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4375 LASSERT(atomic_read(&d->ld_ref) == 0);
4377 server_put_mount(mdt_obd_name(m), true);
4382 static int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4384 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4385 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4387 struct mdt_thread_info *info;
4388 struct obd_device *obd;
4389 const char *dev = lustre_cfg_string(cfg, 0);
4390 const char *num = lustre_cfg_string(cfg, 2);
4391 struct lustre_mount_info *lmi = NULL;
4392 struct lustre_sb_info *lsi;
4394 struct seq_server_site *ss_site;
4395 const char *identity_upcall = "NONE";
4396 struct md_device *next;
4402 lu_device_init(&m->mdt_lu_dev, ldt);
4404 * Environment (env) might be missing mdt_thread_key values at that
4405 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4408 * Usually device allocation path doesn't use module key values, but
4409 * mdt has to do a lot of work here, so allocate key value.
4411 rc = lu_env_refill((struct lu_env *)env);
4415 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4416 LASSERT(info != NULL);
4418 obd = class_name2obd(dev);
4419 LASSERT(obd != NULL);
4421 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4423 m->mdt_som_conf = 0;
4425 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4427 /* default is coordinator off, it is started through conf_param
4429 m->mdt_opts.mo_coordinator = 0;
4431 lmi = server_get_mount(dev);
4433 CERROR("Cannot get mount info for %s!\n", dev);
4436 lsi = s2lsi(lmi->lmi_sb);
4437 /* CMD is supported only in IAM mode */
4439 node_id = simple_strtol(num, NULL, 10);
4440 obd->u.obt.obt_magic = OBT_MAGIC;
4443 spin_lock_init(&m->mdt_ioepoch_lock);
4444 m->mdt_capa_timeout = CAPA_TIMEOUT;
4445 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4446 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4447 m->mdt_squash.rsi_uid = 0;
4448 m->mdt_squash.rsi_gid = 0;
4449 INIT_LIST_HEAD(&m->mdt_squash.rsi_nosquash_nids);
4450 init_rwsem(&m->mdt_squash.rsi_sem);
4451 spin_lock_init(&m->mdt_osfs_lock);
4452 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4453 m->mdt_enable_remote_dir = 0;
4454 m->mdt_enable_remote_dir_gid = 0;
4456 m->mdt_lu_dev.ld_ops = &mdt_lu_ops;
4457 m->mdt_lu_dev.ld_obd = obd;
4458 /* Set this lu_device to obd for error handling purposes. */
4459 obd->obd_lu_dev = &m->mdt_lu_dev;
4461 /* init the stack */
4462 rc = mdt_stack_init((struct lu_env *)env, m, cfg);
4464 CERROR("%s: Can't init device stack, rc %d\n",
4465 mdt_obd_name(m), rc);
4470 ss_site = mdt_seq_site(m);
4471 s->ld_seq_site = ss_site;
4474 /* set server index */
4475 ss_site->ss_node_id = node_id;
4477 /* failover is the default
4478 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4479 * assumed whose ss_node_id == 0 XXX
4481 obd->obd_replayable = 1;
4482 /* No connection accepted until configurations will finish */
4483 obd->obd_no_conn = 1;
4485 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4486 char *str = lustre_cfg_string(cfg, 4);
4487 if (strchr(str, 'n')) {
4488 CWARN("%s: recovery disabled\n", mdt_obd_name(m));
4489 obd->obd_replayable = 0;
4493 rc = mdt_fld_init(env, mdt_obd_name(m), m);
4495 GOTO(err_fini_stack, rc);
4497 rc = mdt_seq_init(env, m);
4499 GOTO(err_fini_fld, rc);
4501 snprintf(info->mti_u.ns_name, sizeof(info->mti_u.ns_name), "%s-%s",
4502 LUSTRE_MDT_NAME, obd->obd_uuid.uuid);
4503 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4504 LDLM_NAMESPACE_SERVER,
4505 LDLM_NAMESPACE_GREEDY,
4507 if (m->mdt_namespace == NULL)
4508 GOTO(err_fini_seq, rc = -ENOMEM);
4510 m->mdt_namespace->ns_lvbp = m;
4511 m->mdt_namespace->ns_lvbo = &mdt_lvbo;
4513 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4514 /* set obd_namespace for compatibility with old code */
4515 obd->obd_namespace = m->mdt_namespace;
4517 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4519 rc = mdt_hsm_cdt_init(m);
4521 CERROR("%s: error initializing coordinator, rc %d\n",
4522 mdt_obd_name(m), rc);
4523 GOTO(err_free_ns, rc);
4526 rc = mdt_ck_thread_start(m);
4528 GOTO(err_free_hsm, rc);
4530 rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom, mdt_common_slice,
4531 OBD_FAIL_MDS_ALL_REQUEST_NET,
4532 OBD_FAIL_MDS_ALL_REPLY_NET);
4536 rc = mdt_fs_setup(env, m, obd, lsi);
4540 tgt_adapt_sptlrpc_conf(&m->mdt_lut, 1);
4542 next = m->mdt_child;
4543 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4546 GOTO(err_fs_cleanup, rc);
4548 if (mntopts & MNTOPT_USERXATTR)
4549 m->mdt_opts.mo_user_xattr = 1;
4551 m->mdt_opts.mo_user_xattr = 0;
4553 rc = next->md_ops->mdo_maxeasize_get(env, next, &m->mdt_max_ea_size);
4555 GOTO(err_fs_cleanup, rc);
4557 if (mntopts & MNTOPT_ACL)
4558 m->mdt_opts.mo_acl = 1;
4560 m->mdt_opts.mo_acl = 0;
4562 /* XXX: to support suppgid for ACL, we enable identity_upcall
4563 * by default, otherwise, maybe got unexpected -EACCESS. */
4564 if (m->mdt_opts.mo_acl)
4565 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4567 m->mdt_identity_cache = upcall_cache_init(mdt_obd_name(m),
4569 &mdt_identity_upcall_cache_ops);
4570 if (IS_ERR(m->mdt_identity_cache)) {
4571 rc = PTR_ERR(m->mdt_identity_cache);
4572 m->mdt_identity_cache = NULL;
4573 GOTO(err_fs_cleanup, rc);
4576 rc = mdt_procfs_init(m, dev);
4578 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4579 GOTO(err_recovery, rc);
4582 rc = mdt_quota_init(env, m, cfg);
4584 GOTO(err_procfs, rc);
4586 m->mdt_ldlm_client = &mdt2obd_dev(m)->obd_ldlm_client;
4587 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
4588 "mdt_ldlm_client", m->mdt_ldlm_client);
4590 ping_evictor_start();
4592 /* recovery will be started upon mdt_prepare()
4593 * when the whole stack is complete and ready
4594 * to serve the requests */
4596 mdt_init_capa_ctxt(env, m);
4598 /* Reduce the initial timeout on an MDS because it doesn't need such
4599 * a long timeout as an OST does. Adaptive timeouts will adjust this
4600 * value appropriately. */
4601 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4602 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4608 target_recovery_fini(obd);
4609 upcall_cache_cleanup(m->mdt_identity_cache);
4610 m->mdt_identity_cache = NULL;
4612 mdt_fs_cleanup(env, m);
4614 tgt_fini(env, &m->mdt_lut);
4616 cfs_timer_disarm(&m->mdt_ck_timer);
4617 mdt_ck_thread_stop(m);
4619 mdt_hsm_cdt_fini(m);
4621 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4622 obd->obd_namespace = m->mdt_namespace = NULL;
4624 mdt_seq_fini(env, m);
4626 mdt_fld_fini(env, m);
4628 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4631 server_put_mount(dev, true);
4635 /* For interoperability, the left element is old parameter, the right one
4636 * is the new version of the parameter, if some parameter is deprecated,
4637 * the new version should be set as NULL. */
4638 static struct cfg_interop_param mdt_interop_param[] = {
4639 { "mdt.group_upcall", NULL },
4640 { "mdt.quota_type", NULL },
4641 { "mdd.quota_type", NULL },
4642 { "mdt.rootsquash", "mdt.root_squash" },
4643 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
4647 /* used by MGS to process specific configurations */
4648 static int mdt_process_config(const struct lu_env *env,
4649 struct lu_device *d, struct lustre_cfg *cfg)
4651 struct mdt_device *m = mdt_dev(d);
4652 struct md_device *md_next = m->mdt_child;
4653 struct lu_device *next = md2lu_dev(md_next);
4657 switch (cfg->lcfg_command) {
4659 struct obd_device *obd = d->ld_obd;
4661 /* For interoperability */
4662 struct cfg_interop_param *ptr = NULL;
4663 struct lustre_cfg *old_cfg = NULL;
4666 param = lustre_cfg_string(cfg, 1);
4667 if (param == NULL) {
4668 CERROR("param is empty\n");
4673 ptr = class_find_old_param(param, mdt_interop_param);
4675 if (ptr->new_param == NULL) {
4677 CWARN("For interoperability, skip this %s."
4678 " It is obsolete.\n", ptr->old_param);
4682 CWARN("Found old param %s, changed it to %s.\n",
4683 ptr->old_param, ptr->new_param);
4686 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
4693 rc = class_process_proc_seq_param(PARAM_MDT, obd->obd_vars,
4695 if (rc > 0 || rc == -ENOSYS) {
4696 /* is it an HSM var ? */
4697 rc = class_process_proc_seq_param(PARAM_HSM,
4698 hsm_cdt_get_proc_vars(),
4700 if (rc > 0 || rc == -ENOSYS)
4701 /* we don't understand; pass it on */
4702 rc = next->ld_ops->ldo_process_config(env, next,
4706 if (old_cfg != NULL)
4707 lustre_cfg_free(cfg);
4712 /* others are passed further */
4713 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4719 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4720 const struct lu_object_header *hdr,
4721 struct lu_device *d)
4723 struct mdt_object *mo;
4727 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, GFP_NOFS);
4729 struct lu_object *o;
4730 struct lu_object_header *h;
4733 h = &mo->mot_header;
4734 lu_object_header_init(h);
4735 lu_object_init(o, h, d);
4736 lu_object_add_top(h, o);
4737 o->lo_ops = &mdt_obj_ops;
4738 mutex_init(&mo->mot_ioepoch_mutex);
4739 mutex_init(&mo->mot_lov_mutex);
4740 init_rwsem(&mo->mot_open_sem);
4746 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4747 const struct lu_object_conf *unused)
4749 struct mdt_device *d = mdt_dev(o->lo_dev);
4750 struct lu_device *under;
4751 struct lu_object *below;
4755 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4756 PFID(lu_object_fid(o)));
4758 under = &d->mdt_child->md_lu_dev;
4759 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4760 if (below != NULL) {
4761 lu_object_add(o, below);
4768 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4770 struct mdt_object *mo = mdt_obj(o);
4771 struct lu_object_header *h;
4775 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4776 PFID(lu_object_fid(o)));
4778 LASSERT(atomic_read(&mo->mot_open_count) == 0);
4779 LASSERT(atomic_read(&mo->mot_lease_count) == 0);
4782 lu_object_header_fini(h);
4783 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
4788 static int mdt_object_print(const struct lu_env *env, void *cookie,
4789 lu_printer_t p, const struct lu_object *o)
4791 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4792 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4793 "flags="LPX64", epochcount=%d, writecount=%d)",
4794 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4795 mdto->mot_ioepoch_count, mdto->mot_writecount);
4798 static int mdt_prepare(const struct lu_env *env,
4799 struct lu_device *pdev,
4800 struct lu_device *cdev)
4802 struct mdt_device *mdt = mdt_dev(cdev);
4803 struct lu_device *next = &mdt->mdt_child->md_lu_dev;
4804 struct obd_device *obd = cdev->ld_obd;
4811 rc = next->ld_ops->ldo_prepare(env, cdev, next);
4815 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_CHANGELOG_ORIG_CTXT);
4819 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_AGENT_ORIG_CTXT);
4823 rc = lfsck_register_namespace(env, mdt->mdt_bottom, mdt->mdt_namespace);
4824 /* The LFSCK instance is registered just now, so it must be there when
4825 * register the namespace to such instance. */
4826 LASSERTF(rc == 0, "register namespace failed: rc = %d\n", 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 (!(data->ocd_connect_flags & OBD_CONNECT_MDS_MDS) &&
4910 !(data->ocd_connect_flags & OBD_CONNECT_IBITS)) {
4911 CWARN("%s: client %s does not support ibits lock, either "
4912 "very old or an invalid client: flags "LPX64"\n",
4913 mdt_obd_name(mdt), exp->exp_client_uuid.uuid,
4914 data->ocd_connect_flags);
4918 if (!mdt->mdt_opts.mo_acl)
4919 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4921 if (!mdt->mdt_opts.mo_user_xattr)
4922 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4924 if (!mdt->mdt_som_conf)
4925 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4927 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4928 data->ocd_brw_size = min(data->ocd_brw_size,
4929 (__u32)MD_MAX_BRW_SIZE);
4930 if (data->ocd_brw_size == 0) {
4931 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4932 " ocd_version: %x ocd_grant: %d "
4933 "ocd_index: %u ocd_brw_size is "
4934 "unexpectedly zero, network data "
4935 "corruption? Refusing connection of this"
4938 exp->exp_client_uuid.uuid,
4939 exp, data->ocd_connect_flags, data->ocd_version,
4940 data->ocd_grant, data->ocd_index);
4945 /* NB: Disregard the rule against updating
4946 * exp_connect_data.ocd_connect_flags in this case, since
4947 * tgt_client_new() needs to know if this is a lightweight
4948 * connection, and it is safe to expose this flag before
4949 * connection processing completes. */
4950 if (data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) {
4951 spin_lock(&exp->exp_lock);
4952 *exp_connect_flags_ptr(exp) |= OBD_CONNECT_LIGHTWEIGHT;
4953 spin_unlock(&exp->exp_lock);
4956 data->ocd_version = LUSTRE_VERSION_CODE;
4958 if ((data->ocd_connect_flags & OBD_CONNECT_FID) == 0) {
4959 CWARN("%s: MDS requires FID support, but client not\n",
4964 if (mdt->mdt_som_conf &&
4965 !(data->ocd_connect_flags & (OBD_CONNECT_LIGHTWEIGHT |
4966 OBD_CONNECT_MDS_MDS |
4967 OBD_CONNECT_SOM))) {
4968 CWARN("%s: MDS has SOM enabled, but client does not support "
4969 "it\n", mdt_obd_name(mdt));
4973 if (OCD_HAS_FLAG(data, PINGLESS)) {
4974 if (ptlrpc_pinger_suppress_pings()) {
4975 spin_lock(&exp->exp_obd->obd_dev_lock);
4976 list_del_init(&exp->exp_obd_chain_timed);
4977 spin_unlock(&exp->exp_obd->obd_dev_lock);
4979 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
4983 data->ocd_max_easize = mdt->mdt_max_ea_size;
4988 /* mds_connect copy */
4989 static int mdt_obd_connect(const struct lu_env *env,
4990 struct obd_export **exp, struct obd_device *obd,
4991 struct obd_uuid *cluuid,
4992 struct obd_connect_data *data,
4995 struct obd_export *lexp;
4996 struct lustre_handle conn = { 0 };
4997 struct mdt_device *mdt;
5001 LASSERT(env != NULL);
5002 if (!exp || !obd || !cluuid)
5005 mdt = mdt_dev(obd->obd_lu_dev);
5008 * first, check whether the stack is ready to handle requests
5009 * XXX: probably not very appropriate method is used now
5010 * at some point we should find a better one
5012 if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) && data != NULL &&
5013 !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) {
5014 rc = obd_get_info(env, mdt->mdt_child_exp,
5015 sizeof(KEY_OSP_CONNECTED),
5016 KEY_OSP_CONNECTED, NULL, NULL, NULL);
5019 set_bit(MDT_FL_SYNCED, &mdt->mdt_state);
5022 rc = class_connect(&conn, obd, cluuid);
5026 lexp = class_conn2export(&conn);
5027 LASSERT(lexp != NULL);
5029 rc = mdt_connect_internal(lexp, mdt, data);
5031 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5034 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5035 rc = tgt_client_new(env, lexp);
5037 mdt_export_stats_init(obd, lexp, localdata);
5039 /* For phase I, sync for cross-ref operation. */
5040 lexp->exp_keep_sync = 1;
5044 class_disconnect(lexp);
5053 static int mdt_obd_reconnect(const struct lu_env *env,
5054 struct obd_export *exp, struct obd_device *obd,
5055 struct obd_uuid *cluuid,
5056 struct obd_connect_data *data,
5062 if (exp == NULL || obd == NULL || cluuid == NULL)
5065 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5067 mdt_export_stats_init(obd, exp, localdata);
5072 static int mdt_ctxt_add_dirty_flag(struct lu_env *env,
5073 struct mdt_thread_info *info,
5074 struct mdt_file_data *mfd)
5076 struct lu_context ses;
5080 rc = lu_context_init(&ses, LCT_SERVER_SESSION);
5085 lu_context_enter(&ses);
5087 mdt_ucred(info)->uc_valid = UCRED_OLD;
5088 rc = mdt_add_dirty_flag(info, mfd->mfd_object, &info->mti_attr);
5090 lu_context_exit(&ses);
5091 lu_context_fini(&ses);
5097 static int mdt_export_cleanup(struct obd_export *exp)
5099 struct mdt_export_data *med = &exp->exp_mdt_data;
5100 struct obd_device *obd = exp->exp_obd;
5101 struct mdt_device *mdt;
5102 struct mdt_thread_info *info;
5104 CFS_LIST_HEAD(closing_list);
5105 struct mdt_file_data *mfd, *n;
5109 spin_lock(&med->med_open_lock);
5110 while (!cfs_list_empty(&med->med_open_head)) {
5111 cfs_list_t *tmp = med->med_open_head.next;
5112 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5114 /* Remove mfd handle so it can't be found again.
5115 * We are consuming the mfd_list reference here. */
5116 class_handle_unhash(&mfd->mfd_handle);
5117 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5119 spin_unlock(&med->med_open_lock);
5120 mdt = mdt_dev(obd->obd_lu_dev);
5121 LASSERT(mdt != NULL);
5123 rc = lu_env_init(&env, LCT_MD_THREAD);
5127 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5128 LASSERT(info != NULL);
5129 memset(info, 0, sizeof *info);
5130 info->mti_env = &env;
5131 info->mti_mdt = mdt;
5132 info->mti_exp = exp;
5134 if (!cfs_list_empty(&closing_list)) {
5135 struct md_attr *ma = &info->mti_attr;
5137 /* Close any open files (which may also cause orphan unlinking). */
5138 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5139 cfs_list_del_init(&mfd->mfd_list);
5140 ma->ma_need = ma->ma_valid = 0;
5142 /* This file is being closed due to an eviction, it
5143 * could have been modified and now dirty regarding to
5144 * HSM archive, check this!
5145 * The logic here is to mark a file dirty if there's a
5146 * chance it was dirtied before the client was evicted,
5147 * so that we don't have to wait for a release attempt
5148 * before finding out the file was actually dirty and
5149 * fail the release. Aggressively marking it dirty here
5150 * will cause the policy engine to attempt to
5151 * re-archive it; when rearchiving, we can compare the
5152 * current version to the HSM data_version and make the
5153 * archive request into a noop if it's not actually
5156 if (mfd->mfd_mode & (FMODE_WRITE|MDS_FMODE_TRUNC))
5157 rc = mdt_ctxt_add_dirty_flag(&env, info, mfd);
5159 /* Don't unlink orphan on failover umount, LU-184 */
5160 if (exp->exp_flags & OBD_OPT_FAILOVER) {
5161 ma->ma_valid = MA_FLAGS;
5162 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5164 mdt_mfd_close(info, mfd);
5167 info->mti_mdt = NULL;
5168 /* cleanup client slot early */
5169 /* Do not erase record for recoverable client. */
5170 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5171 tgt_client_del(&env, exp);
5177 static int mdt_obd_disconnect(struct obd_export *exp)
5183 class_export_get(exp);
5185 rc = server_disconnect_export(exp);
5187 CDEBUG(D_IOCTL, "server disconnect error: rc = %d\n", rc);
5189 rc = mdt_export_cleanup(exp);
5190 class_export_put(exp);
5194 /* FIXME: Can we avoid using these two interfaces? */
5195 static int mdt_init_export(struct obd_export *exp)
5197 struct mdt_export_data *med = &exp->exp_mdt_data;
5201 CFS_INIT_LIST_HEAD(&med->med_open_head);
5202 spin_lock_init(&med->med_open_lock);
5203 mutex_init(&med->med_idmap_mutex);
5204 med->med_idmap = NULL;
5205 spin_lock(&exp->exp_lock);
5206 exp->exp_connecting = 1;
5207 spin_unlock(&exp->exp_lock);
5209 /* self-export doesn't need client data and ldlm initialization */
5210 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5211 &exp->exp_client_uuid)))
5214 rc = tgt_client_alloc(exp);
5218 rc = ldlm_init_export(exp);
5225 tgt_client_free(exp);
5227 CERROR("%s: Failed to initialize export: rc = %d\n",
5228 exp->exp_obd->obd_name, rc);
5232 static int mdt_destroy_export(struct obd_export *exp)
5236 if (exp_connect_rmtclient(exp))
5237 mdt_cleanup_idmap(&exp->exp_mdt_data);
5239 target_destroy_export(exp);
5240 /* destroy can be called from failed obd_setup, so
5241 * checking uuid is safer than obd_self_export */
5242 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5243 &exp->exp_client_uuid)))
5246 ldlm_destroy_export(exp);
5247 tgt_client_free(exp);
5249 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5250 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5255 /** The maximum depth that fid2path() will search.
5256 * This is limited only because we want to store the fids for
5257 * historical path lookup purposes.
5259 #define MAX_PATH_DEPTH 100
5261 /** mdt_path() lookup structure. */
5262 struct path_lookup_info {
5263 __u64 pli_recno; /**< history point */
5264 __u64 pli_currec; /**< current record */
5265 struct lu_fid pli_fid;
5266 struct lu_fid pli_fids[MAX_PATH_DEPTH]; /**< path, in fids */
5267 struct mdt_object *pli_mdt_obj;
5268 char *pli_path; /**< full path */
5270 int pli_linkno; /**< which hardlink to follow */
5271 int pli_fidcount; /**< number of \a pli_fids */
5274 int mdt_links_read(struct mdt_thread_info *info, struct mdt_object *mdt_obj,
5275 struct linkea_data *ldata)
5279 LASSERT(ldata->ld_buf->lb_buf != NULL);
5281 if (!mdt_object_exists(mdt_obj))
5284 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5285 ldata->ld_buf, XATTR_NAME_LINK);
5286 if (rc == -ERANGE) {
5287 /* Buf was too small, figure out what we need. */
5288 lu_buf_free(ldata->ld_buf);
5289 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5290 ldata->ld_buf, XATTR_NAME_LINK);
5293 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
5294 if (ldata->ld_buf->lb_buf == NULL)
5296 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5297 ldata->ld_buf, XATTR_NAME_LINK);
5302 return linkea_init(ldata);
5305 static int mdt_path_current(struct mdt_thread_info *info,
5306 struct path_lookup_info *pli)
5308 struct mdt_device *mdt = info->mti_mdt;
5309 struct mdt_object *mdt_obj;
5310 struct link_ea_header *leh;
5311 struct link_ea_entry *lee;
5312 struct lu_name *tmpname = &info->mti_name;
5313 struct lu_fid *tmpfid = &info->mti_tmp_fid1;
5314 struct lu_buf *buf = &info->mti_big_buf;
5317 struct linkea_data ldata = { 0 };
5321 /* temp buffer for path element, the buffer will be finally freed
5322 * in mdt_thread_info_fini */
5323 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
5324 if (buf->lb_buf == NULL)
5328 ptr = pli->pli_path + pli->pli_pathlen - 1;
5331 pli->pli_fidcount = 0;
5332 pli->pli_fids[0] = *(struct lu_fid *)mdt_object_fid(pli->pli_mdt_obj);
5333 *tmpfid = pli->pli_fids[0];
5334 /* root FID only exists on MDT0, and fid2path should also ends at MDT0,
5335 * so checking root_fid can only happen on MDT0. */
5336 while (!lu_fid_eq(&mdt->mdt_md_root_fid,
5337 &pli->pli_fids[pli->pli_fidcount])) {
5338 struct lu_buf lmv_buf;
5340 mdt_obj = mdt_object_find(info->mti_env, mdt, tmpfid);
5341 if (IS_ERR(mdt_obj))
5342 GOTO(out, rc = PTR_ERR(mdt_obj));
5344 if (!mdt_object_exists(mdt_obj)) {
5345 mdt_object_put(info->mti_env, mdt_obj);
5346 GOTO(out, rc = -ENOENT);
5349 if (mdt_object_remote(mdt_obj)) {
5350 mdt_object_put(info->mti_env, mdt_obj);
5351 GOTO(remote_out, rc = -EREMOTE);
5354 rc = mdt_links_read(info, mdt_obj, &ldata);
5356 mdt_object_put(info->mti_env, mdt_obj);
5361 lee = (struct link_ea_entry *)(leh + 1); /* link #0 */
5362 linkea_entry_unpack(lee, &reclen, tmpname, tmpfid);
5363 /* If set, use link #linkno for path lookup, otherwise use
5364 link #0. Only do this for the final path element. */
5365 if (pli->pli_fidcount == 0 &&
5366 pli->pli_linkno < leh->leh_reccount) {
5368 for (count = 0; count < pli->pli_linkno; count++) {
5369 lee = (struct link_ea_entry *)
5370 ((char *)lee + reclen);
5371 linkea_entry_unpack(lee, &reclen, tmpname,
5374 if (pli->pli_linkno < leh->leh_reccount - 1)
5375 /* indicate to user there are more links */
5379 lmv_buf.lb_buf = info->mti_xattr_buf;
5380 lmv_buf.lb_len = sizeof(info->mti_xattr_buf);
5381 /* Check if it is slave stripes */
5382 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5383 &lmv_buf, XATTR_NAME_LMV);
5384 mdt_object_put(info->mti_env, mdt_obj);
5386 union lmv_mds_md *lmm = lmv_buf.lb_buf;
5388 /* For slave stripes, get its master */
5389 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE) {
5390 pli->pli_fids[pli->pli_fidcount] = *tmpfid;
5393 } else if (rc < 0 && rc != -ENODATA) {
5399 /* Pack the name in the end of the buffer */
5400 ptr -= tmpname->ln_namelen;
5401 if (ptr - 1 <= pli->pli_path)
5402 GOTO(out, rc = -EOVERFLOW);
5403 strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
5406 /* Store the parent fid for historic lookup */
5407 if (++pli->pli_fidcount >= MAX_PATH_DEPTH)
5408 GOTO(out, rc = -EOVERFLOW);
5409 pli->pli_fids[pli->pli_fidcount] = *tmpfid;
5413 ptr++; /* skip leading / */
5414 memmove(pli->pli_path, ptr, pli->pli_path + pli->pli_pathlen - ptr);
5421 /* Returns the full path to this fid, as of changelog record recno. */
5422 static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
5423 char *path, int pathlen, __u64 *recno, int *linkno,
5426 struct mdt_device *mdt = info->mti_mdt;
5427 struct path_lookup_info *pli;
5435 if (lu_fid_eq(&mdt->mdt_md_root_fid, mdt_object_fid(obj))) {
5444 pli->pli_mdt_obj = obj;
5445 pli->pli_recno = *recno;
5446 pli->pli_path = path;
5447 pli->pli_pathlen = pathlen;
5448 pli->pli_linkno = *linkno;
5450 /* Retry multiple times in case file is being moved */
5451 while (tries-- && rc == -EAGAIN)
5452 rc = mdt_path_current(info, pli);
5454 /* return the last resolved fids to the client, so the client will
5455 * build the left path on another MDT for remote object */
5456 *fid = pli->pli_fids[pli->pli_fidcount];
5458 *recno = pli->pli_currec;
5459 /* Return next link index to caller */
5460 *linkno = pli->pli_linkno;
5467 static int mdt_fid2path(struct mdt_thread_info *info,
5468 struct getinfo_fid2path *fp)
5470 struct mdt_device *mdt = info->mti_mdt;
5471 struct mdt_object *obj;
5475 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5476 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5478 if (!fid_is_sane(&fp->gf_fid))
5481 if (!fid_is_namespace_visible(&fp->gf_fid)) {
5482 CWARN("%s: "DFID" is invalid, sequence should be "
5483 ">= "LPX64"\n", mdt_obd_name(mdt),
5484 PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
5488 obj = mdt_object_find(info->mti_env, mdt, &fp->gf_fid);
5489 if (obj == NULL || IS_ERR(obj)) {
5490 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5495 if (mdt_object_remote(obj))
5497 else if (!mdt_object_exists(obj))
5503 mdt_object_put(info->mti_env, obj);
5504 CDEBUG(D_IOCTL, "nonlocal object "DFID": rc = %d\n",
5505 PFID(&fp->gf_fid), rc);
5509 rc = mdt_path(info, obj, fp->gf_path, fp->gf_pathlen, &fp->gf_recno,
5510 &fp->gf_linkno, &fp->gf_fid);
5512 CDEBUG(D_INFO, "fid "DFID", path %s recno "LPX64" linkno %u\n",
5513 PFID(&fp->gf_fid), fp->gf_path, fp->gf_recno, fp->gf_linkno);
5515 mdt_object_put(info->mti_env, obj);
5520 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5521 void *val, int vallen)
5523 struct getinfo_fid2path *fpout, *fpin;
5526 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5529 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5530 lustre_swab_fid2path(fpin);
5532 memcpy(fpout, fpin, sizeof(*fpin));
5533 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5536 rc = mdt_fid2path(info, fpout);
5540 int mdt_get_info(struct tgt_session_info *tsi)
5550 key = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_KEY);
5552 CDEBUG(D_IOCTL, "No GETINFO key\n");
5553 RETURN(err_serious(-EFAULT));
5555 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_GETINFO_KEY,
5558 vallen = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_VALLEN);
5559 if (vallen == NULL) {
5560 CDEBUG(D_IOCTL, "%s: cannot get RMF_GETINFO_VALLEN buffer\n",
5561 tgt_name(tsi->tsi_tgt));
5562 RETURN(err_serious(-EFAULT));
5565 req_capsule_set_size(tsi->tsi_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5567 rc = req_capsule_server_pack(tsi->tsi_pill);
5569 RETURN(err_serious(rc));
5571 valout = req_capsule_server_get(tsi->tsi_pill, &RMF_GETINFO_VAL);
5572 if (valout == NULL) {
5573 CDEBUG(D_IOCTL, "%s: cannot get get-info RPC out buffer\n",
5574 tgt_name(tsi->tsi_tgt));
5575 RETURN(err_serious(-EFAULT));
5578 if (KEY_IS(KEY_FID2PATH)) {
5579 struct mdt_thread_info *info = tsi2mdt_info(tsi);
5581 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5582 mdt_thread_info_fini(info);
5589 /* Pass the ioc down */
5590 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5591 unsigned int cmd, int len, void *data)
5593 struct lu_context ioctl_session;
5594 struct md_device *next = mdt->mdt_child;
5598 rc = lu_context_init(&ioctl_session, LCT_SERVER_SESSION);
5601 ioctl_session.lc_thread = (struct ptlrpc_thread *)current;
5602 lu_context_enter(&ioctl_session);
5603 env->le_ses = &ioctl_session;
5605 LASSERT(next->md_ops->mdo_iocontrol);
5606 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5608 lu_context_exit(&ioctl_session);
5609 lu_context_fini(&ioctl_session);
5613 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5615 struct obd_ioctl_data *data = karg;
5618 struct mdt_object *obj;
5619 struct mdt_lock_handle *lh;
5623 if (data->ioc_inlbuf1 == NULL || data->ioc_inllen1 != sizeof(*fid) ||
5624 data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
5627 fid = (struct lu_fid *)data->ioc_inlbuf1;
5629 if (!fid_is_sane(fid))
5632 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5634 lh = &mti->mti_lh[MDT_LH_PARENT];
5635 mdt_lock_reg_init(lh, LCK_CR);
5637 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5639 RETURN(PTR_ERR(obj));
5641 if (mdt_object_remote(obj)) {
5644 * before calling version get the correct MDS should be
5645 * fid, this is error to find remote object here
5647 CERROR("nonlocal object "DFID"\n", PFID(fid));
5648 } else if (!mdt_object_exists(obj)) {
5649 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5652 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5653 *(__u64 *)data->ioc_inlbuf2 = version;
5656 mdt_object_unlock_put(mti, obj, lh, 1);
5660 /* ioctls on obd dev */
5661 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5662 void *karg, void *uarg)
5665 struct obd_device *obd = exp->exp_obd;
5666 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5667 struct dt_device *dt = mdt->mdt_bottom;
5671 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5672 rc = lu_env_init(&env, LCT_MD_THREAD);
5678 rc = mdt_device_sync(&env, mdt);
5680 case OBD_IOC_SET_READONLY:
5681 rc = dt->dd_ops->dt_ro(&env, dt);
5683 case OBD_IOC_ABORT_RECOVERY:
5684 CERROR("%s: Aborting recovery for device\n", mdt_obd_name(mdt));
5685 target_stop_recovery_thread(obd);
5688 case OBD_IOC_CHANGELOG_REG:
5689 case OBD_IOC_CHANGELOG_DEREG:
5690 case OBD_IOC_CHANGELOG_CLEAR:
5691 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5693 case OBD_IOC_START_LFSCK: {
5694 struct md_device *next = mdt->mdt_child;
5695 struct obd_ioctl_data *data = karg;
5696 struct lfsck_start_param lsp;
5698 if (unlikely(data == NULL)) {
5703 lsp.lsp_start = (struct lfsck_start *)(data->ioc_inlbuf1);
5704 lsp.lsp_index_valid = 0;
5705 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, &lsp);
5708 case OBD_IOC_STOP_LFSCK: {
5709 struct md_device *next = mdt->mdt_child;
5710 struct obd_ioctl_data *data = karg;
5711 struct lfsck_stop stop;
5713 stop.ls_status = LS_STOPPED;
5714 /* Old lfsck utils may pass NULL @stop. */
5715 if (data->ioc_inlbuf1 == NULL)
5719 ((struct lfsck_stop *)(data->ioc_inlbuf1))->ls_flags;
5721 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, &stop);
5724 case OBD_IOC_GET_OBJ_VERSION: {
5725 struct mdt_thread_info *mti;
5726 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5727 memset(mti, 0, sizeof *mti);
5728 mti->mti_env = &env;
5732 rc = mdt_ioc_version_get(mti, karg);
5735 case OBD_IOC_CATLOGLIST: {
5736 struct mdt_thread_info *mti;
5738 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5739 lu_local_obj_fid(&mti->mti_tmp_fid1, LLOG_CATALOGS_OID);
5740 rc = llog_catalog_list(&env, mdt->mdt_bottom, 0, karg,
5741 &mti->mti_tmp_fid1);
5746 CERROR("%s: Not supported cmd = %d, rc = %d\n",
5747 mdt_obd_name(mdt), cmd, rc);
5754 static int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5756 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5757 struct lfsck_start_param lsp;
5761 lsp.lsp_start = NULL;
5762 lsp.lsp_index_valid = 0;
5763 rc = mdt->mdt_child->md_ops->mdo_iocontrol(env, mdt->mdt_child,
5764 OBD_IOC_START_LFSCK,
5766 if (rc != 0 && rc != -EALREADY)
5767 CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
5768 mdt_obd_name(mdt), rc);
5770 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5774 static int mdt_obd_postrecov(struct obd_device *obd)
5779 rc = lu_env_init(&env, LCT_MD_THREAD);
5782 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5787 static struct obd_ops mdt_obd_device_ops = {
5788 .o_owner = THIS_MODULE,
5789 .o_set_info_async = mdt_obd_set_info_async,
5790 .o_connect = mdt_obd_connect,
5791 .o_reconnect = mdt_obd_reconnect,
5792 .o_disconnect = mdt_obd_disconnect,
5793 .o_init_export = mdt_init_export,
5794 .o_destroy_export = mdt_destroy_export,
5795 .o_iocontrol = mdt_iocontrol,
5796 .o_postrecov = mdt_obd_postrecov,
5799 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5800 struct lu_device *d)
5802 struct mdt_device *m = mdt_dev(d);
5809 static struct lu_device *mdt_device_free(const struct lu_env *env,
5810 struct lu_device *d)
5812 struct mdt_device *m = mdt_dev(d);
5815 lu_device_fini(&m->mdt_lu_dev);
5821 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5822 struct lu_device_type *t,
5823 struct lustre_cfg *cfg)
5825 struct lu_device *l;
5826 struct mdt_device *m;
5833 rc = mdt_init0(env, m, t, cfg);
5835 mdt_device_free(env, l);
5840 l = ERR_PTR(-ENOMEM);
5844 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5845 LU_KEY_INIT(mdt, struct mdt_thread_info);
5847 static void mdt_key_fini(const struct lu_context *ctx,
5848 struct lu_context_key *key, void* data)
5850 struct mdt_thread_info *info = data;
5852 if (info->mti_big_lmm) {
5853 OBD_FREE_LARGE(info->mti_big_lmm, info->mti_big_lmmsize);
5854 info->mti_big_lmm = NULL;
5855 info->mti_big_lmmsize = 0;
5860 /* context key: mdt_thread_key */
5861 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5863 struct lu_ucred *mdt_ucred(const struct mdt_thread_info *info)
5865 return lu_ucred(info->mti_env);
5868 struct lu_ucred *mdt_ucred_check(const struct mdt_thread_info *info)
5870 return lu_ucred_check(info->mti_env);
5874 * Enable/disable COS (Commit On Sharing).
5876 * Set/Clear the COS flag in mdt options.
5878 * \param mdt mdt device
5879 * \param val 0 disables COS, other values enable COS
5881 void mdt_enable_cos(struct mdt_device *mdt, int val)
5886 mdt->mdt_opts.mo_cos = !!val;
5887 rc = lu_env_init(&env, LCT_LOCAL);
5888 if (unlikely(rc != 0)) {
5889 CWARN("%s: lu_env initialization failed, cannot "
5890 "sync: rc = %d\n", mdt_obd_name(mdt), rc);
5893 mdt_device_sync(&env, mdt);
5898 * Check COS (Commit On Sharing) status.
5900 * Return COS flag status.
5902 * \param mdt mdt device
5904 int mdt_cos_is_enabled(struct mdt_device *mdt)
5906 return mdt->mdt_opts.mo_cos != 0;
5909 static struct lu_device_type_operations mdt_device_type_ops = {
5910 .ldto_device_alloc = mdt_device_alloc,
5911 .ldto_device_free = mdt_device_free,
5912 .ldto_device_fini = mdt_device_fini
5915 static struct lu_device_type mdt_device_type = {
5916 .ldt_tags = LU_DEVICE_MD,
5917 .ldt_name = LUSTRE_MDT_NAME,
5918 .ldt_ops = &mdt_device_type_ops,
5919 .ldt_ctx_tags = LCT_MD_THREAD
5922 static int __init mdt_mod_init(void)
5926 CLASSERT(sizeof("0x0123456789ABCDEF:0x01234567:0x01234567") ==
5927 FID_NOBRACE_LEN + 1);
5928 CLASSERT(sizeof("[0x0123456789ABCDEF:0x01234567:0x01234567]") ==
5930 rc = lu_kmem_init(mdt_caches);
5934 rc = mds_mod_init();
5938 rc = class_register_type(&mdt_obd_device_ops, NULL, true, NULL,
5939 #ifndef HAVE_ONLY_PROCFS_SEQ
5942 LUSTRE_MDT_NAME, &mdt_device_type);
5947 lu_kmem_fini(mdt_caches);
5954 static void __exit mdt_mod_exit(void)
5956 class_unregister_type(LUSTRE_MDT_NAME);
5958 lu_kmem_fini(mdt_caches);
5961 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
5962 MODULE_DESCRIPTION("Lustre Metadata Target ("LUSTRE_MDT_NAME")");
5963 MODULE_LICENSE("GPL");
5965 cfs_module(mdt, LUSTRE_VERSION_STRING, mdt_mod_init, mdt_mod_exit);