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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mdt/mdt_open.c
34 * Lustre Metadata Target (mdt) open/close file handling
36 * Author: Huang Hua <huanghua@clusterfs.com>
39 #define DEBUG_SUBSYSTEM S_MDS
41 #include <lustre_acl.h>
42 #include <lustre_mds.h>
43 #include "mdt_internal.h"
44 #include <lustre_nodemap.h>
46 /* we do nothing because we do not have refcount now */
47 static void mdt_mfd_get(void *mfdp)
51 static struct portals_handle_ops mfd_handle_ops = {
52 .hop_addref = mdt_mfd_get,
56 /* Create a new mdt_file_data struct, initialize it,
57 * and insert it to global hash table */
58 struct mdt_file_data *mdt_mfd_new(const struct mdt_export_data *med)
60 struct mdt_file_data *mfd;
65 INIT_LIST_HEAD(&mfd->mfd_handle.h_link);
66 mfd->mfd_handle.h_owner = med;
67 INIT_LIST_HEAD(&mfd->mfd_list);
68 class_handle_hash(&mfd->mfd_handle, &mfd_handle_ops);
75 * Find the mfd pointed to by handle in global hash table.
76 * In case of replay the handle is obsoleted
77 * but mfd can be found in mfd list by that handle.
78 * Callers need to be holding med_open_lock.
80 struct mdt_file_data *mdt_handle2mfd(struct mdt_export_data *med,
81 const struct lustre_handle *handle,
82 bool is_replay_or_resent)
84 struct mdt_file_data *mfd;
87 LASSERT(handle != NULL);
88 mfd = class_handle2object(handle->cookie, med);
89 /* during dw/setattr replay the mfd can be found by old handle */
90 if (mfd == NULL && is_replay_or_resent) {
91 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
92 if (mfd->mfd_old_handle.cookie == handle->cookie)
102 void mdt_mfd_free(struct mdt_file_data *mfd)
104 LASSERT(list_empty(&mfd->mfd_list));
105 OBD_FREE_RCU(mfd, sizeof *mfd, &mfd->mfd_handle);
108 static int mdt_create_data(struct mdt_thread_info *info,
109 struct mdt_object *p, struct mdt_object *o)
111 struct md_op_spec *spec = &info->mti_spec;
112 struct md_attr *ma = &info->mti_attr;
116 if (!md_should_create(spec->sp_cr_flags))
119 ma->ma_need = MA_INODE | MA_LOV;
121 mutex_lock(&o->mot_lov_mutex);
122 if (!o->mot_lov_created) {
123 rc = mdo_create_data(info->mti_env,
124 p ? mdt_object_child(p) : NULL,
125 mdt_object_child(o), spec, ma);
127 rc = mdt_attr_get_complex(info, o, ma);
129 if (rc == 0 && ma->ma_valid & MA_LOV)
130 o->mot_lov_created = 1;
133 mutex_unlock(&o->mot_lov_mutex);
137 int mdt_write_read(struct mdt_object *o)
141 spin_lock(&o->mot_write_lock);
142 rc = o->mot_write_count;
143 spin_unlock(&o->mot_write_lock);
147 int mdt_write_get(struct mdt_object *o)
151 spin_lock(&o->mot_write_lock);
152 if (o->mot_write_count < 0)
155 o->mot_write_count++;
156 spin_unlock(&o->mot_write_lock);
161 void mdt_write_put(struct mdt_object *o)
164 spin_lock(&o->mot_write_lock);
165 o->mot_write_count--;
166 spin_unlock(&o->mot_write_lock);
170 static int mdt_write_deny(struct mdt_object *o)
174 spin_lock(&o->mot_write_lock);
175 if (o->mot_write_count > 0)
178 o->mot_write_count--;
179 spin_unlock(&o->mot_write_lock);
183 static void mdt_write_allow(struct mdt_object *o)
186 spin_lock(&o->mot_write_lock);
187 o->mot_write_count++;
188 spin_unlock(&o->mot_write_lock);
192 /* there can be no real transaction so prepare the fake one */
193 static void mdt_empty_transno(struct mdt_thread_info *info, int rc)
195 struct mdt_device *mdt = info->mti_mdt;
196 struct ptlrpc_request *req = mdt_info_req(info);
197 struct tg_export_data *ted;
198 struct lsd_client_data *lcd;
201 if (mdt_rdonly(req->rq_export))
204 /* transaction has occurred already */
205 if (lustre_msg_get_transno(req->rq_repmsg) != 0)
208 if (tgt_is_multimodrpcs_client(req->rq_export)) {
211 /* generate an empty transaction to get a transno
213 th = dt_trans_create(info->mti_env, mdt->mdt_bottom);
215 rc = dt_trans_start(info->mti_env, mdt->mdt_bottom, th);
216 dt_trans_stop(info->mti_env, mdt->mdt_bottom, th);
221 spin_lock(&mdt->mdt_lut.lut_translock);
223 if (info->mti_transno != 0) {
224 struct obd_export *exp = req->rq_export;
226 CERROR("%s: replay trans %llu NID %s: rc = %d\n",
227 mdt_obd_name(mdt), info->mti_transno,
228 libcfs_nid2str(exp->exp_connection->c_peer.nid),
230 spin_unlock(&mdt->mdt_lut.lut_translock);
233 } else if (info->mti_transno == 0) {
234 info->mti_transno = ++mdt->mdt_lut.lut_last_transno;
236 /* should be replay */
237 if (info->mti_transno > mdt->mdt_lut.lut_last_transno)
238 mdt->mdt_lut.lut_last_transno = info->mti_transno;
240 spin_unlock(&mdt->mdt_lut.lut_translock);
242 CDEBUG(D_INODE, "transno = %llu, last_committed = %llu\n",
244 req->rq_export->exp_obd->obd_last_committed);
246 req->rq_transno = info->mti_transno;
247 lustre_msg_set_transno(req->rq_repmsg, info->mti_transno);
249 /* update lcd in memory only for resent cases */
250 ted = &req->rq_export->exp_target_data;
252 mutex_lock(&ted->ted_lcd_lock);
254 if (info->mti_transno < lcd->lcd_last_transno &&
255 info->mti_transno != 0) {
256 /* This should happen during replay. Do not update
257 * last rcvd info if replay req transno < last transno,
258 * otherwise the following resend(after replay) can not
259 * be checked correctly by xid */
260 mutex_unlock(&ted->ted_lcd_lock);
261 CDEBUG(D_HA, "%s: transno = %llu < last_transno = %llu\n",
262 mdt_obd_name(mdt), info->mti_transno,
263 lcd->lcd_last_transno);
267 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE) {
268 if (info->mti_transno != 0)
269 lcd->lcd_last_close_transno = info->mti_transno;
270 lcd->lcd_last_close_xid = req->rq_xid;
271 lcd->lcd_last_close_result = rc;
273 /* VBR: save versions in last_rcvd for reconstruct. */
274 __u64 *pre_versions = lustre_msg_get_versions(req->rq_repmsg);
276 lcd->lcd_pre_versions[0] = pre_versions[0];
277 lcd->lcd_pre_versions[1] = pre_versions[1];
278 lcd->lcd_pre_versions[2] = pre_versions[2];
279 lcd->lcd_pre_versions[3] = pre_versions[3];
281 if (info->mti_transno != 0)
282 lcd->lcd_last_transno = info->mti_transno;
284 lcd->lcd_last_xid = req->rq_xid;
285 lcd->lcd_last_result = rc;
286 lcd->lcd_last_data = info->mti_opdata;
288 mutex_unlock(&ted->ted_lcd_lock);
293 void mdt_mfd_set_mode(struct mdt_file_data *mfd, __u64 mode)
295 LASSERT(mfd != NULL);
297 CDEBUG(D_DENTRY, DFID " Change mfd mode %#llo -> %#llo.\n",
298 PFID(mdt_object_fid(mfd->mfd_object)), mfd->mfd_mode, mode);
300 mfd->mfd_mode = mode;
304 * prep ma_lmm/ma_lmv for md_attr from reply
306 static void mdt_prep_ma_buf_from_rep(struct mdt_thread_info *info,
307 struct mdt_object *obj,
310 LASSERT(ma->ma_lmv == NULL && ma->ma_lmm == NULL);
311 if (S_ISDIR(obj->mot_header.loh_attr)) {
312 ma->ma_lmv = req_capsule_server_get(info->mti_pill,
314 ma->ma_lmv_size = req_capsule_get_size(info->mti_pill,
317 if (ma->ma_lmv_size > 0)
318 ma->ma_need |= MA_LMV;
320 ma->ma_lmm = req_capsule_server_get(info->mti_pill,
322 ma->ma_lmm_size = req_capsule_get_size(info->mti_pill,
325 if (ma->ma_lmm_size > 0)
326 ma->ma_need |= MA_LOV;
330 static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p,
331 struct mdt_object *o, __u64 flags, int created,
332 struct ldlm_reply *rep)
334 struct ptlrpc_request *req = mdt_info_req(info);
335 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
336 struct mdt_file_data *mfd;
337 struct md_attr *ma = &info->mti_attr;
338 struct lu_attr *la = &ma->ma_attr;
339 struct mdt_body *repbody;
340 int rc = 0, isdir, isreg;
343 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
345 isreg = S_ISREG(la->la_mode);
346 isdir = S_ISDIR(la->la_mode);
347 if (isreg && !(ma->ma_valid & MA_LOV) && !(flags & MDS_OPEN_RELEASE)) {
349 * No EA, check whether it is will set regEA and dirEA since in
350 * above attr get, these size might be zero, so reset it, to
351 * retrieve the MD after create obj.
353 ma->ma_lmm_size = req_capsule_get_size(info->mti_pill,
356 /* in replay case, p == NULL */
357 rc = mdt_create_data(info, p, o);
361 if (exp_connect_flags(req->rq_export) & OBD_CONNECT_DISP_STRIPE)
362 mdt_set_disposition(info, rep, DISP_OPEN_STRIPE);
365 CDEBUG(D_INODE, "after open, ma_valid bit = %#llx lmm_size = %d\n",
366 ma->ma_valid, ma->ma_lmm_size);
368 if (ma->ma_valid & MA_LOV) {
369 LASSERT(ma->ma_lmm_size != 0);
370 repbody->mbo_eadatasize = ma->ma_lmm_size;
372 repbody->mbo_valid |= OBD_MD_FLDIREA;
374 repbody->mbo_valid |= OBD_MD_FLEASIZE;
377 if (ma->ma_valid & MA_LMV) {
378 LASSERT(ma->ma_lmv_size != 0);
379 repbody->mbo_eadatasize = ma->ma_lmv_size;
381 repbody->mbo_valid |= OBD_MD_FLDIREA | OBD_MD_MEA;
384 if (flags & FMODE_WRITE)
385 rc = mdt_write_get(o);
386 else if (flags & MDS_FMODE_EXEC)
387 rc = mdt_write_deny(o);
392 rc = mo_open(info->mti_env, mdt_object_child(o),
393 created ? flags | MDS_OPEN_CREATED : flags);
395 /* If we allow the client to chgrp (CFS_SETGRP_PERM), but the
396 * client does not know which suppgid should be sent to the MDS,
397 * or some other(s) changed the target file's GID after this RPC
398 * sent to the MDS with the suppgid as the original GID, then we
399 * give the client another chance to send the right suppgid. */
401 allow_client_chgrp(info, lu_ucred(info->mti_env)))
402 mdt_set_disposition(info, rep, DISP_OPEN_DENY);
407 mfd = mdt_mfd_new(med);
409 GOTO(err_out, rc = -ENOMEM);
412 * Keep a reference on this object for this open, and is
413 * released by mdt_mfd_close().
415 mdt_object_get(info->mti_env, o);
417 mfd->mfd_xid = req->rq_xid;
420 * @flags is always not zero. At least it should be FMODE_READ,
421 * FMODE_WRITE or MDS_FMODE_EXEC.
426 mdt_mfd_set_mode(mfd, flags);
428 atomic_inc(&o->mot_open_count);
429 if (flags & MDS_OPEN_LEASE)
430 atomic_inc(&o->mot_lease_count);
433 if (req_is_replay(req)) {
434 struct mdt_file_data *old_mfd;
435 /* Check wheather old cookie already exist in
436 * the list, becasue when do recovery, client
437 * might be disconnected from server, and
438 * restart replay, so there maybe some orphan
439 * mfd here, we should remove them */
440 LASSERT(info->mti_rr.rr_handle != NULL);
441 spin_lock(&med->med_open_lock);
442 old_mfd = mdt_handle2mfd(med, info->mti_rr.rr_handle, true);
443 if (old_mfd != NULL) {
444 CDEBUG(D_HA, "delete orphan mfd = %p, fid = "DFID", "
445 "cookie = %#llx\n", mfd,
446 PFID(mdt_object_fid(mfd->mfd_object)),
447 info->mti_rr.rr_handle->cookie);
448 class_handle_unhash(&old_mfd->mfd_handle);
449 list_del_init(&old_mfd->mfd_list);
450 spin_unlock(&med->med_open_lock);
451 /* no attr update for that close */
453 ma->ma_valid |= MA_FLAGS;
454 ma->ma_attr_flags |= MDS_RECOV_OPEN;
455 mdt_mfd_close(info, old_mfd);
456 ma->ma_attr_flags &= ~MDS_RECOV_OPEN;
457 ma->ma_valid &= ~MA_FLAGS;
459 spin_unlock(&med->med_open_lock);
460 CDEBUG(D_HA, "orphan mfd not found, fid = "DFID", "
462 PFID(mdt_object_fid(mfd->mfd_object)),
463 info->mti_rr.rr_handle->cookie);
466 CDEBUG(D_HA, "Store old cookie %#llx in new mfd\n",
467 info->mti_rr.rr_handle->cookie);
469 mfd->mfd_old_handle.cookie = info->mti_rr.rr_handle->cookie;
472 repbody->mbo_handle.cookie = mfd->mfd_handle.h_cookie;
474 if (req->rq_export->exp_disconnected) {
475 spin_lock(&med->med_open_lock);
476 class_handle_unhash(&mfd->mfd_handle);
477 list_del_init(&mfd->mfd_list);
478 spin_unlock(&med->med_open_lock);
479 mdt_mfd_close(info, mfd);
481 spin_lock(&med->med_open_lock);
482 list_add_tail(&mfd->mfd_list, &med->med_open_head);
483 spin_unlock(&med->med_open_lock);
486 mdt_empty_transno(info, rc);
491 if (flags & FMODE_WRITE)
493 else if (flags & MDS_FMODE_EXEC)
499 static int mdt_finish_open(struct mdt_thread_info *info,
500 struct mdt_object *p, struct mdt_object *o,
501 __u64 flags, int created, struct ldlm_reply *rep)
503 struct ptlrpc_request *req = mdt_info_req(info);
504 struct obd_export *exp = req->rq_export;
505 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
506 struct md_attr *ma = &info->mti_attr;
507 struct lu_attr *la = &ma->ma_attr;
508 struct mdt_file_data *mfd;
509 struct mdt_body *repbody;
511 int isreg, isdir, islnk;
515 LASSERT(ma->ma_valid & MA_INODE);
517 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
519 isreg = S_ISREG(la->la_mode);
520 isdir = S_ISDIR(la->la_mode);
521 islnk = S_ISLNK(la->la_mode);
522 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
524 /* LU-2275, simulate broken behaviour (esp. prevalent in
525 * pre-2.4 servers where a very strange reply is sent on error
526 * that looks like it was actually almost successful and a
527 * failure at the same time.) */
528 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_NEGATIVE_POSITIVE)) {
529 mdt_set_disposition(info, rep, DISP_OPEN_OPEN |
533 if (flags & MDS_OPEN_LOCK)
534 mdt_set_disposition(info, rep, DISP_OPEN_LOCK);
539 #ifdef CONFIG_FS_POSIX_ACL
540 if (exp_connect_flags(exp) & OBD_CONNECT_ACL) {
541 struct lu_nodemap *nodemap = nodemap_get_from_exp(exp);
543 RETURN(PTR_ERR(nodemap));
545 rc = mdt_pack_acl2body(info, repbody, o, nodemap);
546 nodemap_putref(nodemap);
553 * If we are following a symlink, don't open; and do not return open
554 * handle for special nodes as client required.
556 if (islnk || (!isreg && !isdir &&
557 (exp_connect_flags(req->rq_export) & OBD_CONNECT_NODEVOH))) {
558 lustre_msg_set_transno(req->rq_repmsg, 0);
563 * We need to return the existing object's fid back, so it is done here,
564 * after preparing the reply.
566 if (!created && (flags & MDS_OPEN_EXCL) && (flags & MDS_OPEN_CREAT))
569 /* This can't be done earlier, we need to return reply body */
571 if (flags & (MDS_OPEN_CREAT | FMODE_WRITE)) {
572 /* We are trying to create or write an existing dir. */
575 } else if (flags & MDS_OPEN_DIRECTORY)
578 if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MDS_OPEN_CREATE,
579 OBD_FAIL_LDLM_REPLY | OBD_FAIL_ONCE)) {
584 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
585 spin_lock(&med->med_open_lock);
586 list_for_each(t, &med->med_open_head) {
587 mfd = list_entry(t, struct mdt_file_data, mfd_list);
588 if (mfd->mfd_xid == req->rq_xid)
592 spin_unlock(&med->med_open_lock);
595 repbody->mbo_handle.cookie = mfd->mfd_handle.h_cookie;
596 /* set repbody->ea_size for resent case */
597 if (ma->ma_valid & MA_LOV) {
598 LASSERT(ma->ma_lmm_size != 0);
599 repbody->mbo_eadatasize = ma->ma_lmm_size;
601 repbody->mbo_valid |= OBD_MD_FLDIREA;
603 repbody->mbo_valid |= OBD_MD_FLEASIZE;
605 mdt_set_disposition(info, rep, DISP_OPEN_OPEN);
610 rc = mdt_mfd_open(info, p, o, flags, created, rep);
612 mdt_set_disposition(info, rep, DISP_OPEN_OPEN);
617 void mdt_reconstruct_open(struct mdt_thread_info *info,
618 struct mdt_lock_handle *lhc)
620 const struct lu_env *env = info->mti_env;
621 struct mdt_device *mdt = info->mti_mdt;
622 struct req_capsule *pill = info->mti_pill;
623 struct ptlrpc_request *req = mdt_info_req(info);
624 struct md_attr *ma = &info->mti_attr;
625 struct mdt_reint_record *rr = &info->mti_rr;
626 __u64 flags = info->mti_spec.sp_cr_flags;
627 struct ldlm_reply *ldlm_rep;
628 struct mdt_object *parent;
629 struct mdt_object *child;
630 struct mdt_body *repbody;
635 LASSERT(pill->rc_fmt == &RQF_LDLM_INTENT_OPEN);
636 ldlm_rep = req_capsule_server_get(pill, &RMF_DLM_REP);
637 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
639 ma->ma_need = MA_INODE | MA_HSM;
642 opdata = mdt_req_from_lrd(req, info->mti_reply_data);
643 mdt_set_disposition(info, ldlm_rep, opdata);
645 CDEBUG(D_INODE, "This is reconstruct open: disp=%#llx, result=%d\n",
646 ldlm_rep->lock_policy_res1, req->rq_status);
648 if (mdt_get_disposition(ldlm_rep, DISP_OPEN_CREATE) &&
650 /* We did not create successfully, return error to client. */
651 GOTO(out, rc = req->rq_status);
653 if (mdt_get_disposition(ldlm_rep, DISP_OPEN_CREATE)) {
654 struct obd_export *exp = req->rq_export;
656 * We failed after creation, but we do not know in which step
657 * we failed. So try to check the child object.
659 parent = mdt_object_find(env, mdt, rr->rr_fid1);
660 if (IS_ERR(parent)) {
661 rc = PTR_ERR(parent);
662 LCONSOLE_WARN("Parent "DFID" lookup error %d."
663 " Evicting client %s with export %s.\n",
664 PFID(rr->rr_fid1), rc,
665 obd_uuid2str(&exp->exp_client_uuid),
666 obd_export_nid2str(exp));
667 mdt_export_evict(exp);
671 child = mdt_object_find(env, mdt, rr->rr_fid2);
674 LCONSOLE_WARN("cannot lookup child "DFID": rc = %d; "
675 "evicting client %s with export %s\n",
676 PFID(rr->rr_fid2), rc,
677 obd_uuid2str(&exp->exp_client_uuid),
678 obd_export_nid2str(exp));
679 mdt_object_put(env, parent);
680 mdt_export_evict(exp);
684 if (unlikely(mdt_object_remote(child))) {
685 /* the child object was created on remote server */
686 if (!mdt_is_dne_client(exp)) {
687 /* Return -EIO for old client */
688 mdt_object_put(env, parent);
689 mdt_object_put(env, child);
690 GOTO(out, rc = -EIO);
692 repbody->mbo_fid1 = *rr->rr_fid2;
693 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
696 if (mdt_object_exists(child)) {
697 mdt_prep_ma_buf_from_rep(info, child, ma);
698 rc = mdt_attr_get_complex(info, child, ma);
700 rc = mdt_finish_open(info, parent,
704 /* the child does not exist, we should do
706 mdt_object_put(env, parent);
707 mdt_object_put(env, child);
708 GOTO(regular_open, 0);
711 mdt_object_put(env, parent);
712 mdt_object_put(env, child);
716 /* We did not try to create, so we are a pure open */
717 rc = mdt_reint_open(info, lhc);
723 lustre_msg_set_status(req->rq_repmsg, req->rq_status);
724 LASSERT(ergo(rc < 0, lustre_msg_get_transno(req->rq_repmsg) == 0));
727 static int mdt_open_by_fid(struct mdt_thread_info *info, struct ldlm_reply *rep)
729 __u64 flags = info->mti_spec.sp_cr_flags;
730 struct mdt_reint_record *rr = &info->mti_rr;
731 struct md_attr *ma = &info->mti_attr;
732 struct mdt_object *o;
736 o = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid2);
738 RETURN(rc = PTR_ERR(o));
740 if (unlikely(mdt_object_remote(o))) {
741 /* the child object was created on remote server */
742 struct mdt_body *repbody;
744 mdt_set_disposition(info, rep, (DISP_IT_EXECD |
747 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
748 repbody->mbo_fid1 = *rr->rr_fid2;
749 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
752 if (mdt_object_exists(o)) {
753 mdt_set_disposition(info, rep, (DISP_IT_EXECD |
756 mdt_prep_ma_buf_from_rep(info, o, ma);
757 rc = mdt_attr_get_complex(info, o, ma);
759 rc = mdt_finish_open(info, NULL, o, flags, 0,
766 mdt_object_put(info->mti_env, o);
770 /* lock object for open */
771 static int mdt_object_open_lock(struct mdt_thread_info *info,
772 struct mdt_object *obj,
773 struct mdt_lock_handle *lhc,
776 struct md_attr *ma = &info->mti_attr;
777 __u64 open_flags = info->mti_spec.sp_cr_flags;
778 enum ldlm_mode lm = LCK_CR;
779 bool acq_lease = !!(open_flags & MDS_OPEN_LEASE);
780 bool try_layout = false;
781 bool create_layout = false;
786 mdt_lock_handle_init(lhc);
788 if (req_is_replay(mdt_info_req(info)))
791 if (S_ISREG(lu_object_attr(&obj->mot_obj))) {
792 if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV) &&
793 md_should_create(open_flags))
794 create_layout = true;
795 if (exp_connect_layout(info->mti_exp) && !create_layout &&
796 ma->ma_need & MA_LOV)
801 /* lease open, acquire write mode of open sem */
802 down_write(&obj->mot_open_sem);
804 /* Lease exists and ask for new lease */
805 if (atomic_read(&obj->mot_lease_count) > 0) {
806 /* only exclusive open is supported, so lease
807 * are conflicted to each other */
808 GOTO(out, rc = -EBUSY);
811 /* Lease must be with open lock */
812 if (!(open_flags & MDS_OPEN_LOCK)) {
813 CERROR("%s: Request lease for file:"DFID ", but open lock "
814 "is missed, open_flags = %#llo : rc = %d\n",
815 mdt_obd_name(info->mti_mdt),
816 PFID(mdt_object_fid(obj)), open_flags, -EPROTO);
817 GOTO(out, rc = -EPROTO);
820 /* XXX: only exclusive open is supported. */
822 *ibits = MDS_INODELOCK_OPEN;
824 /* never grant LCK_EX layout lock to client */
826 } else { /* normal open */
827 /* normal open holds read mode of open sem */
828 down_read(&obj->mot_open_sem);
830 if (open_flags & MDS_OPEN_LOCK) {
831 if (open_flags & FMODE_WRITE)
833 else if (open_flags & MDS_FMODE_EXEC)
838 *ibits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_OPEN;
839 } else if (atomic_read(&obj->mot_lease_count) > 0) {
840 if (open_flags & FMODE_WRITE)
846 *ibits = MDS_INODELOCK_OPEN;
849 lhc = &info->mti_lh[MDT_LH_LOCAL];
851 CDEBUG(D_INODE, "normal open:"DFID" lease count: %d, lm: %d\n",
852 PFID(mdt_object_fid(obj)),
853 atomic_read(&obj->mot_open_count), lm);
856 mdt_lock_reg_init(lhc, lm);
858 /* one problem to return layout lock on open is that it may result
859 * in too many layout locks cached on the client side. */
860 if (!OBD_FAIL_CHECK(OBD_FAIL_MDS_NO_LL_OPEN) && try_layout) {
861 /* return lookup lock to validate inode at the client side,
862 * this is pretty important otherwise mdt will return layout
863 * lock for each open.
864 * However this is a double-edged sword because changing
865 * permission will revoke huge # of LOOKUP locks. */
866 rc = mdt_object_lock_try(info, obj, lhc, ibits,
867 MDS_INODELOCK_LAYOUT |
868 MDS_INODELOCK_LOOKUP, false);
869 } else if (*ibits != 0) {
870 rc = mdt_object_lock(info, obj, lhc, *ibits);
873 CDEBUG(D_INODE, "%s: Requested bits lock:"DFID ", ibits = %#llx"
874 ", open_flags = %#llo, try_layout = %d : rc = %d\n",
875 mdt_obd_name(info->mti_mdt), PFID(mdt_object_fid(obj)),
876 *ibits, open_flags, try_layout, rc);
878 /* will change layout, revoke layout locks by enqueuing EX lock. */
879 if (rc == 0 && create_layout) {
880 struct mdt_lock_handle *ll = &info->mti_lh[MDT_LH_LAYOUT];
882 CDEBUG(D_INODE, "Will create layout, get EX layout lock:"DFID
883 ", open_flags = %#llo\n",
884 PFID(mdt_object_fid(obj)), open_flags);
886 /* We cannot enqueue another lock for the same resource we
887 * already have a lock for, due to mechanics of waiting list
888 * iterating in ldlm, see LU-3601.
889 * As such we'll drop the open lock we just got above here,
890 * it's ok not to have this open lock as it's main purpose is to
891 * flush unused cached client open handles. */
892 if (lustre_handle_is_used(&lhc->mlh_reg_lh))
893 mdt_object_unlock(info, obj, lhc, 1);
895 LASSERT(!try_layout);
896 mdt_lock_handle_init(ll);
897 mdt_lock_reg_init(ll, LCK_EX);
898 rc = mdt_object_lock(info, obj, ll, MDS_INODELOCK_LAYOUT);
900 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_LL_BLOCK, 2);
903 /* Check if there is any other open handles after acquiring
904 * open lock. At this point, caching open handles have been revoked
906 * XXX: Now only exclusive open is supported. Need to check the
907 * type of open for generic lease support. */
908 if (rc == 0 && acq_lease) {
909 struct ptlrpc_request *req = mdt_info_req(info);
910 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
911 struct mdt_file_data *mfd;
912 bool is_replay_or_resent;
915 /* For lease: application can open a file and then apply lease,
916 * @handle contains original open handle in that case.
917 * In recovery, open REQ will be replayed and the lease REQ may
918 * be resent that means the open handle is already stale, so we
919 * need to fix it up here by finding new handle. */
920 is_replay_or_resent = req_is_replay(req) ||
921 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT;
923 /* if the request is _not_ a replay request, rr_handle
924 * may be used to hold an openhandle which is issuing the
925 * lease request, so that this openhandle doesn't count. */
926 mfd = mdt_handle2mfd(med, info->mti_rr.rr_handle,
927 is_replay_or_resent);
931 CDEBUG(D_INODE, "acq_lease "DFID": openers: %d, want: %d\n",
932 PFID(mdt_object_fid(obj)),
933 atomic_read(&obj->mot_open_count), open_count);
935 if (atomic_read(&obj->mot_open_count) > open_count)
936 GOTO(out, rc = -EBUSY);
944 static void mdt_object_open_unlock(struct mdt_thread_info *info,
945 struct mdt_object *obj,
946 struct mdt_lock_handle *lhc,
949 __u64 open_flags = info->mti_spec.sp_cr_flags;
950 struct mdt_lock_handle *ll = &info->mti_lh[MDT_LH_LOCAL];
953 if (req_is_replay(mdt_info_req(info)))
956 /* Release local lock - the lock put in MDT_LH_LOCAL will never
957 * return to client side. */
958 if (lustre_handle_is_used(&ll->mlh_reg_lh))
959 mdt_object_unlock(info, obj, ll, 1);
961 ll = &info->mti_lh[MDT_LH_LAYOUT];
962 /* Release local layout lock, layout was created */
963 if (lustre_handle_is_used(&ll->mlh_reg_lh)) {
964 LASSERT(!(ibits & MDS_INODELOCK_LAYOUT));
965 mdt_object_unlock(info, obj, ll, 1);
968 if (open_flags & MDS_OPEN_LEASE)
969 up_write(&obj->mot_open_sem);
971 up_read(&obj->mot_open_sem);
973 /* Cross-ref case, the lock should be returned to the client */
974 if (ibits == 0 || rc == -MDT_EREMOTE_OPEN)
977 if (!(open_flags & MDS_OPEN_LOCK) && !(ibits & MDS_INODELOCK_LAYOUT)) {
978 /* for the open request, the lock will only return to client
979 * if open or layout lock is granted. */
983 if (rc != 0 || !lustre_handle_is_used(&lhc->mlh_reg_lh)) {
984 struct ldlm_reply *ldlm_rep;
986 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
987 mdt_clear_disposition(info, ldlm_rep, DISP_OPEN_LOCK);
988 if (lustre_handle_is_used(&lhc->mlh_reg_lh))
989 mdt_object_unlock(info, obj, lhc, 1);
995 * Check release is permitted for the current HSM flags.
997 static bool mdt_hsm_release_allow(const struct md_attr *ma)
999 if (!(ma->ma_valid & MA_HSM))
1002 if (ma->ma_hsm.mh_flags & (HS_DIRTY|HS_NORELEASE|HS_LOST))
1005 if (!(ma->ma_hsm.mh_flags & HS_ARCHIVED))
1011 static int mdt_open_by_fid_lock(struct mdt_thread_info *info,
1012 struct ldlm_reply *rep,
1013 struct mdt_lock_handle *lhc)
1015 const struct lu_env *env = info->mti_env;
1016 struct mdt_device *mdt = info->mti_mdt;
1017 __u64 flags = info->mti_spec.sp_cr_flags;
1018 struct mdt_reint_record *rr = &info->mti_rr;
1019 struct md_attr *ma = &info->mti_attr;
1020 struct mdt_object *parent= NULL;
1021 struct mdt_object *o;
1023 bool object_locked = false;
1027 if (md_should_create(flags) && !(flags & MDS_OPEN_HAS_EA)) {
1028 if (!lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) {
1029 parent = mdt_object_find(env, mdt, rr->rr_fid1);
1030 if (IS_ERR(parent)) {
1031 CDEBUG(D_INODE, "Fail to find parent "DFID
1032 " for anonymous created %ld, try to"
1033 " use server-side parent.\n",
1034 PFID(rr->rr_fid1), PTR_ERR(parent));
1039 ma->ma_need |= MA_PFID;
1042 o = mdt_object_find(env, mdt, rr->rr_fid2);
1044 GOTO(out_parent_put, rc = PTR_ERR(o));
1046 if (mdt_object_remote(o)) {
1047 CDEBUG(D_INFO, "%s: "DFID" is on remote MDT.\n",
1048 mdt_obd_name(info->mti_mdt),
1050 GOTO(out, rc = -EREMOTE);
1051 } else if (!mdt_object_exists(o)) {
1052 mdt_set_disposition(info, rep,
1056 GOTO(out, rc = -ENOENT);
1059 mdt_set_disposition(info, rep, (DISP_IT_EXECD | DISP_LOOKUP_EXECD));
1061 mdt_prep_ma_buf_from_rep(info, o, ma);
1062 if (flags & MDS_OPEN_RELEASE)
1063 ma->ma_need |= MA_HSM;
1064 rc = mdt_attr_get_complex(info, o, ma);
1068 /* We should not change file's existing LOV EA */
1069 if (S_ISREG(lu_object_attr(&o->mot_obj)) &&
1070 flags & MDS_OPEN_HAS_EA && ma->ma_valid & MA_LOV)
1071 GOTO(out, rc = -EEXIST);
1073 /* If a release request, check file flags are fine and ask for an
1074 * exclusive open access. */
1075 if (flags & MDS_OPEN_RELEASE && !mdt_hsm_release_allow(ma))
1076 GOTO(out, rc = -EPERM);
1078 rc = mdt_check_resent_lock(info, o, lhc);
1081 } else if (rc > 0) {
1082 rc = mdt_object_open_lock(info, o, lhc, &ibits);
1083 object_locked = true;
1085 GOTO(out_unlock, rc);
1088 if (ma->ma_valid & MA_PFID) {
1089 parent = mdt_object_find(env, mdt, &ma->ma_pfid);
1090 if (IS_ERR(parent)) {
1091 CDEBUG(D_INODE, "Fail to find parent "DFID
1092 " for anonymous created %ld, try to"
1093 " use system default.\n",
1094 PFID(&ma->ma_pfid), PTR_ERR(parent));
1099 rc = mdt_finish_open(info, parent, o, flags, 0, rep);
1101 mdt_set_disposition(info, rep, DISP_LOOKUP_POS);
1102 if (flags & MDS_OPEN_LOCK)
1103 mdt_set_disposition(info, rep, DISP_OPEN_LOCK);
1104 if (flags & MDS_OPEN_LEASE)
1105 mdt_set_disposition(info, rep, DISP_OPEN_LEASE);
1107 GOTO(out_unlock, rc);
1111 mdt_object_open_unlock(info, o, lhc, ibits, rc);
1113 mdt_object_put(env, o);
1116 mdt_object_put(env, parent);
1120 /* Cross-ref request. Currently it can only be a pure open (w/o create) */
1121 static int mdt_cross_open(struct mdt_thread_info *info,
1122 const struct lu_fid *parent_fid,
1123 const struct lu_fid *fid,
1124 struct ldlm_reply *rep, __u32 flags)
1126 struct md_attr *ma = &info->mti_attr;
1127 struct mdt_object *o;
1131 o = mdt_object_find(info->mti_env, info->mti_mdt, fid);
1133 RETURN(rc = PTR_ERR(o));
1135 if (mdt_object_remote(o)) {
1136 /* Something is wrong here, the object is on another MDS! */
1137 CERROR("%s: "DFID" isn't on this server!: rc = %d\n",
1138 mdt_obd_name(info->mti_mdt), PFID(fid), -EFAULT);
1139 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
1141 "Object isn't on this server! FLD error?");
1144 if (mdt_object_exists(o)) {
1145 /* Do permission check for cross-open. */
1146 rc = mo_permission(info->mti_env, NULL,
1147 mdt_object_child(o),
1148 NULL, flags | MDS_OPEN_CROSS);
1152 mdt_prep_ma_buf_from_rep(info, o, ma);
1153 rc = mdt_attr_get_complex(info, o, ma);
1157 rc = mdt_finish_open(info, NULL, o, flags, 0, rep);
1160 * Something is wrong here. lookup was positive but
1161 * there is no object!
1163 CERROR("%s: "DFID" doesn't exist!: rc = %d\n",
1164 mdt_obd_name(info->mti_mdt), PFID(fid), -EFAULT);
1169 mdt_object_put(info->mti_env, o);
1174 * find root object and take its xattr lock if it's on remote MDT, later create
1175 * may use fs default striping (which is stored in root xattr).
1177 static int mdt_lock_root_xattr(struct mdt_thread_info *info,
1178 struct mdt_device *mdt)
1180 struct mdt_object *md_root = mdt->mdt_md_root;
1181 struct lustre_handle lhroot;
1184 if (md_root == NULL) {
1185 lu_root_fid(&info->mti_tmp_fid1);
1186 md_root = mdt_object_find(info->mti_env, mdt,
1187 &info->mti_tmp_fid1);
1188 if (IS_ERR(md_root))
1189 return PTR_ERR(md_root);
1191 spin_lock(&mdt->mdt_lock);
1192 if (mdt->mdt_md_root != NULL) {
1193 spin_unlock(&mdt->mdt_lock);
1195 LASSERTF(mdt->mdt_md_root == md_root,
1196 "Different root object ("
1197 DFID") instances, %p, %p\n",
1198 PFID(&info->mti_tmp_fid1),
1199 mdt->mdt_md_root, md_root);
1200 LASSERT(atomic_read(
1201 &md_root->mot_obj.lo_header->loh_ref) > 1);
1203 mdt_object_put(info->mti_env, md_root);
1205 mdt->mdt_md_root = md_root;
1206 spin_unlock(&mdt->mdt_lock);
1210 if (md_root->mot_cache_attr || !mdt_object_remote(md_root))
1213 rc = mdt_remote_object_lock(info, md_root, mdt_object_fid(md_root),
1214 &lhroot, LCK_PR, MDS_INODELOCK_XATTR,
1219 md_root->mot_cache_attr = 1;
1221 /* don't cancel this lock, so that we know the cached xattr is valid. */
1222 ldlm_lock_decref(&lhroot, LCK_PR);
1227 int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc)
1229 struct mdt_device *mdt = info->mti_mdt;
1230 struct ptlrpc_request *req = mdt_info_req(info);
1231 struct mdt_object *parent;
1232 struct mdt_object *child;
1233 struct mdt_lock_handle *lh;
1234 struct ldlm_reply *ldlm_rep;
1235 struct mdt_body *repbody;
1236 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1237 struct md_attr *ma = &info->mti_attr;
1238 __u64 create_flags = info->mti_spec.sp_cr_flags;
1240 struct mdt_reint_record *rr = &info->mti_rr;
1243 int object_locked = 0;
1247 OBD_FAIL_TIMEOUT_ORSET(OBD_FAIL_MDS_PAUSE_OPEN, OBD_FAIL_ONCE,
1248 (obd_timeout + 1) / 4);
1250 mdt_counter_incr(req, LPROC_MDT_OPEN);
1251 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1253 ma->ma_need = MA_INODE;
1256 LASSERT(info->mti_pill->rc_fmt == &RQF_LDLM_INTENT_OPEN);
1257 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
1259 if (unlikely(create_flags & MDS_OPEN_JOIN_FILE)) {
1260 CERROR("file join is not supported anymore.\n");
1261 GOTO(out, result = err_serious(-EOPNOTSUPP));
1263 msg_flags = lustre_msg_get_flags(req->rq_reqmsg);
1265 if ((create_flags & (MDS_OPEN_HAS_EA | MDS_OPEN_HAS_OBJS)) &&
1266 info->mti_spec.u.sp_ea.eadata == NULL)
1267 GOTO(out, result = err_serious(-EINVAL));
1269 if (create_flags & FMODE_WRITE &&
1270 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
1271 GOTO(out, result = -EROFS);
1273 CDEBUG(D_INODE, "I am going to open "DFID"/("DNAME"->"DFID") "
1274 "cr_flag=%#llo mode=0%06o msg_flag=0x%x\n",
1275 PFID(rr->rr_fid1), PNAME(&rr->rr_name),
1276 PFID(rr->rr_fid2), create_flags,
1277 ma->ma_attr.la_mode, msg_flags);
1279 if (info->mti_cross_ref) {
1280 /* This is cross-ref open */
1281 mdt_set_disposition(info, ldlm_rep,
1282 (DISP_IT_EXECD | DISP_LOOKUP_EXECD |
1284 result = mdt_cross_open(info, rr->rr_fid2, rr->rr_fid1,
1285 ldlm_rep, create_flags);
1287 } else if (req_is_replay(req)) {
1288 result = mdt_open_by_fid(info, ldlm_rep);
1290 if (result != -ENOENT)
1293 /* We didn't find the correct object, so we need to re-create it
1294 * via a regular replay. */
1295 if (!(create_flags & MDS_OPEN_CREAT)) {
1296 DEBUG_REQ(D_ERROR, req,
1297 "OPEN & CREAT not in open replay/by_fid.");
1298 GOTO(out, result = -EFAULT);
1300 CDEBUG(D_INFO, "No object(1), continue as regular open.\n");
1301 } else if (create_flags & (MDS_OPEN_BY_FID | MDS_OPEN_LOCK)) {
1303 * MDS_OPEN_LOCK is checked for backward compatibility with 2.1
1306 result = mdt_open_by_fid_lock(info, ldlm_rep, lhc);
1308 CDEBUG(D_INFO, "no object for "DFID": %d\n",
1309 PFID(rr->rr_fid2), result);
1313 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK))
1314 GOTO(out, result = err_serious(-ENOMEM));
1316 mdt_set_disposition(info, ldlm_rep,
1317 (DISP_IT_EXECD | DISP_LOOKUP_EXECD));
1319 if (!lu_name_is_valid(&rr->rr_name))
1320 GOTO(out, result = -EPROTO);
1322 result = mdt_lock_root_xattr(info, mdt);
1327 lh = &info->mti_lh[MDT_LH_PARENT];
1328 mdt_lock_pdo_init(lh,
1329 (create_flags & MDS_OPEN_CREAT) ? LCK_PW : LCK_PR,
1332 parent = mdt_object_find(info->mti_env, mdt, rr->rr_fid1);
1334 GOTO(out, result = PTR_ERR(parent));
1336 result = mdt_object_lock(info, parent, lh, MDS_INODELOCK_UPDATE);
1338 mdt_object_put(info->mti_env, parent);
1342 /* get and check version of parent */
1343 result = mdt_version_get_check(info, parent, 0);
1345 GOTO(out_parent, result);
1347 fid_zero(child_fid);
1349 result = mdo_lookup(info->mti_env, mdt_object_child(parent),
1350 &rr->rr_name, child_fid, &info->mti_spec);
1352 LASSERTF(ergo(result == 0, fid_is_sane(child_fid)),
1353 "looking for "DFID"/"DNAME", found FID = "DFID"\n",
1354 PFID(mdt_object_fid(parent)), PNAME(&rr->rr_name),
1357 if (result != 0 && result != -ENOENT && result != -ESTALE)
1358 GOTO(out_parent, result);
1360 if (result == -ENOENT || result == -ESTALE) {
1361 /* If the object is dead, let's check if the object
1362 * is being migrated to a new object */
1363 if (result == -ESTALE) {
1364 struct lu_buf lmv_buf;
1366 lmv_buf.lb_buf = info->mti_xattr_buf;
1367 lmv_buf.lb_len = sizeof(info->mti_xattr_buf);
1368 rc = mo_xattr_get(info->mti_env,
1369 mdt_object_child(parent),
1370 &lmv_buf, XATTR_NAME_LMV);
1372 struct lmv_mds_md_v1 *lmv;
1374 lmv = lmv_buf.lb_buf;
1375 if (le32_to_cpu(lmv->lmv_hash_type) &
1376 LMV_HASH_FLAG_MIGRATION) {
1377 /* Get the new parent FID and retry */
1378 mdt_object_unlock_put(info, parent,
1380 mdt_lock_handle_init(lh);
1382 (struct lu_fid *)rr->rr_fid1,
1383 &lmv->lmv_stripe_fids[1]);
1389 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1390 if (result == -ESTALE) {
1392 * -ESTALE means the parent is a dead(unlinked) dir, so
1393 * it should return -ENOENT to in accordance with the
1394 * original mds implementaion.
1396 GOTO(out_parent, result = -ENOENT);
1399 if (!(create_flags & MDS_OPEN_CREAT))
1400 GOTO(out_parent, result);
1401 if (mdt_rdonly(req->rq_export))
1402 GOTO(out_parent, result = -EROFS);
1403 *child_fid = *info->mti_rr.rr_fid2;
1404 LASSERTF(fid_is_sane(child_fid), "fid="DFID"\n",
1406 /* In the function below, .hs_keycmp resolves to
1407 * lu_obj_hop_keycmp() */
1408 /* coverity[overrun-buffer-val] */
1409 child = mdt_object_new(info->mti_env, mdt, child_fid);
1412 * Check for O_EXCL is moved to the mdt_finish_open(), we need to
1413 * return FID back in that case.
1415 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1416 child = mdt_object_find(info->mti_env, mdt, child_fid);
1419 GOTO(out_parent, result = PTR_ERR(child));
1421 /** check version of child */
1422 rc = mdt_version_get_check(info, child, 1);
1424 GOTO(out_child, result = rc);
1426 if (result == -ENOENT) {
1427 /* Create under OBF and .lustre is not permitted */
1428 if (!fid_is_md_operative(rr->rr_fid1))
1429 GOTO(out_child, result = -EPERM);
1431 /* save versions in reply */
1432 mdt_version_get_save(info, parent, 0);
1433 mdt_version_get_save(info, child, 1);
1435 /* version of child will be changed */
1436 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(child));
1438 /* Not found and with MDS_OPEN_CREAT: let's create it. */
1439 mdt_set_disposition(info, ldlm_rep, DISP_OPEN_CREATE);
1441 /* Let lower layers know what is lock mode on directory. */
1442 info->mti_spec.sp_cr_mode =
1443 mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode);
1445 /* Don't do lookup sanity check. We know name doesn't exist. */
1446 info->mti_spec.sp_cr_lookup = 0;
1447 info->mti_spec.sp_feat = &dt_directory_features;
1449 result = mdo_create(info->mti_env, mdt_object_child(parent),
1450 &rr->rr_name, mdt_object_child(child),
1451 &info->mti_spec, &info->mti_attr);
1452 if (result == -ERESTART) {
1453 mdt_clear_disposition(info, ldlm_rep, DISP_OPEN_CREATE);
1454 GOTO(out_child, result);
1456 mdt_prep_ma_buf_from_rep(info, child, ma);
1457 /* XXX: we should call this once, see few lines below */
1459 result = mdt_attr_get_complex(info, child, ma);
1462 GOTO(out_child, result);
1465 mdt_counter_incr(req, LPROC_MDT_MKNOD);
1468 * The object is on remote node, return its FID for remote open.
1470 if (mdt_object_remote(child)) {
1472 * Check if this lock already was sent to client and
1473 * this is resent case. For resent case do not take lock
1474 * again, use what is already granted.
1476 LASSERT(lhc != NULL);
1478 rc = mdt_check_resent_lock(info, child, lhc);
1480 GOTO(out_child, result = rc);
1481 } else if (rc > 0) {
1482 mdt_lock_handle_init(lhc);
1483 mdt_lock_reg_init(lhc, LCK_PR);
1485 rc = mdt_object_lock(info, child, lhc,
1486 MDS_INODELOCK_LOOKUP);
1488 repbody->mbo_fid1 = *mdt_object_fid(child);
1489 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
1493 result = -MDT_EREMOTE_OPEN;
1494 GOTO(out_child, result);
1495 } else if (mdt_object_exists(child)) {
1496 /* We have to get attr & LOV EA & HSM for this
1498 mdt_prep_ma_buf_from_rep(info, child, ma);
1499 ma->ma_need |= MA_HSM;
1500 result = mdt_attr_get_complex(info, child, ma);
1502 GOTO(out_child, result);
1504 /* Object does not exist. Likely FS corruption. */
1505 CERROR("%s: name '"DNAME"' present, but FID "
1506 DFID" is invalid\n", mdt_obd_name(info->mti_mdt),
1507 PNAME(&rr->rr_name), PFID(child_fid));
1508 GOTO(out_child, result = -EIO);
1512 rc = mdt_check_resent_lock(info, child, lhc);
1514 GOTO(out_child, result = rc);
1515 } else if (rc == 0) {
1516 /* the open lock might already be gotten in
1517 * ldlm_handle_enqueue() */
1518 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
1519 if (create_flags & MDS_OPEN_LOCK)
1520 mdt_set_disposition(info, ldlm_rep, DISP_OPEN_LOCK);
1522 /* get openlock if this isn't replay and client requested it */
1523 if (!req_is_replay(req)) {
1524 rc = mdt_object_open_lock(info, child, lhc, &ibits);
1527 GOTO(out_child_unlock, result = rc);
1528 else if (create_flags & MDS_OPEN_LOCK)
1529 mdt_set_disposition(info, ldlm_rep,
1533 /* Try to open it now. */
1534 rc = mdt_finish_open(info, parent, child, create_flags,
1538 /* openlock will be released if mdt_finish_open failed */
1539 mdt_clear_disposition(info, ldlm_rep, DISP_OPEN_LOCK);
1541 if (created && create_flags & MDS_OPEN_VOLATILE) {
1542 CERROR("%s: cannot open volatile file "DFID", orphan "
1543 "file will be left in PENDING directory until "
1544 "next reboot, rc = %d\n", mdt_obd_name(mdt),
1545 PFID(mdt_object_fid(child)), rc);
1546 GOTO(out_child_unlock, result);
1552 rc = mdo_unlink(info->mti_env,
1553 mdt_object_child(parent),
1554 mdt_object_child(child),
1556 &info->mti_attr, 0);
1558 CERROR("%s: "DFID" cleanup of open: rc = %d\n",
1559 mdt_obd_name(info->mti_mdt),
1560 PFID(mdt_object_fid(child)), rc);
1561 mdt_clear_disposition(info, ldlm_rep, DISP_OPEN_CREATE);
1567 mdt_object_open_unlock(info, child, lhc, ibits, result);
1569 mdt_object_put(info->mti_env, child);
1571 mdt_object_unlock_put(info, parent, lh, result || !created);
1574 lustre_msg_set_transno(req->rq_repmsg, 0);
1579 * Create an orphan object use local root.
1581 static struct mdt_object *mdt_orphan_open(struct mdt_thread_info *info,
1582 struct mdt_device *mdt,
1583 const struct lu_fid *fid,
1584 struct md_attr *attr, fmode_t fmode)
1586 const struct lu_env *env = info->mti_env;
1587 struct md_op_spec *spec = &info->mti_spec;
1588 struct lu_fid *local_root_fid = &info->mti_tmp_fid1;
1589 struct mdt_object *obj = NULL;
1590 struct mdt_object *local_root;
1591 static const struct lu_name lname = {
1592 .ln_name = "i_am_nobody",
1593 .ln_namelen = sizeof("i_am_nobody") - 1,
1595 struct lu_ucred *uc;
1596 cfs_cap_t uc_cap_save;
1600 rc = dt_root_get(env, mdt->mdt_bottom, local_root_fid);
1602 RETURN(ERR_PTR(rc));
1604 local_root = mdt_object_find(env, mdt, local_root_fid);
1605 if (IS_ERR(local_root))
1608 obj = mdt_object_new(env, mdt, fid);
1610 GOTO(out, rc = PTR_ERR(obj));
1612 spec->sp_cr_lookup = 0;
1613 spec->sp_feat = &dt_directory_features;
1614 spec->sp_cr_mode = MDL_MINMODE; /* no lock */
1615 spec->sp_cr_flags = MDS_OPEN_VOLATILE | fmode;
1616 if (attr->ma_valid & MA_LOV) {
1617 spec->u.sp_ea.eadata = attr->ma_lmm;
1618 spec->u.sp_ea.eadatalen = attr->ma_lmm_size;
1619 spec->sp_cr_flags |= MDS_OPEN_HAS_EA;
1621 spec->sp_cr_flags |= MDS_OPEN_DELAY_CREATE;
1625 uc_cap_save = uc->uc_cap;
1626 uc->uc_cap |= 1 << CFS_CAP_DAC_OVERRIDE;
1627 rc = mdo_create(env, mdt_object_child(local_root), &lname,
1628 mdt_object_child(obj), spec, attr);
1629 uc->uc_cap = uc_cap_save;
1631 CERROR("%s: cannot create volatile file "DFID": rc = %d\n",
1632 mdt_obd_name(mdt), PFID(fid), rc);
1636 rc = mo_open(env, mdt_object_child(obj), MDS_OPEN_CREATED);
1638 CERROR("%s: cannot open volatile file "DFID", orphan "
1639 "file will be left in PENDING directory until "
1640 "next reboot, rc = %d\n", mdt_obd_name(mdt),
1647 mdt_object_put(env, obj);
1650 mdt_object_put(env, local_root);
1654 /* XXX Look into layout in MDT layer. */
1655 static inline int mdt_hsm_set_released(struct lov_mds_md *lmm)
1657 struct lov_comp_md_v1 *comp_v1;
1658 struct lov_mds_md *v1;
1662 if (lmm->lmm_magic == cpu_to_le32(LOV_MAGIC_COMP_V1_DEF)) {
1663 comp_v1 = (struct lov_comp_md_v1 *)lmm;
1665 if (comp_v1->lcm_entry_count == 0)
1668 for (i = 0; i < le16_to_cpu(comp_v1->lcm_entry_count); i++) {
1669 off = le32_to_cpu(comp_v1->lcm_entries[i].lcme_offset);
1670 v1 = (struct lov_mds_md *)((char *)comp_v1 + off);
1671 v1->lmm_pattern |= cpu_to_le32(LOV_PATTERN_F_RELEASED);
1674 lmm->lmm_pattern |= cpu_to_le32(LOV_PATTERN_F_RELEASED);
1679 static int mdt_hsm_release(struct mdt_thread_info *info, struct mdt_object *o,
1682 struct mdt_lock_handle *lh = &info->mti_lh[MDT_LH_LAYOUT];
1683 struct lu_ucred *uc = mdt_ucred(info);
1684 struct close_data *data;
1685 struct ldlm_lock *lease;
1686 struct mdt_object *orphan;
1687 struct md_attr *orp_ma;
1695 if (mdt_rdonly(info->mti_exp))
1698 data = req_capsule_client_get(info->mti_pill, &RMF_CLOSE_DATA);
1702 lease = ldlm_handle2lock(&data->cd_handle);
1706 /* try to hold open_sem so that nobody else can open the file */
1707 if (!down_write_trylock(&o->mot_open_sem)) {
1708 ldlm_lock_cancel(lease);
1709 GOTO(out_reprocess, rc = -EBUSY);
1712 /* Check if the lease open lease has already canceled */
1713 lock_res_and_lock(lease);
1714 lease_broken = ldlm_is_cancel(lease);
1715 unlock_res_and_lock(lease);
1717 LDLM_DEBUG(lease, DFID " lease broken? %d",
1718 PFID(mdt_object_fid(o)), lease_broken);
1720 /* Cancel server side lease. Client side counterpart should
1721 * have been cancelled. It's okay to cancel it now as we've
1722 * held mot_open_sem. */
1723 ldlm_lock_cancel(lease);
1725 if (lease_broken) /* don't perform release task */
1726 GOTO(out_unlock, rc = -ESTALE);
1728 if (fid_is_zero(&data->cd_fid) || !fid_is_sane(&data->cd_fid))
1729 GOTO(out_unlock, rc = -EINVAL);
1731 /* ma_need was set before but it seems fine to change it in order to
1732 * avoid modifying the one from RPC */
1733 ma->ma_need = MA_HSM;
1734 rc = mdt_attr_get_complex(info, o, ma);
1736 GOTO(out_unlock, rc);
1738 if (!mdt_hsm_release_allow(ma))
1739 GOTO(out_unlock, rc = -EPERM);
1741 /* already released? */
1742 if (ma->ma_hsm.mh_flags & HS_RELEASED)
1743 GOTO(out_unlock, rc = 0);
1745 /* Compare on-disk and packed data_version */
1746 if (data->cd_data_version != ma->ma_hsm.mh_arch_ver) {
1747 CDEBUG(D_HSM, DFID" data_version mismatches: packed=%llu"
1748 " and on-disk=%llu\n", PFID(mdt_object_fid(o)),
1749 data->cd_data_version, ma->ma_hsm.mh_arch_ver);
1750 GOTO(out_unlock, rc = -EPERM);
1753 ma->ma_valid = MA_INODE;
1754 ma->ma_attr.la_valid &= LA_ATIME | LA_MTIME | LA_CTIME | LA_SIZE;
1755 rc = mo_attr_set(info->mti_env, mdt_object_child(o), ma);
1757 GOTO(out_unlock, rc);
1759 ma->ma_need = MA_INODE | MA_LOV;
1760 rc = mdt_attr_get_complex(info, o, ma);
1762 GOTO(out_unlock, rc);
1764 if (!(ma->ma_valid & MA_LOV)) {
1765 /* Even empty file are released */
1766 memset(ma->ma_lmm, 0, sizeof(*ma->ma_lmm));
1767 ma->ma_lmm->lmm_magic = cpu_to_le32(LOV_MAGIC_V1_DEF);
1768 ma->ma_lmm->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
1769 ma->ma_lmm->lmm_stripe_size = cpu_to_le32(LOV_MIN_STRIPE_SIZE);
1770 ma->ma_lmm_size = sizeof(*ma->ma_lmm);
1772 /* Magic must be LOV_MAGIC_*_DEF otherwise LOD will interpret
1773 * ma_lmm as lov_user_md, then it will be confused by union of
1774 * layout_gen and stripe_offset. */
1775 if ((le32_to_cpu(ma->ma_lmm->lmm_magic) & LOV_MAGIC_MASK) ==
1777 ma->ma_lmm->lmm_magic |= cpu_to_le32(LOV_MAGIC_DEF);
1779 GOTO(out_unlock, rc = -EINVAL);
1782 /* Set file as released. */
1783 rc = mdt_hsm_set_released(ma->ma_lmm);
1785 GOTO(out_unlock, rc);
1787 orp_ma = &info->mti_u.hsm.attr;
1788 orp_ma->ma_attr.la_mode = S_IFREG | S_IWUSR;
1789 /* We use root ownership to bypass potential quota
1790 * restrictions on the user and group of the file. */
1791 orp_ma->ma_attr.la_uid = 0;
1792 orp_ma->ma_attr.la_gid = 0;
1793 orp_ma->ma_attr.la_valid = LA_MODE | LA_UID | LA_GID;
1794 orp_ma->ma_lmm = ma->ma_lmm;
1795 orp_ma->ma_lmm_size = ma->ma_lmm_size;
1796 orp_ma->ma_valid = MA_INODE | MA_LOV;
1797 orphan = mdt_orphan_open(info, info->mti_mdt, &data->cd_fid, orp_ma,
1799 if (IS_ERR(orphan)) {
1800 CERROR("%s: cannot open orphan file "DFID": rc = %ld\n",
1801 mdt_obd_name(info->mti_mdt), PFID(&data->cd_fid),
1803 GOTO(out_unlock, rc = PTR_ERR(orphan));
1806 /* Set up HSM attribute for orphan object */
1807 CLASSERT(sizeof(struct hsm_attrs) <= sizeof(info->mti_xattr_buf));
1808 buf = &info->mti_buf;
1809 buf->lb_buf = info->mti_xattr_buf;
1810 buf->lb_len = sizeof(struct hsm_attrs);
1811 ma->ma_hsm.mh_flags |= HS_RELEASED;
1812 lustre_hsm2buf(buf->lb_buf, &ma->ma_hsm);
1813 ma->ma_hsm.mh_flags &= ~HS_RELEASED;
1815 mdt_lock_reg_init(lh, LCK_EX);
1816 rc = mdt_object_lock(info, o, lh, MDS_INODELOCK_LAYOUT |
1817 MDS_INODELOCK_XATTR);
1819 GOTO(out_close, rc);
1821 /* The orphan has root ownership so we need to raise
1822 * CAP_FOWNER to set the HSM attributes. */
1824 uc->uc_cap |= MD_CAP_TO_MASK(CFS_CAP_FOWNER);
1825 rc = mo_xattr_set(info->mti_env, mdt_object_child(orphan), buf,
1829 GOTO(out_layout_lock, rc);
1831 /* Swap layout with orphan objects. */
1832 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o),
1833 mdt_object_child(orphan),
1834 SWAP_LAYOUTS_MDS_HSM);
1838 /* Release exclusive LL */
1839 mdt_object_unlock(info, o, lh, 1);
1841 /* Close orphan object anyway */
1842 rc2 = mo_close(info->mti_env, mdt_object_child(orphan), orp_ma,
1845 CERROR("%s: error closing volatile file "DFID": rc = %d\n",
1846 mdt_obd_name(info->mti_mdt), PFID(&data->cd_fid), rc2);
1847 LU_OBJECT_DEBUG(D_HSM, info->mti_env, &orphan->mot_obj,
1849 mdt_object_put(info->mti_env, orphan);
1852 up_write(&o->mot_open_sem);
1854 /* already released */
1856 struct mdt_body *repbody;
1858 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1859 LASSERT(repbody != NULL);
1860 repbody->mbo_valid |= OBD_MD_CLOSE_INTENT_EXECED;
1864 ldlm_reprocess_all(lease->l_resource);
1865 LDLM_LOCK_PUT(lease);
1873 int mdt_close_swap_layouts(struct mdt_thread_info *info,
1874 struct mdt_object *o, struct md_attr *ma)
1876 struct mdt_lock_handle *lh1 = &info->mti_lh[MDT_LH_NEW];
1877 struct mdt_lock_handle *lh2 = &info->mti_lh[MDT_LH_OLD];
1878 struct close_data *data;
1879 struct ldlm_lock *lease;
1880 struct mdt_object *o1 = o, *o2;
1886 if (exp_connect_flags(info->mti_exp) & OBD_CONNECT_RDONLY)
1889 if (!S_ISREG(lu_object_attr(&o1->mot_obj)))
1892 data = req_capsule_client_get(info->mti_pill, &RMF_CLOSE_DATA);
1896 if (fid_is_zero(&data->cd_fid) || !fid_is_sane(&data->cd_fid))
1899 rc = lu_fid_cmp(&data->cd_fid, mdt_object_fid(o));
1900 if (unlikely(rc == 0))
1903 /* Exchange o1 and o2, to enforce locking order */
1904 swap_objects = (rc < 0);
1906 lease = ldlm_handle2lock(&data->cd_handle);
1910 o2 = mdt_object_find(info->mti_env, info->mti_mdt, &data->cd_fid);
1912 GOTO(out_lease, rc = PTR_ERR(o2));
1914 if (!S_ISREG(lu_object_attr(&o2->mot_obj))) {
1915 swap_objects = false; /* not swapped yet */
1916 GOTO(out_obj, rc = -EINVAL);
1922 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o1), NULL,
1927 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o2), NULL,
1932 /* try to hold open_sem so that nobody else can open the file */
1933 if (!down_write_trylock(&o->mot_open_sem)) {
1934 ldlm_lock_cancel(lease);
1935 GOTO(out_obj, rc = -EBUSY);
1938 /* Check if the lease open lease has already canceled */
1939 lock_res_and_lock(lease);
1940 lease_broken = ldlm_is_cancel(lease);
1941 unlock_res_and_lock(lease);
1943 LDLM_DEBUG(lease, DFID " lease broken? %d",
1944 PFID(mdt_object_fid(o)), lease_broken);
1946 /* Cancel server side lease. Client side counterpart should
1947 * have been cancelled. It's okay to cancel it now as we've
1948 * held mot_open_sem. */
1949 ldlm_lock_cancel(lease);
1952 GOTO(out_unlock_sem, rc = -ESTALE);
1954 mdt_lock_reg_init(lh1, LCK_EX);
1955 rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT |
1956 MDS_INODELOCK_XATTR);
1958 GOTO(out_unlock_sem, rc);
1960 mdt_lock_reg_init(lh2, LCK_EX);
1961 rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT |
1962 MDS_INODELOCK_XATTR);
1964 GOTO(out_unlock1, rc);
1966 /* Swap layout with orphan object */
1967 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
1968 mdt_object_child(o2), 0);
1970 GOTO(out_unlock2, rc);
1975 /* Release exclusive LL */
1976 mdt_object_unlock(info, o2, lh2, 1);
1979 mdt_object_unlock(info, o1, lh1, 1);
1982 up_write(&o->mot_open_sem);
1984 /* already swapped */
1986 struct mdt_body *repbody;
1988 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1989 LASSERT(repbody != NULL);
1990 repbody->mbo_valid |= OBD_MD_CLOSE_INTENT_EXECED;
1994 mdt_object_put(info->mti_env, swap_objects ? o1 : o2);
1996 ldlm_reprocess_all(lease->l_resource);
1999 LDLM_LOCK_PUT(lease);
2009 #define MFD_CLOSED(mode) ((mode) == MDS_FMODE_CLOSED)
2010 static int mdt_mfd_closed(struct mdt_file_data *mfd)
2012 return ((mfd == NULL) || MFD_CLOSED(mfd->mfd_mode));
2015 int mdt_mfd_close(struct mdt_thread_info *info, struct mdt_file_data *mfd)
2017 struct mdt_object *o = mfd->mfd_object;
2018 struct md_object *next = mdt_object_child(o);
2019 struct md_attr *ma = &info->mti_attr;
2024 mode = mfd->mfd_mode;
2026 if (ma->ma_attr_flags & MDS_HSM_RELEASE) {
2027 rc = mdt_hsm_release(info, o, ma);
2029 CDEBUG(D_HSM, "%s: File " DFID " release failed: %d\n",
2030 mdt_obd_name(info->mti_mdt),
2031 PFID(mdt_object_fid(o)), rc);
2032 /* continue to close even error occurred. */
2036 if (ma->ma_attr_flags & MDS_CLOSE_LAYOUT_SWAP) {
2037 rc = mdt_close_swap_layouts(info, o, ma);
2040 "%s: cannot swap layout of "DFID": rc=%d\n",
2041 mdt_obd_name(info->mti_mdt),
2042 PFID(mdt_object_fid(o)), rc);
2043 /* continue to close even if error occurred. */
2047 if (mode & FMODE_WRITE)
2049 else if (mode & MDS_FMODE_EXEC)
2052 /* Update atime on close only. */
2053 if ((mode & MDS_FMODE_EXEC || mode & FMODE_READ || mode & FMODE_WRITE)
2054 && (ma->ma_valid & MA_INODE) && (ma->ma_attr.la_valid & LA_ATIME)) {
2055 /* Set the atime only. */
2056 ma->ma_valid = MA_INODE;
2057 ma->ma_attr.la_valid = LA_ATIME;
2058 rc = mo_attr_set(info->mti_env, next, ma);
2061 /* If file data is modified, add the dirty flag. */
2062 if (ma->ma_attr_flags & MDS_DATA_MODIFIED)
2063 rc = mdt_add_dirty_flag(info, o, ma);
2065 ma->ma_need |= MA_INODE;
2066 ma->ma_valid &= ~MA_INODE;
2068 LASSERT(atomic_read(&o->mot_open_count) > 0);
2069 atomic_dec(&o->mot_open_count);
2070 mdt_handle_last_unlink(info, o, ma);
2072 if (!MFD_CLOSED(mode))
2073 rc = mo_close(info->mti_env, next, ma, mode);
2075 /* adjust open and lease count */
2076 if (mode & MDS_OPEN_LEASE) {
2077 LASSERT(atomic_read(&o->mot_lease_count) > 0);
2078 atomic_dec(&o->mot_lease_count);
2082 mdt_object_put(info->mti_env, o);
2087 int mdt_close_internal(struct mdt_thread_info *info, struct ptlrpc_request *req,
2088 struct mdt_body *repbody)
2090 struct mdt_export_data *med;
2091 struct mdt_file_data *mfd;
2096 med = &req->rq_export->exp_mdt_data;
2097 spin_lock(&med->med_open_lock);
2098 mfd = mdt_handle2mfd(med, &info->mti_close_handle, req_is_replay(req));
2099 if (mdt_mfd_closed(mfd)) {
2100 spin_unlock(&med->med_open_lock);
2101 CDEBUG(D_INODE, "no handle for file close: fid = "DFID
2102 ": cookie = %#llx\n", PFID(info->mti_rr.rr_fid1),
2103 info->mti_close_handle.cookie);
2104 /** not serious error since bug 3633 */
2107 class_handle_unhash(&mfd->mfd_handle);
2108 list_del_init(&mfd->mfd_list);
2109 spin_unlock(&med->med_open_lock);
2110 ret = mdt_mfd_close(info, mfd);
2113 RETURN(rc ? rc : ret);
2116 int mdt_close(struct tgt_session_info *tsi)
2118 struct mdt_thread_info *info = tsi2mdt_info(tsi);
2119 struct ptlrpc_request *req = tgt_ses_req(tsi);
2120 struct md_attr *ma = &info->mti_attr;
2121 struct mdt_body *repbody = NULL;
2125 mdt_counter_incr(req, LPROC_MDT_CLOSE);
2126 /* Close may come with the Size-on-MDS update. Unpack it. */
2127 rc = mdt_close_unpack(info);
2129 GOTO(out, rc = err_serious(rc));
2131 /* These fields are no longer used and are left for compatibility.
2132 * size is always zero */
2133 req_capsule_set_size(info->mti_pill, &RMF_MDT_MD, RCL_SERVER,
2135 req_capsule_set_size(info->mti_pill, &RMF_LOGCOOKIES, RCL_SERVER,
2137 rc = req_capsule_server_pack(info->mti_pill);
2138 if (mdt_check_resent(info, mdt_reconstruct_generic, NULL)) {
2139 mdt_client_compatibility(info);
2141 mdt_fix_reply(info);
2142 mdt_exit_ucred(info);
2143 GOTO(out, rc = lustre_msg_get_status(req->rq_repmsg));
2146 /* Continue to close handle even if we can not pack reply */
2148 repbody = req_capsule_server_get(info->mti_pill,
2150 ma->ma_lmm = req_capsule_server_get(info->mti_pill,
2152 ma->ma_lmm_size = req_capsule_get_size(info->mti_pill,
2155 ma->ma_need = MA_INODE | MA_LOV;
2156 repbody->mbo_eadatasize = 0;
2157 repbody->mbo_aclsize = 0;
2159 rc = err_serious(rc);
2162 rc = mdt_close_internal(info, req, repbody);
2164 mdt_empty_transno(info, rc);
2166 if (repbody != NULL) {
2167 mdt_client_compatibility(info);
2168 rc = mdt_fix_reply(info);
2171 mdt_exit_ucred(info);
2172 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK))
2173 GOTO(out, rc = err_serious(-ENOMEM));
2175 if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MDS_CLOSE_NET_REP,
2176 OBD_FAIL_MDS_CLOSE_NET_REP))
2177 tsi->tsi_reply_fail_id = OBD_FAIL_MDS_CLOSE_NET_REP;
2179 mdt_thread_info_fini(info);
2180 RETURN(rc ? rc : ret);