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) 2011, 2015, 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_open.c
38 * Lustre Metadata Target (mdt) open/close file handling
40 * Author: Huang Hua <huanghua@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_MDS
45 #include <lustre_acl.h>
46 #include <lustre_mds.h>
47 #include "mdt_internal.h"
48 #include <lustre_nodemap.h>
50 /* we do nothing because we do not have refcount now */
51 static void mdt_mfd_get(void *mfdp)
55 static struct portals_handle_ops mfd_handle_ops = {
56 .hop_addref = mdt_mfd_get,
60 /* Create a new mdt_file_data struct, initialize it,
61 * and insert it to global hash table */
62 struct mdt_file_data *mdt_mfd_new(const struct mdt_export_data *med)
64 struct mdt_file_data *mfd;
69 INIT_LIST_HEAD(&mfd->mfd_handle.h_link);
70 mfd->mfd_handle.h_owner = med;
71 INIT_LIST_HEAD(&mfd->mfd_list);
72 class_handle_hash(&mfd->mfd_handle, &mfd_handle_ops);
79 * Find the mfd pointed to by handle in global hash table.
80 * In case of replay the handle is obsoleted
81 * but mfd can be found in mfd list by that handle.
82 * Callers need to be holding med_open_lock.
84 struct mdt_file_data *mdt_handle2mfd(struct mdt_export_data *med,
85 const struct lustre_handle *handle,
86 bool is_replay_or_resent)
88 struct mdt_file_data *mfd;
91 LASSERT(handle != NULL);
92 mfd = class_handle2object(handle->cookie, med);
93 /* during dw/setattr replay the mfd can be found by old handle */
94 if (mfd == NULL && is_replay_or_resent) {
95 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
96 if (mfd->mfd_old_handle.cookie == handle->cookie)
106 void mdt_mfd_free(struct mdt_file_data *mfd)
108 LASSERT(list_empty(&mfd->mfd_list));
109 OBD_FREE_RCU(mfd, sizeof *mfd, &mfd->mfd_handle);
112 static int mdt_create_data(struct mdt_thread_info *info,
113 struct mdt_object *p, struct mdt_object *o)
115 struct md_op_spec *spec = &info->mti_spec;
116 struct md_attr *ma = &info->mti_attr;
120 if (!md_should_create(spec->sp_cr_flags))
123 ma->ma_need = MA_INODE | MA_LOV;
125 mutex_lock(&o->mot_lov_mutex);
126 if (!o->mot_lov_created) {
127 rc = mdo_create_data(info->mti_env,
128 p ? mdt_object_child(p) : NULL,
129 mdt_object_child(o), spec, ma);
131 rc = mdt_attr_get_complex(info, o, ma);
133 if (rc == 0 && ma->ma_valid & MA_LOV)
134 o->mot_lov_created = 1;
137 mutex_unlock(&o->mot_lov_mutex);
141 int mdt_write_read(struct mdt_object *o)
145 spin_lock(&o->mot_write_lock);
146 rc = o->mot_write_count;
147 spin_unlock(&o->mot_write_lock);
151 int mdt_write_get(struct mdt_object *o)
155 spin_lock(&o->mot_write_lock);
156 if (o->mot_write_count < 0)
159 o->mot_write_count++;
160 spin_unlock(&o->mot_write_lock);
165 void mdt_write_put(struct mdt_object *o)
168 spin_lock(&o->mot_write_lock);
169 o->mot_write_count--;
170 spin_unlock(&o->mot_write_lock);
174 static int mdt_write_deny(struct mdt_object *o)
178 spin_lock(&o->mot_write_lock);
179 if (o->mot_write_count > 0)
182 o->mot_write_count--;
183 spin_unlock(&o->mot_write_lock);
187 static void mdt_write_allow(struct mdt_object *o)
190 spin_lock(&o->mot_write_lock);
191 o->mot_write_count++;
192 spin_unlock(&o->mot_write_lock);
196 /* there can be no real transaction so prepare the fake one */
197 static void mdt_empty_transno(struct mdt_thread_info *info, int rc)
199 struct mdt_device *mdt = info->mti_mdt;
200 struct ptlrpc_request *req = mdt_info_req(info);
201 struct tg_export_data *ted;
202 struct lsd_client_data *lcd;
205 /* transaction has occurred already */
206 if (lustre_msg_get_transno(req->rq_repmsg) != 0)
209 if (tgt_is_multimodrpcs_client(req->rq_export)) {
212 /* generate an empty transaction to get a transno
214 th = dt_trans_create(info->mti_env, mdt->mdt_bottom);
216 rc = dt_trans_start(info->mti_env, mdt->mdt_bottom, th);
217 dt_trans_stop(info->mti_env, mdt->mdt_bottom, th);
222 spin_lock(&mdt->mdt_lut.lut_translock);
224 if (info->mti_transno != 0) {
225 struct obd_export *exp = req->rq_export;
227 CERROR("%s: replay trans %llu NID %s: rc = %d\n",
228 mdt_obd_name(mdt), info->mti_transno,
229 libcfs_nid2str(exp->exp_connection->c_peer.nid),
231 spin_unlock(&mdt->mdt_lut.lut_translock);
234 } else if (info->mti_transno == 0) {
235 info->mti_transno = ++mdt->mdt_lut.lut_last_transno;
237 /* should be replay */
238 if (info->mti_transno > mdt->mdt_lut.lut_last_transno)
239 mdt->mdt_lut.lut_last_transno = info->mti_transno;
241 spin_unlock(&mdt->mdt_lut.lut_translock);
243 CDEBUG(D_INODE, "transno = %llu, last_committed = %llu\n",
245 req->rq_export->exp_obd->obd_last_committed);
247 req->rq_transno = info->mti_transno;
248 lustre_msg_set_transno(req->rq_repmsg, info->mti_transno);
250 /* update lcd in memory only for resent cases */
251 ted = &req->rq_export->exp_target_data;
253 mutex_lock(&ted->ted_lcd_lock);
255 if (info->mti_transno < lcd->lcd_last_transno &&
256 info->mti_transno != 0) {
257 /* This should happen during replay. Do not update
258 * last rcvd info if replay req transno < last transno,
259 * otherwise the following resend(after replay) can not
260 * be checked correctly by xid */
261 mutex_unlock(&ted->ted_lcd_lock);
262 CDEBUG(D_HA, "%s: transno = %llu < last_transno = %llu\n",
263 mdt_obd_name(mdt), info->mti_transno,
264 lcd->lcd_last_transno);
268 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE) {
269 if (info->mti_transno != 0)
270 lcd->lcd_last_close_transno = info->mti_transno;
271 lcd->lcd_last_close_xid = req->rq_xid;
272 lcd->lcd_last_close_result = rc;
274 /* VBR: save versions in last_rcvd for reconstruct. */
275 __u64 *pre_versions = lustre_msg_get_versions(req->rq_repmsg);
277 lcd->lcd_pre_versions[0] = pre_versions[0];
278 lcd->lcd_pre_versions[1] = pre_versions[1];
279 lcd->lcd_pre_versions[2] = pre_versions[2];
280 lcd->lcd_pre_versions[3] = pre_versions[3];
282 if (info->mti_transno != 0)
283 lcd->lcd_last_transno = info->mti_transno;
285 lcd->lcd_last_xid = req->rq_xid;
286 lcd->lcd_last_result = rc;
287 lcd->lcd_last_data = info->mti_opdata;
289 mutex_unlock(&ted->ted_lcd_lock);
294 void mdt_mfd_set_mode(struct mdt_file_data *mfd, __u64 mode)
296 LASSERT(mfd != NULL);
298 CDEBUG(D_HA, DFID " Change mfd mode %#llo -> %#llo.\n",
299 PFID(mdt_object_fid(mfd->mfd_object)), mfd->mfd_mode, mode);
301 mfd->mfd_mode = mode;
305 * prep ma_lmm/ma_lmv for md_attr from reply
307 static void mdt_prep_ma_buf_from_rep(struct mdt_thread_info *info,
308 struct mdt_object *obj,
311 LASSERT(ma->ma_lmv == NULL && ma->ma_lmm == NULL);
312 if (S_ISDIR(obj->mot_header.loh_attr)) {
313 ma->ma_lmv = req_capsule_server_get(info->mti_pill,
315 ma->ma_lmv_size = req_capsule_get_size(info->mti_pill,
318 if (ma->ma_lmv_size > 0)
319 ma->ma_need |= MA_LMV;
321 ma->ma_lmm = req_capsule_server_get(info->mti_pill,
323 ma->ma_lmm_size = req_capsule_get_size(info->mti_pill,
326 if (ma->ma_lmm_size > 0)
327 ma->ma_need |= MA_LOV;
331 static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p,
332 struct mdt_object *o, __u64 flags, int created,
333 struct ldlm_reply *rep)
335 struct ptlrpc_request *req = mdt_info_req(info);
336 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
337 struct mdt_file_data *mfd;
338 struct md_attr *ma = &info->mti_attr;
339 struct lu_attr *la = &ma->ma_attr;
340 struct mdt_body *repbody;
341 int rc = 0, isdir, isreg;
344 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
346 isreg = S_ISREG(la->la_mode);
347 isdir = S_ISDIR(la->la_mode);
348 if (isreg && !(ma->ma_valid & MA_LOV) && !(flags & MDS_OPEN_RELEASE)) {
350 * No EA, check whether it is will set regEA and dirEA since in
351 * above attr get, these size might be zero, so reset it, to
352 * retrieve the MD after create obj.
354 ma->ma_lmm_size = req_capsule_get_size(info->mti_pill,
357 /* in replay case, p == NULL */
358 rc = mdt_create_data(info, p, o);
362 if (exp_connect_flags(req->rq_export) & OBD_CONNECT_DISP_STRIPE)
363 mdt_set_disposition(info, rep, DISP_OPEN_STRIPE);
366 CDEBUG(D_INODE, "after open, ma_valid bit = %#llx lmm_size = %d\n",
367 ma->ma_valid, ma->ma_lmm_size);
369 if (ma->ma_valid & MA_LOV) {
370 LASSERT(ma->ma_lmm_size != 0);
371 repbody->mbo_eadatasize = ma->ma_lmm_size;
373 repbody->mbo_valid |= OBD_MD_FLDIREA;
375 repbody->mbo_valid |= OBD_MD_FLEASIZE;
378 if (ma->ma_valid & MA_LMV) {
379 LASSERT(ma->ma_lmv_size != 0);
380 repbody->mbo_eadatasize = ma->ma_lmv_size;
382 repbody->mbo_valid |= OBD_MD_FLDIREA | OBD_MD_MEA;
385 if (flags & FMODE_WRITE)
386 rc = mdt_write_get(o);
387 else if (flags & MDS_FMODE_EXEC)
388 rc = mdt_write_deny(o);
393 rc = mo_open(info->mti_env, mdt_object_child(o),
394 created ? flags | MDS_OPEN_CREATED : flags);
396 /* If we allow the client to chgrp (CFS_SETGRP_PERM), but the
397 * client does not know which suppgid should be sent to the MDS,
398 * or some other(s) changed the target file's GID after this RPC
399 * sent to the MDS with the suppgid as the original GID, then we
400 * give the client another chance to send the right suppgid. */
402 allow_client_chgrp(info, lu_ucred(info->mti_env)))
403 mdt_set_disposition(info, rep, DISP_OPEN_DENY);
408 mfd = mdt_mfd_new(med);
410 GOTO(err_out, rc = -ENOMEM);
413 * Keep a reference on this object for this open, and is
414 * released by mdt_mfd_close().
416 mdt_object_get(info->mti_env, o);
418 mfd->mfd_xid = req->rq_xid;
421 * @flags is always not zero. At least it should be FMODE_READ,
422 * FMODE_WRITE or MDS_FMODE_EXEC.
427 mdt_mfd_set_mode(mfd, flags);
429 atomic_inc(&o->mot_open_count);
430 if (flags & MDS_OPEN_LEASE)
431 atomic_inc(&o->mot_lease_count);
434 if (req_is_replay(req)) {
435 struct mdt_file_data *old_mfd;
436 /* Check wheather old cookie already exist in
437 * the list, becasue when do recovery, client
438 * might be disconnected from server, and
439 * restart replay, so there maybe some orphan
440 * mfd here, we should remove them */
441 LASSERT(info->mti_rr.rr_handle != NULL);
442 spin_lock(&med->med_open_lock);
443 old_mfd = mdt_handle2mfd(med, info->mti_rr.rr_handle, true);
444 if (old_mfd != NULL) {
445 CDEBUG(D_HA, "delete orphan mfd = %p, fid = "DFID", "
446 "cookie = %#llx\n", mfd,
447 PFID(mdt_object_fid(mfd->mfd_object)),
448 info->mti_rr.rr_handle->cookie);
449 class_handle_unhash(&old_mfd->mfd_handle);
450 list_del_init(&old_mfd->mfd_list);
451 spin_unlock(&med->med_open_lock);
452 /* no attr update for that close */
454 ma->ma_valid |= MA_FLAGS;
455 ma->ma_attr_flags |= MDS_RECOV_OPEN;
456 mdt_mfd_close(info, old_mfd);
457 ma->ma_attr_flags &= ~MDS_RECOV_OPEN;
458 ma->ma_valid &= ~MA_FLAGS;
460 spin_unlock(&med->med_open_lock);
461 CDEBUG(D_HA, "orphan mfd not found, fid = "DFID", "
463 PFID(mdt_object_fid(mfd->mfd_object)),
464 info->mti_rr.rr_handle->cookie);
467 CDEBUG(D_HA, "Store old cookie %#llx in new mfd\n",
468 info->mti_rr.rr_handle->cookie);
470 mfd->mfd_old_handle.cookie = info->mti_rr.rr_handle->cookie;
473 repbody->mbo_handle.cookie = mfd->mfd_handle.h_cookie;
475 if (req->rq_export->exp_disconnected) {
476 spin_lock(&med->med_open_lock);
477 class_handle_unhash(&mfd->mfd_handle);
478 list_del_init(&mfd->mfd_list);
479 spin_unlock(&med->med_open_lock);
480 mdt_mfd_close(info, mfd);
482 spin_lock(&med->med_open_lock);
483 list_add(&mfd->mfd_list, &med->med_open_head);
484 spin_unlock(&med->med_open_lock);
487 mdt_empty_transno(info, rc);
492 if (flags & FMODE_WRITE)
494 else if (flags & MDS_FMODE_EXEC)
500 static int mdt_finish_open(struct mdt_thread_info *info,
501 struct mdt_object *p, struct mdt_object *o,
502 __u64 flags, int created, struct ldlm_reply *rep)
504 struct ptlrpc_request *req = mdt_info_req(info);
505 struct obd_export *exp = req->rq_export;
506 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
507 struct md_attr *ma = &info->mti_attr;
508 struct lu_attr *la = &ma->ma_attr;
509 struct mdt_file_data *mfd;
510 struct mdt_body *repbody;
512 int isreg, isdir, islnk;
516 LASSERT(ma->ma_valid & MA_INODE);
518 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
520 isreg = S_ISREG(la->la_mode);
521 isdir = S_ISDIR(la->la_mode);
522 islnk = S_ISLNK(la->la_mode);
523 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
525 /* LU-2275, simulate broken behaviour (esp. prevalent in
526 * pre-2.4 servers where a very strange reply is sent on error
527 * that looks like it was actually almost successful and a
528 * failure at the same time.) */
529 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_NEGATIVE_POSITIVE)) {
530 mdt_set_disposition(info, rep, DISP_OPEN_OPEN |
534 if (flags & MDS_OPEN_LOCK)
535 mdt_set_disposition(info, rep, DISP_OPEN_LOCK);
540 #ifdef CONFIG_FS_POSIX_ACL
541 if (exp_connect_flags(exp) & OBD_CONNECT_ACL) {
542 struct lu_nodemap *nodemap = nodemap_get_from_exp(exp);
544 RETURN(PTR_ERR(nodemap));
546 rc = mdt_pack_acl2body(info, repbody, o, nodemap);
547 nodemap_putref(nodemap);
554 * If we are following a symlink, don't open; and do not return open
555 * handle for special nodes as client required.
557 if (islnk || (!isreg && !isdir &&
558 (exp_connect_flags(req->rq_export) & OBD_CONNECT_NODEVOH))) {
559 lustre_msg_set_transno(req->rq_repmsg, 0);
564 * We need to return the existing object's fid back, so it is done here,
565 * after preparing the reply.
567 if (!created && (flags & MDS_OPEN_EXCL) && (flags & MDS_OPEN_CREAT))
570 /* This can't be done earlier, we need to return reply body */
572 if (flags & (MDS_OPEN_CREAT | FMODE_WRITE)) {
573 /* We are trying to create or write an existing dir. */
576 } else if (flags & MDS_OPEN_DIRECTORY)
579 if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MDS_OPEN_CREATE,
580 OBD_FAIL_LDLM_REPLY | OBD_FAIL_ONCE)) {
585 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
586 spin_lock(&med->med_open_lock);
587 list_for_each(t, &med->med_open_head) {
588 mfd = list_entry(t, struct mdt_file_data, mfd_list);
589 if (mfd->mfd_xid == req->rq_xid)
593 spin_unlock(&med->med_open_lock);
596 repbody->mbo_handle.cookie = mfd->mfd_handle.h_cookie;
597 /* set repbody->ea_size for resent case */
598 if (ma->ma_valid & MA_LOV) {
599 LASSERT(ma->ma_lmm_size != 0);
600 repbody->mbo_eadatasize = ma->ma_lmm_size;
602 repbody->mbo_valid |= OBD_MD_FLDIREA;
604 repbody->mbo_valid |= OBD_MD_FLEASIZE;
606 mdt_set_disposition(info, rep, DISP_OPEN_OPEN);
611 rc = mdt_mfd_open(info, p, o, flags, created, rep);
613 mdt_set_disposition(info, rep, DISP_OPEN_OPEN);
618 void mdt_reconstruct_open(struct mdt_thread_info *info,
619 struct mdt_lock_handle *lhc)
621 const struct lu_env *env = info->mti_env;
622 struct mdt_device *mdt = info->mti_mdt;
623 struct req_capsule *pill = info->mti_pill;
624 struct ptlrpc_request *req = mdt_info_req(info);
625 struct md_attr *ma = &info->mti_attr;
626 struct mdt_reint_record *rr = &info->mti_rr;
627 __u64 flags = info->mti_spec.sp_cr_flags;
628 struct ldlm_reply *ldlm_rep;
629 struct mdt_object *parent;
630 struct mdt_object *child;
631 struct mdt_body *repbody;
636 LASSERT(pill->rc_fmt == &RQF_LDLM_INTENT_OPEN);
637 ldlm_rep = req_capsule_server_get(pill, &RMF_DLM_REP);
638 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
640 ma->ma_need = MA_INODE | MA_HSM;
643 opdata = mdt_req_from_lrd(req, info->mti_reply_data);
644 mdt_set_disposition(info, ldlm_rep, opdata);
646 CDEBUG(D_INODE, "This is reconstruct open: disp=%#llx, result=%d\n",
647 ldlm_rep->lock_policy_res1, req->rq_status);
649 if (mdt_get_disposition(ldlm_rep, DISP_OPEN_CREATE) &&
651 /* We did not create successfully, return error to client. */
652 GOTO(out, rc = req->rq_status);
654 if (mdt_get_disposition(ldlm_rep, DISP_OPEN_CREATE)) {
655 struct obd_export *exp = req->rq_export;
657 * We failed after creation, but we do not know in which step
658 * we failed. So try to check the child object.
660 parent = mdt_object_find(env, mdt, rr->rr_fid1);
661 if (IS_ERR(parent)) {
662 rc = PTR_ERR(parent);
663 LCONSOLE_WARN("Parent "DFID" lookup error %d."
664 " Evicting client %s with export %s.\n",
665 PFID(rr->rr_fid1), rc,
666 obd_uuid2str(&exp->exp_client_uuid),
667 obd_export_nid2str(exp));
668 mdt_export_evict(exp);
672 child = mdt_object_find(env, mdt, rr->rr_fid2);
675 LCONSOLE_WARN("cannot lookup child "DFID": rc = %d; "
676 "evicting client %s with export %s\n",
677 PFID(rr->rr_fid2), rc,
678 obd_uuid2str(&exp->exp_client_uuid),
679 obd_export_nid2str(exp));
680 mdt_object_put(env, parent);
681 mdt_export_evict(exp);
685 if (unlikely(mdt_object_remote(child))) {
686 /* the child object was created on remote server */
687 if (!mdt_is_dne_client(exp)) {
688 /* Return -EIO for old client */
689 mdt_object_put(env, parent);
690 mdt_object_put(env, child);
691 GOTO(out, rc = -EIO);
693 repbody->mbo_fid1 = *rr->rr_fid2;
694 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
697 if (mdt_object_exists(child)) {
698 mdt_prep_ma_buf_from_rep(info, child, ma);
699 rc = mdt_attr_get_complex(info, child, ma);
701 rc = mdt_finish_open(info, parent,
705 /* the child does not exist, we should do
707 mdt_object_put(env, parent);
708 mdt_object_put(env, child);
709 GOTO(regular_open, 0);
712 mdt_object_put(env, parent);
713 mdt_object_put(env, child);
717 /* We did not try to create, so we are a pure open */
718 rc = mdt_reint_open(info, lhc);
724 lustre_msg_set_status(req->rq_repmsg, req->rq_status);
725 LASSERT(ergo(rc < 0, lustre_msg_get_transno(req->rq_repmsg) == 0));
728 static int mdt_open_by_fid(struct mdt_thread_info *info, struct ldlm_reply *rep)
730 __u64 flags = info->mti_spec.sp_cr_flags;
731 struct mdt_reint_record *rr = &info->mti_rr;
732 struct md_attr *ma = &info->mti_attr;
733 struct mdt_object *o;
737 o = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid2);
739 RETURN(rc = PTR_ERR(o));
741 if (unlikely(mdt_object_remote(o))) {
742 /* the child object was created on remote server */
743 struct mdt_body *repbody;
745 mdt_set_disposition(info, rep, (DISP_IT_EXECD |
748 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
749 repbody->mbo_fid1 = *rr->rr_fid2;
750 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
753 if (mdt_object_exists(o)) {
754 mdt_set_disposition(info, rep, (DISP_IT_EXECD |
757 mdt_prep_ma_buf_from_rep(info, o, ma);
758 rc = mdt_attr_get_complex(info, o, ma);
760 rc = mdt_finish_open(info, NULL, o, flags, 0,
767 mdt_object_put(info->mti_env, o);
771 /* lock object for open */
772 static int mdt_object_open_lock(struct mdt_thread_info *info,
773 struct mdt_object *obj,
774 struct mdt_lock_handle *lhc,
777 struct md_attr *ma = &info->mti_attr;
778 __u64 open_flags = info->mti_spec.sp_cr_flags;
779 enum ldlm_mode lm = LCK_CR;
780 bool acq_lease = !!(open_flags & MDS_OPEN_LEASE);
781 bool try_layout = false;
782 bool create_layout = false;
787 mdt_lock_handle_init(lhc);
789 if (req_is_replay(mdt_info_req(info)))
792 if (S_ISREG(lu_object_attr(&obj->mot_obj))) {
793 if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV) &&
794 md_should_create(open_flags))
795 create_layout = true;
796 if (exp_connect_layout(info->mti_exp) && !create_layout &&
797 ma->ma_need & MA_LOV)
802 /* lease open, acquire write mode of open sem */
803 down_write(&obj->mot_open_sem);
805 /* Lease exists and ask for new lease */
806 if (atomic_read(&obj->mot_lease_count) > 0) {
807 /* only exclusive open is supported, so lease
808 * are conflicted to each other */
809 GOTO(out, rc = -EBUSY);
812 /* Lease must be with open lock */
813 if (!(open_flags & MDS_OPEN_LOCK)) {
814 CERROR("%s: Request lease for file:"DFID ", but open lock "
815 "is missed, open_flags = %#llo : rc = %d\n",
816 mdt_obd_name(info->mti_mdt),
817 PFID(mdt_object_fid(obj)), open_flags, -EPROTO);
818 GOTO(out, rc = -EPROTO);
821 /* XXX: only exclusive open is supported. */
823 *ibits = MDS_INODELOCK_OPEN;
825 /* never grant LCK_EX layout lock to client */
827 } else { /* normal open */
828 /* normal open holds read mode of open sem */
829 down_read(&obj->mot_open_sem);
831 if (open_flags & MDS_OPEN_LOCK) {
832 if (open_flags & FMODE_WRITE)
834 else if (open_flags & MDS_FMODE_EXEC)
839 *ibits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_OPEN;
840 } else if (atomic_read(&obj->mot_lease_count) > 0) {
841 if (open_flags & FMODE_WRITE)
847 *ibits = MDS_INODELOCK_OPEN;
850 lhc = &info->mti_lh[MDT_LH_LOCAL];
852 CDEBUG(D_INODE, "normal open:"DFID" lease count: %d, lm: %d\n",
853 PFID(mdt_object_fid(obj)),
854 atomic_read(&obj->mot_open_count), lm);
857 mdt_lock_reg_init(lhc, lm);
859 /* one problem to return layout lock on open is that it may result
860 * in too many layout locks cached on the client side. */
861 if (!OBD_FAIL_CHECK(OBD_FAIL_MDS_NO_LL_OPEN) && try_layout) {
862 /* return lookup lock to validate inode at the client side,
863 * this is pretty important otherwise mdt will return layout
864 * lock for each open.
865 * However this is a double-edged sword because changing
866 * permission will revoke huge # of LOOKUP locks. */
867 *ibits |= MDS_INODELOCK_LAYOUT | MDS_INODELOCK_LOOKUP;
868 if (!mdt_object_lock_try(info, obj, lhc, *ibits)) {
869 *ibits &= ~(MDS_INODELOCK_LAYOUT|MDS_INODELOCK_LOOKUP);
871 rc = mdt_object_lock(info, obj, lhc, *ibits);
873 } else if (*ibits != 0) {
874 rc = mdt_object_lock(info, obj, lhc, *ibits);
877 CDEBUG(D_INODE, "%s: Requested bits lock:"DFID ", ibits = %#llx"
878 ", open_flags = %#llo, try_layout = %d : rc = %d\n",
879 mdt_obd_name(info->mti_mdt), PFID(mdt_object_fid(obj)),
880 *ibits, open_flags, try_layout, rc);
882 /* will change layout, revoke layout locks by enqueuing EX lock. */
883 if (rc == 0 && create_layout) {
884 struct mdt_lock_handle *ll = &info->mti_lh[MDT_LH_LAYOUT];
886 CDEBUG(D_INODE, "Will create layout, get EX layout lock:"DFID
887 ", open_flags = %#llo\n",
888 PFID(mdt_object_fid(obj)), open_flags);
890 /* We cannot enqueue another lock for the same resource we
891 * already have a lock for, due to mechanics of waiting list
892 * iterating in ldlm, see LU-3601.
893 * As such we'll drop the open lock we just got above here,
894 * it's ok not to have this open lock as it's main purpose is to
895 * flush unused cached client open handles. */
896 if (lustre_handle_is_used(&lhc->mlh_reg_lh))
897 mdt_object_unlock(info, obj, lhc, 1);
899 LASSERT(!try_layout);
900 mdt_lock_handle_init(ll);
901 mdt_lock_reg_init(ll, LCK_EX);
902 rc = mdt_object_lock(info, obj, ll, MDS_INODELOCK_LAYOUT);
904 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_LL_BLOCK, 2);
907 /* Check if there is any other open handles after acquiring
908 * open lock. At this point, caching open handles have been revoked
910 * XXX: Now only exclusive open is supported. Need to check the
911 * type of open for generic lease support. */
912 if (rc == 0 && acq_lease) {
913 struct ptlrpc_request *req = mdt_info_req(info);
914 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
915 struct mdt_file_data *mfd;
916 bool is_replay_or_resent;
919 /* For lease: application can open a file and then apply lease,
920 * @handle contains original open handle in that case.
921 * In recovery, open REQ will be replayed and the lease REQ may
922 * be resent that means the open handle is already stale, so we
923 * need to fix it up here by finding new handle. */
924 is_replay_or_resent = req_is_replay(req) ||
925 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT;
927 /* if the request is _not_ a replay request, rr_handle
928 * may be used to hold an openhandle which is issuing the
929 * lease request, so that this openhandle doesn't count. */
930 mfd = mdt_handle2mfd(med, info->mti_rr.rr_handle,
931 is_replay_or_resent);
935 CDEBUG(D_INODE, "acq_lease "DFID": openers: %d, want: %d\n",
936 PFID(mdt_object_fid(obj)),
937 atomic_read(&obj->mot_open_count), open_count);
939 if (atomic_read(&obj->mot_open_count) > open_count)
940 GOTO(out, rc = -EBUSY);
948 static void mdt_object_open_unlock(struct mdt_thread_info *info,
949 struct mdt_object *obj,
950 struct mdt_lock_handle *lhc,
953 __u64 open_flags = info->mti_spec.sp_cr_flags;
954 struct mdt_lock_handle *ll = &info->mti_lh[MDT_LH_LOCAL];
957 if (req_is_replay(mdt_info_req(info)))
960 /* Release local lock - the lock put in MDT_LH_LOCAL will never
961 * return to client side. */
962 if (lustre_handle_is_used(&ll->mlh_reg_lh))
963 mdt_object_unlock(info, obj, ll, 1);
965 ll = &info->mti_lh[MDT_LH_LAYOUT];
966 /* Release local layout lock, layout was created */
967 if (lustre_handle_is_used(&ll->mlh_reg_lh)) {
968 LASSERT(!(ibits & MDS_INODELOCK_LAYOUT));
969 mdt_object_unlock(info, obj, ll, 1);
972 if (open_flags & MDS_OPEN_LEASE)
973 up_write(&obj->mot_open_sem);
975 up_read(&obj->mot_open_sem);
977 /* Cross-ref case, the lock should be returned to the client */
978 if (ibits == 0 || rc == -MDT_EREMOTE_OPEN)
981 if (!(open_flags & MDS_OPEN_LOCK) && !(ibits & MDS_INODELOCK_LAYOUT)) {
982 /* for the open request, the lock will only return to client
983 * if open or layout lock is granted. */
987 if (rc != 0 || !lustre_handle_is_used(&lhc->mlh_reg_lh)) {
988 struct ldlm_reply *ldlm_rep;
990 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
991 mdt_clear_disposition(info, ldlm_rep, DISP_OPEN_LOCK);
992 if (lustre_handle_is_used(&lhc->mlh_reg_lh))
993 mdt_object_unlock(info, obj, lhc, 1);
999 * Check release is permitted for the current HSM flags.
1001 static bool mdt_hsm_release_allow(const struct md_attr *ma)
1003 if (!(ma->ma_valid & MA_HSM))
1006 if (ma->ma_hsm.mh_flags & (HS_DIRTY|HS_NORELEASE|HS_LOST))
1009 if (!(ma->ma_hsm.mh_flags & HS_ARCHIVED))
1015 static int mdt_open_by_fid_lock(struct mdt_thread_info *info,
1016 struct ldlm_reply *rep,
1017 struct mdt_lock_handle *lhc)
1019 const struct lu_env *env = info->mti_env;
1020 struct mdt_device *mdt = info->mti_mdt;
1021 __u64 flags = info->mti_spec.sp_cr_flags;
1022 struct mdt_reint_record *rr = &info->mti_rr;
1023 struct md_attr *ma = &info->mti_attr;
1024 struct mdt_object *parent= NULL;
1025 struct mdt_object *o;
1027 bool object_locked = false;
1031 if (md_should_create(flags) && !(flags & MDS_OPEN_HAS_EA)) {
1032 if (!lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) {
1033 parent = mdt_object_find(env, mdt, rr->rr_fid1);
1034 if (IS_ERR(parent)) {
1035 CDEBUG(D_INODE, "Fail to find parent "DFID
1036 " for anonymous created %ld, try to"
1037 " use server-side parent.\n",
1038 PFID(rr->rr_fid1), PTR_ERR(parent));
1043 ma->ma_need |= MA_PFID;
1046 o = mdt_object_find(env, mdt, rr->rr_fid2);
1048 GOTO(out_parent_put, rc = PTR_ERR(o));
1050 if (mdt_object_remote(o)) {
1051 CDEBUG(D_INFO, "%s: "DFID" is on remote MDT.\n",
1052 mdt_obd_name(info->mti_mdt),
1054 GOTO(out, rc = -EREMOTE);
1055 } else if (!mdt_object_exists(o)) {
1056 mdt_set_disposition(info, rep,
1060 GOTO(out, rc = -ENOENT);
1063 mdt_set_disposition(info, rep, (DISP_IT_EXECD | DISP_LOOKUP_EXECD));
1065 mdt_prep_ma_buf_from_rep(info, o, ma);
1066 if (flags & MDS_OPEN_RELEASE)
1067 ma->ma_need |= MA_HSM;
1068 rc = mdt_attr_get_complex(info, o, ma);
1072 /* We should not change file's existing LOV EA */
1073 if (S_ISREG(lu_object_attr(&o->mot_obj)) &&
1074 flags & MDS_OPEN_HAS_EA && ma->ma_valid & MA_LOV)
1075 GOTO(out, rc = -EEXIST);
1077 /* If a release request, check file flags are fine and ask for an
1078 * exclusive open access. */
1079 if (flags & MDS_OPEN_RELEASE && !mdt_hsm_release_allow(ma))
1080 GOTO(out, rc = -EPERM);
1082 rc = mdt_check_resent_lock(info, o, lhc);
1085 } else if (rc > 0) {
1086 rc = mdt_object_open_lock(info, o, lhc, &ibits);
1087 object_locked = true;
1089 GOTO(out_unlock, rc);
1092 if (ma->ma_valid & MA_PFID) {
1093 parent = mdt_object_find(env, mdt, &ma->ma_pfid);
1094 if (IS_ERR(parent)) {
1095 CDEBUG(D_INODE, "Fail to find parent "DFID
1096 " for anonymous created %ld, try to"
1097 " use system default.\n",
1098 PFID(&ma->ma_pfid), PTR_ERR(parent));
1103 rc = mdt_finish_open(info, parent, o, flags, 0, rep);
1105 mdt_set_disposition(info, rep, DISP_LOOKUP_POS);
1106 if (flags & MDS_OPEN_LOCK)
1107 mdt_set_disposition(info, rep, DISP_OPEN_LOCK);
1108 if (flags & MDS_OPEN_LEASE)
1109 mdt_set_disposition(info, rep, DISP_OPEN_LEASE);
1111 GOTO(out_unlock, rc);
1115 mdt_object_open_unlock(info, o, lhc, ibits, rc);
1117 mdt_object_put(env, o);
1120 mdt_object_put(env, parent);
1124 /* Cross-ref request. Currently it can only be a pure open (w/o create) */
1125 static int mdt_cross_open(struct mdt_thread_info *info,
1126 const struct lu_fid *parent_fid,
1127 const struct lu_fid *fid,
1128 struct ldlm_reply *rep, __u32 flags)
1130 struct md_attr *ma = &info->mti_attr;
1131 struct mdt_object *o;
1135 o = mdt_object_find(info->mti_env, info->mti_mdt, fid);
1137 RETURN(rc = PTR_ERR(o));
1139 if (mdt_object_remote(o)) {
1140 /* Something is wrong here, the object is on another MDS! */
1141 CERROR("%s: "DFID" isn't on this server!: rc = %d\n",
1142 mdt_obd_name(info->mti_mdt), PFID(fid), -EFAULT);
1143 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
1145 "Object isn't on this server! FLD error?");
1148 if (mdt_object_exists(o)) {
1149 /* Do permission check for cross-open. */
1150 rc = mo_permission(info->mti_env, NULL,
1151 mdt_object_child(o),
1152 NULL, flags | MDS_OPEN_CROSS);
1156 mdt_prep_ma_buf_from_rep(info, o, ma);
1157 rc = mdt_attr_get_complex(info, o, ma);
1161 rc = mdt_finish_open(info, NULL, o, flags, 0, rep);
1164 * Something is wrong here. lookup was positive but
1165 * there is no object!
1167 CERROR("%s: "DFID" doesn't exist!: rc = %d\n",
1168 mdt_obd_name(info->mti_mdt), PFID(fid), -EFAULT);
1173 mdt_object_put(info->mti_env, o);
1178 * find root object and take its xattr lock if it's on remote MDT, later create
1179 * may use fs default striping (which is stored in root xattr).
1181 static int mdt_lock_root_xattr(struct mdt_thread_info *info,
1182 struct mdt_device *mdt)
1184 struct mdt_object *md_root = mdt->mdt_md_root;
1185 struct lustre_handle lhroot;
1188 if (md_root == NULL) {
1189 lu_root_fid(&info->mti_tmp_fid1);
1190 md_root = mdt_object_find(info->mti_env, mdt,
1191 &info->mti_tmp_fid1);
1192 if (IS_ERR(md_root))
1193 return PTR_ERR(md_root);
1195 spin_lock(&mdt->mdt_lock);
1196 if (mdt->mdt_md_root != NULL)
1197 mdt_object_put(info->mti_env, mdt->mdt_md_root);
1198 mdt->mdt_md_root = md_root;
1199 spin_unlock(&mdt->mdt_lock);
1202 if (md_root->mot_cache_attr || !mdt_object_remote(md_root))
1205 rc = mdt_remote_object_lock(info, md_root, mdt_object_fid(md_root),
1206 &lhroot, LCK_PR, MDS_INODELOCK_XATTR,
1211 md_root->mot_cache_attr = 1;
1213 /* don't cancel this lock, so that we know the cached xattr is valid. */
1214 ldlm_lock_decref(&lhroot, LCK_PR);
1219 int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc)
1221 struct mdt_device *mdt = info->mti_mdt;
1222 struct ptlrpc_request *req = mdt_info_req(info);
1223 struct mdt_object *parent;
1224 struct mdt_object *child;
1225 struct mdt_lock_handle *lh;
1226 struct ldlm_reply *ldlm_rep;
1227 struct mdt_body *repbody;
1228 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1229 struct md_attr *ma = &info->mti_attr;
1230 __u64 create_flags = info->mti_spec.sp_cr_flags;
1232 struct mdt_reint_record *rr = &info->mti_rr;
1235 int object_locked = 0;
1239 OBD_FAIL_TIMEOUT_ORSET(OBD_FAIL_MDS_PAUSE_OPEN, OBD_FAIL_ONCE,
1240 (obd_timeout + 1) / 4);
1242 mdt_counter_incr(req, LPROC_MDT_OPEN);
1243 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1245 ma->ma_need = MA_INODE;
1248 LASSERT(info->mti_pill->rc_fmt == &RQF_LDLM_INTENT_OPEN);
1249 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
1251 if (unlikely(create_flags & MDS_OPEN_JOIN_FILE)) {
1252 CERROR("file join is not supported anymore.\n");
1253 GOTO(out, result = err_serious(-EOPNOTSUPP));
1255 msg_flags = lustre_msg_get_flags(req->rq_reqmsg);
1257 if ((create_flags & (MDS_OPEN_HAS_EA | MDS_OPEN_HAS_OBJS)) &&
1258 info->mti_spec.u.sp_ea.eadata == NULL)
1259 GOTO(out, result = err_serious(-EINVAL));
1261 if (create_flags & FMODE_WRITE &&
1262 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
1263 GOTO(out, result = -EROFS);
1265 CDEBUG(D_INODE, "I am going to open "DFID"/("DNAME"->"DFID") "
1266 "cr_flag=%#llo mode=0%06o msg_flag=0x%x\n",
1267 PFID(rr->rr_fid1), PNAME(&rr->rr_name),
1268 PFID(rr->rr_fid2), create_flags,
1269 ma->ma_attr.la_mode, msg_flags);
1271 if (info->mti_cross_ref) {
1272 /* This is cross-ref open */
1273 mdt_set_disposition(info, ldlm_rep,
1274 (DISP_IT_EXECD | DISP_LOOKUP_EXECD |
1276 result = mdt_cross_open(info, rr->rr_fid2, rr->rr_fid1,
1277 ldlm_rep, create_flags);
1279 } else if (req_is_replay(req) ||
1280 (req->rq_export->exp_libclient && create_flags & MDS_OPEN_HAS_EA)) {
1281 /* This is a replay request or from liblustre with ea. */
1282 result = mdt_open_by_fid(info, ldlm_rep);
1284 if (result != -ENOENT) {
1285 if (req->rq_export->exp_libclient &&
1286 create_flags & MDS_OPEN_HAS_EA)
1287 GOTO(out, result = 0);
1290 /* We didn't find the correct object, so we need to re-create it
1291 * via a regular replay. */
1292 if (!(create_flags & MDS_OPEN_CREAT)) {
1293 DEBUG_REQ(D_ERROR, req,
1294 "OPEN & CREAT not in open replay/by_fid.");
1295 GOTO(out, result = -EFAULT);
1297 CDEBUG(D_INFO, "No object(1), continue as regular open.\n");
1298 } else if (create_flags & (MDS_OPEN_BY_FID | MDS_OPEN_LOCK)) {
1300 * MDS_OPEN_LOCK is checked for backward compatibility with 2.1
1303 result = mdt_open_by_fid_lock(info, ldlm_rep, lhc);
1305 CDEBUG(D_INFO, "no object for "DFID": %d\n",
1306 PFID(rr->rr_fid2), result);
1310 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK))
1311 GOTO(out, result = err_serious(-ENOMEM));
1313 mdt_set_disposition(info, ldlm_rep,
1314 (DISP_IT_EXECD | DISP_LOOKUP_EXECD));
1316 if (!lu_name_is_valid(&rr->rr_name))
1317 GOTO(out, result = -EPROTO);
1319 result = mdt_lock_root_xattr(info, mdt);
1324 lh = &info->mti_lh[MDT_LH_PARENT];
1325 mdt_lock_pdo_init(lh,
1326 (create_flags & MDS_OPEN_CREAT) ? LCK_PW : LCK_PR,
1329 parent = mdt_object_find(info->mti_env, mdt, rr->rr_fid1);
1331 GOTO(out, result = PTR_ERR(parent));
1333 result = mdt_object_lock(info, parent, lh, MDS_INODELOCK_UPDATE);
1335 mdt_object_put(info->mti_env, parent);
1339 /* get and check version of parent */
1340 result = mdt_version_get_check(info, parent, 0);
1342 GOTO(out_parent, result);
1344 fid_zero(child_fid);
1346 result = mdo_lookup(info->mti_env, mdt_object_child(parent),
1347 &rr->rr_name, child_fid, &info->mti_spec);
1349 LASSERTF(ergo(result == 0, fid_is_sane(child_fid)),
1350 "looking for "DFID"/"DNAME", found FID = "DFID"\n",
1351 PFID(mdt_object_fid(parent)), PNAME(&rr->rr_name),
1354 if (result != 0 && result != -ENOENT && result != -ESTALE)
1355 GOTO(out_parent, result);
1357 if (result == -ENOENT || result == -ESTALE) {
1358 /* If the object is dead, let's check if the object
1359 * is being migrated to a new object */
1360 if (result == -ESTALE) {
1361 struct lu_buf lmv_buf;
1363 lmv_buf.lb_buf = info->mti_xattr_buf;
1364 lmv_buf.lb_len = sizeof(info->mti_xattr_buf);
1365 rc = mo_xattr_get(info->mti_env,
1366 mdt_object_child(parent),
1367 &lmv_buf, XATTR_NAME_LMV);
1369 struct lmv_mds_md_v1 *lmv;
1371 lmv = lmv_buf.lb_buf;
1372 if (le32_to_cpu(lmv->lmv_hash_type) &
1373 LMV_HASH_FLAG_MIGRATION) {
1374 /* Get the new parent FID and retry */
1375 mdt_object_unlock_put(info, parent,
1377 mdt_lock_handle_init(lh);
1379 (struct lu_fid *)rr->rr_fid1,
1380 &lmv->lmv_stripe_fids[1]);
1386 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1387 if (result == -ESTALE) {
1389 * -ESTALE means the parent is a dead(unlinked) dir, so
1390 * it should return -ENOENT to in accordance with the
1391 * original mds implementaion.
1393 GOTO(out_parent, result = -ENOENT);
1396 if (!(create_flags & MDS_OPEN_CREAT))
1397 GOTO(out_parent, result);
1398 if (exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
1399 GOTO(out_parent, result = -EROFS);
1400 *child_fid = *info->mti_rr.rr_fid2;
1401 LASSERTF(fid_is_sane(child_fid), "fid="DFID"\n",
1403 /* In the function below, .hs_keycmp resolves to
1404 * lu_obj_hop_keycmp() */
1405 /* coverity[overrun-buffer-val] */
1406 child = mdt_object_new(info->mti_env, mdt, child_fid);
1409 * Check for O_EXCL is moved to the mdt_finish_open(), we need to
1410 * return FID back in that case.
1412 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1413 child = mdt_object_find(info->mti_env, mdt, child_fid);
1416 GOTO(out_parent, result = PTR_ERR(child));
1418 /** check version of child */
1419 rc = mdt_version_get_check(info, child, 1);
1421 GOTO(out_child, result = rc);
1423 if (result == -ENOENT) {
1424 /* Create under OBF and .lustre is not permitted */
1425 if (!fid_is_md_operative(rr->rr_fid1))
1426 GOTO(out_child, result = -EPERM);
1428 /* save versions in reply */
1429 mdt_version_get_save(info, parent, 0);
1430 mdt_version_get_save(info, child, 1);
1432 /* version of child will be changed */
1433 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(child));
1435 /* Not found and with MDS_OPEN_CREAT: let's create it. */
1436 mdt_set_disposition(info, ldlm_rep, DISP_OPEN_CREATE);
1438 /* Let lower layers know what is lock mode on directory. */
1439 info->mti_spec.sp_cr_mode =
1440 mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode);
1443 * Do not perform lookup sanity check. We know that name does
1446 info->mti_spec.sp_cr_lookup = 0;
1447 info->mti_spec.sp_feat = &dt_directory_features;
1449 result = mdo_create(info->mti_env,
1450 mdt_object_child(parent),
1452 mdt_object_child(child),
1455 if (result == -ERESTART) {
1456 mdt_clear_disposition(info, ldlm_rep, DISP_OPEN_CREATE);
1457 GOTO(out_child, result);
1459 mdt_prep_ma_buf_from_rep(info, child, ma);
1460 /* XXX: we should call this once, see few lines below */
1462 result = mdt_attr_get_complex(info, child, ma);
1465 GOTO(out_child, result);
1468 mdt_counter_incr(req, LPROC_MDT_MKNOD);
1471 * The object is on remote node, return its FID for remote open.
1473 if (mdt_object_remote(child)) {
1475 * Check if this lock already was sent to client and
1476 * this is resent case. For resent case do not take lock
1477 * again, use what is already granted.
1479 LASSERT(lhc != NULL);
1481 rc = mdt_check_resent_lock(info, child, lhc);
1483 GOTO(out_child, result = rc);
1484 } else if (rc > 0) {
1485 mdt_lock_handle_init(lhc);
1486 mdt_lock_reg_init(lhc, LCK_PR);
1488 rc = mdt_object_lock(info, child, lhc,
1489 MDS_INODELOCK_LOOKUP);
1491 repbody->mbo_fid1 = *mdt_object_fid(child);
1492 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
1496 result = -MDT_EREMOTE_OPEN;
1497 GOTO(out_child, result);
1498 } else if (mdt_object_exists(child)) {
1499 /* We have to get attr & LOV EA & HSM for this
1501 mdt_prep_ma_buf_from_rep(info, child, ma);
1502 ma->ma_need |= MA_HSM;
1503 result = mdt_attr_get_complex(info, child, ma);
1505 GOTO(out_child, result);
1507 /* Object does not exist. Likely FS corruption. */
1508 CERROR("%s: name '"DNAME"' present, but FID "
1509 DFID" is invalid\n", mdt_obd_name(info->mti_mdt),
1510 PNAME(&rr->rr_name), PFID(child_fid));
1511 GOTO(out_child, result = -EIO);
1515 rc = mdt_check_resent_lock(info, child, lhc);
1517 GOTO(out_child, result = rc);
1518 } else if (rc == 0) {
1519 /* the open lock might already be gotten in
1520 * ldlm_handle_enqueue() */
1521 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
1522 if (create_flags & MDS_OPEN_LOCK)
1523 mdt_set_disposition(info, ldlm_rep, DISP_OPEN_LOCK);
1525 /* get openlock if this isn't replay and client requested it */
1526 if (!req_is_replay(req)) {
1527 rc = mdt_object_open_lock(info, child, lhc, &ibits);
1530 GOTO(out_child_unlock, result = rc);
1531 else if (create_flags & MDS_OPEN_LOCK)
1532 mdt_set_disposition(info, ldlm_rep,
1536 /* Try to open it now. */
1537 rc = mdt_finish_open(info, parent, child, create_flags,
1541 /* openlock will be released if mdt_finish_open failed */
1542 mdt_clear_disposition(info, ldlm_rep, DISP_OPEN_LOCK);
1544 if (created && create_flags & MDS_OPEN_VOLATILE) {
1545 CERROR("%s: cannot open volatile file "DFID", orphan "
1546 "file will be left in PENDING directory until "
1547 "next reboot, rc = %d\n", mdt_obd_name(mdt),
1548 PFID(mdt_object_fid(child)), rc);
1549 GOTO(out_child_unlock, result);
1555 rc = mdo_unlink(info->mti_env,
1556 mdt_object_child(parent),
1557 mdt_object_child(child),
1559 &info->mti_attr, 0);
1561 CERROR("%s: "DFID" cleanup of open: rc = %d\n",
1562 mdt_obd_name(info->mti_mdt),
1563 PFID(mdt_object_fid(child)), rc);
1564 mdt_clear_disposition(info, ldlm_rep, DISP_OPEN_CREATE);
1570 mdt_object_open_unlock(info, child, lhc, ibits, result);
1572 mdt_object_put(info->mti_env, child);
1574 mdt_object_unlock_put(info, parent, lh, result || !created);
1577 lustre_msg_set_transno(req->rq_repmsg, 0);
1582 * Create an orphan object use local root.
1584 static struct mdt_object *mdt_orphan_open(struct mdt_thread_info *info,
1585 struct mdt_device *mdt,
1586 const struct lu_fid *fid,
1587 struct md_attr *attr, fmode_t fmode)
1589 const struct lu_env *env = info->mti_env;
1590 struct md_op_spec *spec = &info->mti_spec;
1591 struct lu_fid *local_root_fid = &info->mti_tmp_fid1;
1592 struct mdt_object *obj = NULL;
1593 struct mdt_object *local_root;
1594 static const struct lu_name lname = {
1595 .ln_name = "i_am_nobody",
1596 .ln_namelen = sizeof("i_am_nobody") - 1,
1598 struct lu_ucred *uc;
1599 cfs_cap_t uc_cap_save;
1603 rc = dt_root_get(env, mdt->mdt_bottom, local_root_fid);
1605 RETURN(ERR_PTR(rc));
1607 local_root = mdt_object_find(env, mdt, local_root_fid);
1608 if (IS_ERR(local_root))
1611 obj = mdt_object_new(env, mdt, fid);
1613 GOTO(out, rc = PTR_ERR(obj));
1615 spec->sp_cr_lookup = 0;
1616 spec->sp_feat = &dt_directory_features;
1617 spec->sp_cr_mode = MDL_MINMODE; /* no lock */
1618 spec->sp_cr_flags = MDS_OPEN_VOLATILE | fmode;
1619 if (attr->ma_valid & MA_LOV) {
1620 spec->u.sp_ea.eadata = attr->ma_lmm;
1621 spec->u.sp_ea.eadatalen = attr->ma_lmm_size;
1622 spec->sp_cr_flags |= MDS_OPEN_HAS_EA;
1624 spec->sp_cr_flags |= MDS_OPEN_DELAY_CREATE;
1628 uc_cap_save = uc->uc_cap;
1629 uc->uc_cap |= 1 << CFS_CAP_DAC_OVERRIDE;
1630 rc = mdo_create(env, mdt_object_child(local_root), &lname,
1631 mdt_object_child(obj), spec, attr);
1632 uc->uc_cap = uc_cap_save;
1634 CERROR("%s: cannot create volatile file "DFID": rc = %d\n",
1635 mdt_obd_name(mdt), PFID(fid), rc);
1639 rc = mo_open(env, mdt_object_child(obj), MDS_OPEN_CREATED);
1641 CERROR("%s: cannot open volatile file "DFID", orphan "
1642 "file will be left in PENDING directory until "
1643 "next reboot, rc = %d\n", mdt_obd_name(mdt),
1650 mdt_object_put(env, obj);
1653 mdt_object_put(env, local_root);
1657 static int mdt_hsm_release(struct mdt_thread_info *info, struct mdt_object *o,
1660 struct mdt_lock_handle *lh = &info->mti_lh[MDT_LH_LAYOUT];
1661 struct close_data *data;
1662 struct ldlm_lock *lease;
1663 struct mdt_object *orphan;
1664 struct md_attr *orp_ma;
1671 if (exp_connect_flags(info->mti_exp) & OBD_CONNECT_RDONLY)
1674 data = req_capsule_client_get(info->mti_pill, &RMF_CLOSE_DATA);
1678 lease = ldlm_handle2lock(&data->cd_handle);
1682 /* try to hold open_sem so that nobody else can open the file */
1683 if (!down_write_trylock(&o->mot_open_sem)) {
1684 ldlm_lock_cancel(lease);
1685 GOTO(out_reprocess, rc = -EBUSY);
1688 /* Check if the lease open lease has already canceled */
1689 lock_res_and_lock(lease);
1690 lease_broken = ldlm_is_cancel(lease);
1691 unlock_res_and_lock(lease);
1693 LDLM_DEBUG(lease, DFID " lease broken? %d",
1694 PFID(mdt_object_fid(o)), lease_broken);
1696 /* Cancel server side lease. Client side counterpart should
1697 * have been cancelled. It's okay to cancel it now as we've
1698 * held mot_open_sem. */
1699 ldlm_lock_cancel(lease);
1701 if (lease_broken) /* don't perform release task */
1702 GOTO(out_unlock, rc = -ESTALE);
1704 if (fid_is_zero(&data->cd_fid) || !fid_is_sane(&data->cd_fid))
1705 GOTO(out_unlock, rc = -EINVAL);
1707 /* ma_need was set before but it seems fine to change it in order to
1708 * avoid modifying the one from RPC */
1709 ma->ma_need = MA_HSM;
1710 rc = mdt_attr_get_complex(info, o, ma);
1712 GOTO(out_unlock, rc);
1714 if (!mdt_hsm_release_allow(ma))
1715 GOTO(out_unlock, rc = -EPERM);
1717 /* already released? */
1718 if (ma->ma_hsm.mh_flags & HS_RELEASED)
1719 GOTO(out_unlock, rc = 0);
1721 /* Compare on-disk and packed data_version */
1722 if (data->cd_data_version != ma->ma_hsm.mh_arch_ver) {
1723 CDEBUG(D_HSM, DFID" data_version mismatches: packed=%llu"
1724 " and on-disk=%llu\n", PFID(mdt_object_fid(o)),
1725 data->cd_data_version, ma->ma_hsm.mh_arch_ver);
1726 GOTO(out_unlock, rc = -EPERM);
1729 ma->ma_valid = MA_INODE;
1730 ma->ma_attr.la_valid &= LA_ATIME | LA_MTIME | LA_CTIME | LA_SIZE;
1731 rc = mo_attr_set(info->mti_env, mdt_object_child(o), ma);
1733 GOTO(out_unlock, rc);
1735 ma->ma_need = MA_INODE | MA_LOV;
1736 rc = mdt_attr_get_complex(info, o, ma);
1738 GOTO(out_unlock, rc);
1740 if (!(ma->ma_valid & MA_LOV)) {
1741 /* Even empty file are released */
1742 memset(ma->ma_lmm, 0, sizeof(*ma->ma_lmm));
1743 ma->ma_lmm->lmm_magic = cpu_to_le32(LOV_MAGIC_V1_DEF);
1744 ma->ma_lmm->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
1745 ma->ma_lmm->lmm_stripe_size = cpu_to_le32(LOV_MIN_STRIPE_SIZE);
1746 ma->ma_lmm_size = sizeof(*ma->ma_lmm);
1748 /* Magic must be LOV_MAGIC_Vx_DEF otherwise LOD will interpret
1749 * ma_lmm as lov_user_md, then it will be confused by union of
1750 * layout_gen and stripe_offset. */
1751 if (le32_to_cpu(ma->ma_lmm->lmm_magic) == LOV_MAGIC_V1)
1752 ma->ma_lmm->lmm_magic = cpu_to_le32(LOV_MAGIC_V1_DEF);
1753 else if (le32_to_cpu(ma->ma_lmm->lmm_magic) == LOV_MAGIC_V3)
1754 ma->ma_lmm->lmm_magic = cpu_to_le32(LOV_MAGIC_V3_DEF);
1756 GOTO(out_unlock, rc = -EINVAL);
1759 /* Set file as released */
1760 ma->ma_lmm->lmm_pattern |= cpu_to_le32(LOV_PATTERN_F_RELEASED);
1762 orp_ma = &info->mti_u.hsm.attr;
1763 orp_ma->ma_attr.la_mode = S_IFREG | S_IWUSR;
1764 orp_ma->ma_attr.la_uid = ma->ma_attr.la_uid;
1765 orp_ma->ma_attr.la_gid = ma->ma_attr.la_gid;
1766 orp_ma->ma_attr.la_valid = LA_MODE | LA_UID | LA_GID;
1767 orp_ma->ma_lmm = ma->ma_lmm;
1768 orp_ma->ma_lmm_size = ma->ma_lmm_size;
1769 orp_ma->ma_valid = MA_INODE | MA_LOV;
1770 orphan = mdt_orphan_open(info, info->mti_mdt, &data->cd_fid, orp_ma,
1772 if (IS_ERR(orphan)) {
1773 CERROR("%s: cannot open orphan file "DFID": rc = %ld\n",
1774 mdt_obd_name(info->mti_mdt), PFID(&data->cd_fid),
1776 GOTO(out_unlock, rc = PTR_ERR(orphan));
1779 /* Set up HSM attribute for orphan object */
1780 CLASSERT(sizeof(struct hsm_attrs) <= sizeof(info->mti_xattr_buf));
1781 buf = &info->mti_buf;
1782 buf->lb_buf = info->mti_xattr_buf;
1783 buf->lb_len = sizeof(struct hsm_attrs);
1784 ma->ma_hsm.mh_flags |= HS_RELEASED;
1785 lustre_hsm2buf(buf->lb_buf, &ma->ma_hsm);
1786 ma->ma_hsm.mh_flags &= ~HS_RELEASED;
1788 mdt_lock_reg_init(lh, LCK_EX);
1789 rc = mdt_object_lock(info, o, lh, MDS_INODELOCK_LAYOUT |
1790 MDS_INODELOCK_XATTR);
1792 GOTO(out_close, rc);
1794 rc = mo_xattr_set(info->mti_env, mdt_object_child(orphan), buf,
1798 /* Swap layout with orphan object */
1799 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o),
1800 mdt_object_child(orphan),
1801 SWAP_LAYOUTS_MDS_HSM);
1803 /* Release exclusive LL */
1804 mdt_object_unlock(info, o, lh, 1);
1809 /* Close orphan object anyway */
1810 rc2 = mo_close(info->mti_env, mdt_object_child(orphan), orp_ma,
1813 CERROR("%s: error closing volatile file "DFID": rc = %d\n",
1814 mdt_obd_name(info->mti_mdt), PFID(&data->cd_fid), rc2);
1815 LU_OBJECT_DEBUG(D_HSM, info->mti_env, &orphan->mot_obj,
1817 mdt_object_put(info->mti_env, orphan);
1820 up_write(&o->mot_open_sem);
1822 /* already released */
1824 struct mdt_body *repbody;
1826 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1827 LASSERT(repbody != NULL);
1828 repbody->mbo_valid |= OBD_MD_CLOSE_INTENT_EXECED;
1832 ldlm_reprocess_all(lease->l_resource);
1833 LDLM_LOCK_PUT(lease);
1841 int mdt_close_swap_layouts(struct mdt_thread_info *info,
1842 struct mdt_object *o, struct md_attr *ma)
1844 struct mdt_lock_handle *lh1 = &info->mti_lh[MDT_LH_NEW];
1845 struct mdt_lock_handle *lh2 = &info->mti_lh[MDT_LH_OLD];
1846 struct close_data *data;
1847 struct ldlm_lock *lease;
1848 struct mdt_object *o1 = o, *o2;
1854 if (exp_connect_flags(info->mti_exp) & OBD_CONNECT_RDONLY)
1857 if (!S_ISREG(lu_object_attr(&o1->mot_obj)))
1860 data = req_capsule_client_get(info->mti_pill, &RMF_CLOSE_DATA);
1864 if (fid_is_zero(&data->cd_fid) || !fid_is_sane(&data->cd_fid))
1867 rc = lu_fid_cmp(&data->cd_fid, mdt_object_fid(o));
1868 if (unlikely(rc == 0))
1871 /* Exchange o1 and o2, to enforce locking order */
1872 swap_objects = (rc < 0);
1874 lease = ldlm_handle2lock(&data->cd_handle);
1878 o2 = mdt_object_find(info->mti_env, info->mti_mdt, &data->cd_fid);
1880 GOTO(out_lease, rc = PTR_ERR(o2));
1882 if (!S_ISREG(lu_object_attr(&o2->mot_obj))) {
1883 swap_objects = false; /* not swapped yet */
1884 GOTO(out_obj, rc = -EINVAL);
1890 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o1), NULL,
1895 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o2), NULL,
1900 /* try to hold open_sem so that nobody else can open the file */
1901 if (!down_write_trylock(&o->mot_open_sem)) {
1902 ldlm_lock_cancel(lease);
1903 GOTO(out_obj, rc = -EBUSY);
1906 /* Check if the lease open lease has already canceled */
1907 lock_res_and_lock(lease);
1908 lease_broken = ldlm_is_cancel(lease);
1909 unlock_res_and_lock(lease);
1911 LDLM_DEBUG(lease, DFID " lease broken? %d",
1912 PFID(mdt_object_fid(o)), lease_broken);
1914 /* Cancel server side lease. Client side counterpart should
1915 * have been cancelled. It's okay to cancel it now as we've
1916 * held mot_open_sem. */
1917 ldlm_lock_cancel(lease);
1920 GOTO(out_unlock_sem, rc = -ESTALE);
1922 mdt_lock_reg_init(lh1, LCK_EX);
1923 rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT |
1924 MDS_INODELOCK_XATTR);
1926 GOTO(out_unlock_sem, rc);
1928 mdt_lock_reg_init(lh2, LCK_EX);
1929 rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT |
1930 MDS_INODELOCK_XATTR);
1932 GOTO(out_unlock1, rc);
1934 /* Swap layout with orphan object */
1935 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
1936 mdt_object_child(o2), 0);
1938 GOTO(out_unlock2, rc);
1943 /* Release exclusive LL */
1944 mdt_object_unlock(info, o2, lh2, 1);
1947 mdt_object_unlock(info, o1, lh1, 1);
1950 up_write(&o->mot_open_sem);
1952 /* already swapped */
1954 struct mdt_body *repbody;
1956 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1957 LASSERT(repbody != NULL);
1958 repbody->mbo_valid |= OBD_MD_CLOSE_INTENT_EXECED;
1962 mdt_object_put(info->mti_env, swap_objects ? o1 : o2);
1964 ldlm_reprocess_all(lease->l_resource);
1967 LDLM_LOCK_PUT(lease);
1977 #define MFD_CLOSED(mode) ((mode) == MDS_FMODE_CLOSED)
1978 static int mdt_mfd_closed(struct mdt_file_data *mfd)
1980 return ((mfd == NULL) || MFD_CLOSED(mfd->mfd_mode));
1983 int mdt_mfd_close(struct mdt_thread_info *info, struct mdt_file_data *mfd)
1985 struct mdt_object *o = mfd->mfd_object;
1986 struct md_object *next = mdt_object_child(o);
1987 struct md_attr *ma = &info->mti_attr;
1992 mode = mfd->mfd_mode;
1994 if (ma->ma_attr_flags & MDS_HSM_RELEASE) {
1995 rc = mdt_hsm_release(info, o, ma);
1997 CDEBUG(D_HSM, "%s: File " DFID " release failed: %d\n",
1998 mdt_obd_name(info->mti_mdt),
1999 PFID(mdt_object_fid(o)), rc);
2000 /* continue to close even error occurred. */
2004 if (ma->ma_attr_flags & MDS_CLOSE_LAYOUT_SWAP) {
2005 rc = mdt_close_swap_layouts(info, o, ma);
2008 "%s: cannot swap layout of "DFID": rc=%d\n",
2009 mdt_obd_name(info->mti_mdt),
2010 PFID(mdt_object_fid(o)), rc);
2011 /* continue to close even if error occurred. */
2015 if (mode & FMODE_WRITE)
2017 else if (mode & MDS_FMODE_EXEC)
2020 /* Update atime on close only. */
2021 if ((mode & MDS_FMODE_EXEC || mode & FMODE_READ || mode & FMODE_WRITE)
2022 && (ma->ma_valid & MA_INODE) && (ma->ma_attr.la_valid & LA_ATIME)) {
2023 /* Set the atime only. */
2024 ma->ma_valid = MA_INODE;
2025 ma->ma_attr.la_valid = LA_ATIME;
2026 rc = mo_attr_set(info->mti_env, next, ma);
2029 /* If file data is modified, add the dirty flag. */
2030 if (ma->ma_attr_flags & MDS_DATA_MODIFIED)
2031 rc = mdt_add_dirty_flag(info, o, ma);
2033 ma->ma_need |= MA_INODE;
2034 ma->ma_valid &= ~MA_INODE;
2036 if (!MFD_CLOSED(mode))
2037 rc = mo_close(info->mti_env, next, ma, mode);
2039 /* adjust open and lease count */
2040 if (mode & MDS_OPEN_LEASE) {
2041 LASSERT(atomic_read(&o->mot_lease_count) > 0);
2042 atomic_dec(&o->mot_lease_count);
2045 LASSERT(atomic_read(&o->mot_open_count) > 0);
2046 atomic_dec(&o->mot_open_count);
2048 mdt_object_put(info->mti_env, o);
2053 int mdt_close_internal(struct mdt_thread_info *info, struct ptlrpc_request *req,
2054 struct mdt_body *repbody)
2056 struct mdt_export_data *med;
2057 struct mdt_file_data *mfd;
2058 struct mdt_object *o;
2059 struct md_attr *ma = &info->mti_attr;
2064 med = &req->rq_export->exp_mdt_data;
2065 spin_lock(&med->med_open_lock);
2066 mfd = mdt_handle2mfd(med, &info->mti_close_handle, req_is_replay(req));
2067 if (mdt_mfd_closed(mfd)) {
2068 spin_unlock(&med->med_open_lock);
2069 CDEBUG(D_INODE, "no handle for file close: fid = "DFID
2070 ": cookie = %#llx\n", PFID(info->mti_rr.rr_fid1),
2071 info->mti_close_handle.cookie);
2072 /** not serious error since bug 3633 */
2075 class_handle_unhash(&mfd->mfd_handle);
2076 list_del_init(&mfd->mfd_list);
2077 spin_unlock(&med->med_open_lock);
2079 /* Do not lose object before last unlink. */
2080 o = mfd->mfd_object;
2081 mdt_object_get(info->mti_env, o);
2082 ret = mdt_mfd_close(info, mfd);
2083 if (repbody != NULL)
2084 rc = mdt_handle_last_unlink(info, o, ma);
2085 mdt_object_put(info->mti_env, o);
2088 RETURN(rc ? rc : ret);
2091 int mdt_close(struct tgt_session_info *tsi)
2093 struct mdt_thread_info *info = tsi2mdt_info(tsi);
2094 struct ptlrpc_request *req = tgt_ses_req(tsi);
2095 struct md_attr *ma = &info->mti_attr;
2096 struct mdt_body *repbody = NULL;
2100 mdt_counter_incr(req, LPROC_MDT_CLOSE);
2101 /* Close may come with the Size-on-MDS update. Unpack it. */
2102 rc = mdt_close_unpack(info);
2104 GOTO(out, rc = err_serious(rc));
2106 /* These fields are no longer used and are left for compatibility.
2107 * size is always zero */
2108 req_capsule_set_size(info->mti_pill, &RMF_MDT_MD, RCL_SERVER,
2110 req_capsule_set_size(info->mti_pill, &RMF_LOGCOOKIES, RCL_SERVER,
2112 rc = req_capsule_server_pack(info->mti_pill);
2113 if (mdt_check_resent(info, mdt_reconstruct_generic, NULL)) {
2114 mdt_client_compatibility(info);
2116 mdt_fix_reply(info);
2117 mdt_exit_ucred(info);
2118 GOTO(out, rc = lustre_msg_get_status(req->rq_repmsg));
2121 /* Continue to close handle even if we can not pack reply */
2123 repbody = req_capsule_server_get(info->mti_pill,
2125 ma->ma_lmm = req_capsule_server_get(info->mti_pill,
2127 ma->ma_lmm_size = req_capsule_get_size(info->mti_pill,
2130 ma->ma_need = MA_INODE | MA_LOV;
2131 repbody->mbo_eadatasize = 0;
2132 repbody->mbo_aclsize = 0;
2134 rc = err_serious(rc);
2137 rc = mdt_close_internal(info, req, repbody);
2139 mdt_empty_transno(info, rc);
2141 if (repbody != NULL) {
2142 mdt_client_compatibility(info);
2143 rc = mdt_fix_reply(info);
2146 mdt_exit_ucred(info);
2147 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK))
2148 GOTO(out, rc = err_serious(-ENOMEM));
2150 if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MDS_CLOSE_NET_REP,
2151 OBD_FAIL_MDS_CLOSE_NET_REP))
2152 tsi->tsi_reply_fail_id = OBD_FAIL_MDS_CLOSE_NET_REP;
2154 mdt_thread_info_fini(info);
2155 RETURN(rc ? rc : ret);