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, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/mdt/mdt_lib.c
33 * Lustre Metadata Target (mdt) request unpacking helper.
35 * Author: Peter Braam <braam@clusterfs.com>
36 * Author: Andreas Dilger <adilger@clusterfs.com>
37 * Author: Phil Schwan <phil@clusterfs.com>
38 * Author: Mike Shaver <shaver@clusterfs.com>
39 * Author: Nikita Danilov <nikita@clusterfs.com>
40 * Author: Huang Hua <huanghua@clusterfs.com>
41 * Author: Fan Yong <fanyong@clusterfs.com>
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include <linux/user_namespace.h>
47 #include <linux/uidgid.h>
49 #include "mdt_internal.h"
50 #include <uapi/linux/lnet/nidstr.h>
51 #include <lustre_nodemap.h>
53 typedef enum ucred_init_type {
59 static __u64 get_mrc_cr_flags(struct mdt_rec_create *mrc)
61 return (__u64)(mrc->cr_flags_l) | ((__u64)mrc->cr_flags_h << 32);
64 void mdt_exit_ucred(struct mdt_thread_info *info)
66 struct lu_ucred *uc = mdt_ucred(info);
67 struct mdt_device *mdt = info->mti_mdt;
70 if (uc->uc_valid != UCRED_INIT) {
71 uc->uc_suppgids[0] = uc->uc_suppgids[1] = -1;
73 put_group_info(uc->uc_ginfo);
76 if (uc->uc_identity) {
77 mdt_identity_put(mdt->mdt_identity_cache,
79 uc->uc_identity = NULL;
81 uc->uc_valid = UCRED_INIT;
85 static int match_nosquash_list(struct spinlock *rsi_lock,
86 struct list_head *nidlist,
87 struct lnet_nid *peernid)
92 rc = cfs_match_nid(peernid, nidlist);
93 spin_unlock(rsi_lock);
97 /* root_squash for inter-MDS operations */
98 static int mdt_root_squash(struct mdt_thread_info *info,
99 struct lnet_nid *peernid)
101 struct lu_ucred *ucred = mdt_ucred(info);
102 struct root_squash_info *squash = &info->mti_mdt->mdt_squash;
105 LASSERT(ucred != NULL);
106 if (!squash->rsi_uid || ucred->uc_fsuid)
109 if (match_nosquash_list(&squash->rsi_lock,
110 &squash->rsi_nosquash_nids,
112 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
113 libcfs_nidstr(peernid));
117 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
118 libcfs_nidstr(peernid), ucred->uc_fsuid, ucred->uc_fsgid,
119 (u32)ll_capability_u32(ucred->uc_cap),
120 squash->rsi_uid, squash->rsi_gid, 0);
122 ucred->uc_fsuid = squash->rsi_uid;
123 ucred->uc_fsgid = squash->rsi_gid;
124 ucred->uc_cap = CAP_EMPTY_SET;
125 ucred->uc_suppgids[0] = -1;
126 ucred->uc_suppgids[1] = -1;
127 if (ucred->uc_ginfo) {
128 put_group_info(ucred->uc_ginfo);
129 ucred->uc_ginfo = NULL;
135 static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc)
137 struct ptlrpc_request *req = mdt_info_req(info);
138 const char *jobid = mdt_req_get_jobid(req);
140 /* set jobid if specified. */
142 strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid));
144 uc->uc_jobid[0] = '\0';
147 static void ucred_set_nid(struct mdt_thread_info *info, struct lu_ucred *uc)
149 if (info && info->mti_exp && info->mti_exp->exp_connection)
150 uc->uc_nid = lnet_nid_to_nid4(
151 &info->mti_exp->exp_connection->c_peer.nid);
153 uc->uc_nid = LNET_NID_ANY;
156 static void ucred_set_audit_enabled(struct mdt_thread_info *info,
159 struct lu_nodemap *nodemap = NULL;
162 if (info && info->mti_exp) {
163 nodemap = nodemap_get_from_exp(info->mti_exp);
164 if (nodemap && !IS_ERR(nodemap)) {
165 audit = nodemap->nmf_enable_audit;
166 nodemap_putref(nodemap);
170 uc->uc_enable_audit = audit;
173 static void ucred_set_rbac_roles(struct mdt_thread_info *info,
176 struct lu_nodemap *nodemap = NULL;
177 enum nodemap_rbac_roles rbac = NODEMAP_RBAC_ALL;
179 if (info && info->mti_exp) {
180 nodemap = nodemap_get_from_exp(info->mti_exp);
181 if (!IS_ERR_OR_NULL(nodemap)) {
182 rbac = nodemap->nmf_rbac;
183 nodemap_putref(nodemap);
187 uc->uc_rbac_file_perms = !!(rbac & NODEMAP_RBAC_FILE_PERMS);
188 uc->uc_rbac_dne_ops = !!(rbac & NODEMAP_RBAC_DNE_OPS);
189 uc->uc_rbac_quota_ops = !!(rbac & NODEMAP_RBAC_QUOTA_OPS);
190 uc->uc_rbac_byfid_ops = !!(rbac & NODEMAP_RBAC_BYFID_OPS);
191 uc->uc_rbac_chlg_ops = !!(rbac & NODEMAP_RBAC_CHLG_OPS);
192 uc->uc_rbac_fscrypt_admin = !!(rbac & NODEMAP_RBAC_FSCRYPT_ADMIN);
195 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
198 struct ptlrpc_request *req = mdt_info_req(info);
199 struct mdt_device *mdt = info->mti_mdt;
200 struct ptlrpc_user_desc *pud = req->rq_user_desc;
201 struct lu_ucred *ucred = mdt_ucred(info);
202 struct lu_nodemap *nodemap;
203 struct lnet_nid peernid = req->rq_peer.nid;
211 LASSERT(req->rq_auth_gss);
212 LASSERT(!req->rq_auth_usr_mdt);
213 LASSERT(req->rq_user_desc);
214 LASSERT(ucred != NULL);
216 ucred->uc_valid = UCRED_INVALID;
218 nodemap = nodemap_get_from_exp(info->mti_exp);
220 RETURN(PTR_ERR(nodemap));
222 pud->pud_uid = nodemap_map_id(nodemap, NODEMAP_UID,
223 NODEMAP_CLIENT_TO_FS, pud->pud_uid);
224 pud->pud_gid = nodemap_map_id(nodemap, NODEMAP_GID,
225 NODEMAP_CLIENT_TO_FS, pud->pud_gid);
226 pud->pud_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
227 NODEMAP_CLIENT_TO_FS, pud->pud_fsuid);
228 pud->pud_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
229 NODEMAP_CLIENT_TO_FS, pud->pud_fsgid);
231 ucred->uc_o_uid = pud->pud_uid;
232 ucred->uc_o_gid = pud->pud_gid;
233 ucred->uc_o_fsuid = pud->pud_fsuid;
234 ucred->uc_o_fsgid = pud->pud_fsgid;
236 if (type == BODY_INIT) {
237 struct mdt_body *body = (struct mdt_body *)buf;
239 ucred->uc_suppgids[0] = body->mbo_suppgid;
240 ucred->uc_suppgids[1] = -1;
243 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
244 req->rq_auth_uid != pud->pud_uid) {
245 CDEBUG(D_SEC, "local client %s: auth uid %u "
246 "while client claims %u:%u/%u:%u\n",
247 libcfs_nidstr(&peernid), req->rq_auth_uid,
248 pud->pud_uid, pud->pud_gid,
249 pud->pud_fsuid, pud->pud_fsgid);
250 GOTO(out_nodemap, rc = -EACCES);
253 if (nodemap && ucred->uc_o_uid == nodemap->nm_squash_uid &&
254 nodemap->nmf_deny_unknown)
255 /* deny access before we get identity ref */
256 GOTO(out, rc = -EACCES);
258 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
259 ucred->uc_identity = NULL;
260 perm = CFS_SETUID_PERM | CFS_SETGID_PERM | CFS_SETGRP_PERM;
262 struct md_identity *identity;
264 identity = mdt_identity_get(mdt->mdt_identity_cache,
266 if (IS_ERR(identity)) {
267 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
268 ucred->uc_identity = NULL;
269 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
273 "Deny access without identity: uid %u\n",
275 GOTO(out_nodemap, rc = -EACCES);
278 ucred->uc_identity = identity;
279 perm = mdt_identity_get_perm(ucred->uc_identity,
284 /* find out the setuid/setgid attempt */
285 setuid = (pud->pud_uid != pud->pud_fsuid);
286 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
287 (ucred->uc_identity &&
288 (pud->pud_gid != ucred->uc_identity->mi_gid)));
290 /* check permission of setuid */
291 if (setuid && !(perm & CFS_SETUID_PERM)) {
292 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
293 pud->pud_uid, pud->pud_fsuid, libcfs_nidstr(&peernid));
294 GOTO(out, rc = -EACCES);
297 /* check permission of setgid */
298 if (setgid && !(perm & CFS_SETGID_PERM)) {
299 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
300 "from %s\n", pud->pud_uid, pud->pud_gid,
301 pud->pud_fsuid, pud->pud_fsgid,
302 ucred->uc_identity->mi_gid, libcfs_nidstr(&peernid));
303 GOTO(out, rc = -EACCES);
306 if (perm & CFS_SETGRP_PERM && pud->pud_ngroups) {
307 /* setgroups for local client */
308 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
309 if (!ucred->uc_ginfo) {
310 CERROR("failed to alloc %d groups\n",
312 GOTO(out, rc = -ENOMEM);
315 lustre_groups_from_list(ucred->uc_ginfo, pud->pud_groups);
316 lustre_groups_sort(ucred->uc_ginfo);
318 ucred->uc_suppgids[0] = -1;
319 ucred->uc_suppgids[1] = -1;
320 ucred->uc_ginfo = NULL;
323 ll_set_capability_u32(&ucred->uc_cap, pud->pud_cap);
325 ucred->uc_uid = pud->pud_uid;
326 ucred->uc_gid = pud->pud_gid;
328 ucred->uc_fsuid = pud->pud_fsuid;
329 ucred->uc_fsgid = pud->pud_fsgid;
331 /* clear suppgids if uid or gid was squashed. */
333 (ucred->uc_o_uid == nodemap->nm_squash_uid ||
334 ucred->uc_o_gid == nodemap->nm_squash_gid)) {
336 ucred->uc_cap = CAP_EMPTY_SET;
337 ucred->uc_suppgids[0] = -1;
338 ucred->uc_suppgids[1] = -1;
339 if (ucred->uc_ginfo) {
340 put_group_info(ucred->uc_ginfo);
341 ucred->uc_ginfo = NULL;
345 mdt_root_squash(info, &peernid);
347 if (ucred->uc_fsuid) {
348 if (!cap_issubset(ucred->uc_cap, mdt->mdt_enable_cap_mask))
349 CDEBUG(D_SEC, "%s: drop capabilities %llx for NID %s\n",
351 #ifdef CAP_FOR_EACH_U32
352 ucred->uc_cap.cap[0] |
353 ((u64)ucred->uc_cap.cap[1] << 32),
357 libcfs_nidstr(&mdt_info_req(info)->rq_peer.nid));
358 ucred->uc_cap = cap_intersect(ucred->uc_cap,
359 mdt->mdt_enable_cap_mask);
362 ucred->uc_valid = UCRED_NEW;
363 ucred_set_jobid(info, ucred);
364 ucred_set_nid(info, ucred);
365 ucred_set_audit_enabled(info, ucred);
366 ucred_set_rbac_roles(info, ucred);
372 if (ucred->uc_ginfo) {
373 put_group_info(ucred->uc_ginfo);
374 ucred->uc_ginfo = NULL;
376 if (ucred->uc_identity) {
377 mdt_identity_put(mdt->mdt_identity_cache,
379 ucred->uc_identity = NULL;
384 nodemap_putref(nodemap);
389 * Check whether allow the client to set supplementary group IDs or not.
391 * \param[in] info pointer to the thread context
392 * \param[in] uc pointer to the RPC user descriptor
394 * \retval true if allow to set supplementary group IDs
395 * \retval false for other cases
397 bool allow_client_chgrp(struct mdt_thread_info *info, struct lu_ucred *uc)
401 /* 1. If identity_upcall is disabled,
402 * permit local client to do anything. */
403 if (is_identity_get_disabled(info->mti_mdt->mdt_identity_cache))
406 /* 2. If fail to get related identities, then forbid any client to
407 * set supplementary group IDs. */
408 if (uc->uc_identity == NULL)
411 /* 3. Check the permission in the identities. */
412 perm = mdt_identity_get_perm(
414 &mdt_info_req(info)->rq_peer.nid);
415 if (perm & CFS_SETGRP_PERM)
421 int mdt_check_ucred(struct mdt_thread_info *info)
423 struct ptlrpc_request *req = mdt_info_req(info);
424 struct mdt_device *mdt = info->mti_mdt;
425 struct ptlrpc_user_desc *pud = req->rq_user_desc;
426 struct lu_ucred *ucred = mdt_ucred(info);
427 struct md_identity *identity = NULL;
428 struct lnet_nid peernid = req->rq_peer.nid;
436 LASSERT(ucred != NULL);
437 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
440 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
443 /* sanity check: if we use strong authentication, we expect the
444 * uid which client claimed is true */
445 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
446 req->rq_auth_uid != pud->pud_uid) {
447 CDEBUG(D_SEC, "local client %s: auth uid %u "
448 "while client claims %u:%u/%u:%u\n",
449 libcfs_nidstr(&peernid), req->rq_auth_uid,
450 pud->pud_uid, pud->pud_gid,
451 pud->pud_fsuid, pud->pud_fsgid);
455 if (is_identity_get_disabled(mdt->mdt_identity_cache))
458 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
459 if (IS_ERR(identity)) {
460 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
463 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
469 perm = mdt_identity_get_perm(identity, &peernid);
470 /* find out the setuid/setgid attempt */
471 setuid = (pud->pud_uid != pud->pud_fsuid);
472 setgid = (pud->pud_gid != pud->pud_fsgid ||
473 pud->pud_gid != identity->mi_gid);
475 /* check permission of setuid */
476 if (setuid && !(perm & CFS_SETUID_PERM)) {
477 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
478 pud->pud_uid, pud->pud_fsuid, libcfs_nidstr(&peernid));
479 GOTO(out, rc = -EACCES);
482 /* check permission of setgid */
483 if (setgid && !(perm & CFS_SETGID_PERM)) {
485 "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) from %s\n",
486 pud->pud_uid, pud->pud_gid,
487 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
488 libcfs_nidstr(&peernid));
489 GOTO(out, rc = -EACCES);
495 mdt_identity_put(mdt->mdt_identity_cache, identity);
499 static int old_init_ucred_common(struct mdt_thread_info *info,
500 struct lu_nodemap *nodemap)
502 struct lu_ucred *uc = mdt_ucred(info);
503 struct mdt_device *mdt = info->mti_mdt;
504 struct md_identity *identity = NULL;
506 if (nodemap && uc->uc_o_uid == nodemap->nm_squash_uid
507 && nodemap->nmf_deny_unknown)
508 /* deny access before we get identity ref */
511 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
512 identity = mdt_identity_get(mdt->mdt_identity_cache,
514 if (IS_ERR(identity)) {
515 if (unlikely(PTR_ERR(identity) == -EREMCHG ||
516 cap_raised(uc->uc_cap,
517 CAP_DAC_READ_SEARCH))) {
520 CDEBUG(D_SEC, "Deny access without identity: "
521 "uid %u\n", uc->uc_fsuid);
526 uc->uc_identity = identity;
529 (uc->uc_o_uid == nodemap->nm_squash_uid ||
530 uc->uc_o_gid == nodemap->nm_squash_gid)) {
532 uc->uc_cap = CAP_EMPTY_SET;
533 uc->uc_suppgids[0] = -1;
534 uc->uc_suppgids[1] = -1;
537 /* process root_squash here. */
538 mdt_root_squash(info,
539 &mdt_info_req(info)->rq_peer.nid);
542 if (!cap_issubset(uc->uc_cap, mdt->mdt_enable_cap_mask))
543 CDEBUG(D_SEC, "%s: drop capabilities %llx for NID %s\n",
545 #ifdef CAP_FOR_EACH_U32
546 uc->uc_cap.cap[0] | ((u64)uc->uc_cap.cap[1]<<32),
550 libcfs_nidstr(&mdt_info_req(info)->rq_peer.nid));
551 uc->uc_cap = cap_intersect(uc->uc_cap,mdt->mdt_enable_cap_mask);
553 uc->uc_valid = UCRED_OLD;
554 ucred_set_jobid(info, uc);
555 ucred_set_nid(info, uc);
556 ucred_set_audit_enabled(info, uc);
557 ucred_set_rbac_roles(info, uc);
564 static int old_init_ucred(struct mdt_thread_info *info,
565 struct mdt_body *body)
567 struct lu_ucred *uc = mdt_ucred(info);
568 struct lu_nodemap *nodemap;
572 nodemap = nodemap_get_from_exp(info->mti_exp);
574 RETURN(PTR_ERR(nodemap));
576 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
577 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
578 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
579 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
580 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
581 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
582 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
583 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
586 uc->uc_valid = UCRED_INVALID;
587 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
588 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
589 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
590 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
591 uc->uc_suppgids[0] = body->mbo_suppgid;
592 uc->uc_suppgids[1] = -1;
594 uc->uc_cap = CAP_EMPTY_SET;
595 ll_set_capability_u32(&uc->uc_cap, body->mbo_capability);
597 rc = old_init_ucred_common(info, nodemap);
598 nodemap_putref(nodemap);
603 static int old_init_ucred_reint(struct mdt_thread_info *info)
605 struct lu_ucred *uc = mdt_ucred(info);
606 struct lu_nodemap *nodemap;
610 nodemap = nodemap_get_from_exp(info->mti_exp);
612 RETURN(PTR_ERR(nodemap));
616 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
617 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
618 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
619 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
621 uc->uc_valid = UCRED_INVALID;
622 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
623 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
626 rc = old_init_ucred_common(info, nodemap);
627 nodemap_putref(nodemap);
632 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
634 struct ptlrpc_request *req = mdt_info_req(info);
635 struct lu_ucred *uc = mdt_ucred(info);
638 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
641 mdt_exit_ucred(info);
643 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
644 return old_init_ucred(info, body);
646 return new_init_ucred(info, BODY_INIT, body);
649 int mdt_init_ucred_reint(struct mdt_thread_info *info)
651 struct ptlrpc_request *req = mdt_info_req(info);
652 struct lu_ucred *uc = mdt_ucred(info);
653 struct md_attr *ma = &info->mti_attr;
656 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
659 /* LU-5564: for normal close request, skip permission check */
660 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE &&
661 !(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP))) {
662 cap_raise_nfsd_set(uc->uc_cap, CAP_FULL_SET);
663 cap_raise_fs_set(uc->uc_cap, CAP_FULL_SET);
666 mdt_exit_ucred(info);
668 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
669 return old_init_ucred_reint(info);
671 return new_init_ucred(info, REC_INIT, NULL);
674 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
675 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
677 const struct lov_ost_data_v1 *lod;
678 __u32 lmm_magic = le32_to_cpu(lmm->lmm_magic);
682 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
685 CDEBUG_LIMIT(level, "objid="DOSTID" magic=0x%08X pattern=%#X\n",
686 POSTID(&lmm->lmm_oi), lmm_magic,
687 le32_to_cpu(lmm->lmm_pattern));
689 /* No support for compound layouts yet */
690 if (lmm_magic != LOV_MAGIC_V1 && lmm_magic != LOV_MAGIC_V3)
693 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
694 CDEBUG_LIMIT(level, "stripe_size=0x%x, %sstripe_count=0x%x\n",
695 le32_to_cpu(lmm->lmm_stripe_size),
696 count > LOV_MAX_STRIPE_COUNT ? "bad " : "", count);
698 /* If it's a directory or a released file, then there are
699 * no actual objects to print, so bail out. */
700 if (valid & OBD_MD_FLDIREA ||
701 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
704 if (unlikely(count > LOV_MAX_STRIPE_COUNT))
707 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
710 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
711 CDEBUG_LIMIT(level, "stripe %u idx %u subobj "DOSTID"\n",
712 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
716 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
718 const struct lmv_mds_md_v1 *lmm1;
719 const struct lmv_foreign_md *lfm;
722 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
725 /* foreign LMV case */
726 lfm = &lmv->lmv_foreign_md;
727 if (le32_to_cpu(lfm->lfm_magic) == LMV_MAGIC_FOREIGN) {
729 "foreign magic 0x%08X, length %u, type %u, flags %u, value '%.*s'\n",
730 le32_to_cpu(lfm->lfm_magic),
731 le32_to_cpu(lfm->lfm_length),
732 le32_to_cpu(lfm->lfm_type),
733 le32_to_cpu(lfm->lfm_flags),
734 le32_to_cpu(lfm->lfm_length), lfm->lfm_value);
738 lmm1 = &lmv->lmv_md_v1;
740 "magic 0x%08X, master %#X stripe_count %d hash_type %#x\n",
741 le32_to_cpu(lmm1->lmv_magic),
742 le32_to_cpu(lmm1->lmv_master_mdt_index),
743 le32_to_cpu(lmm1->lmv_stripe_count),
744 le32_to_cpu(lmm1->lmv_hash_type));
746 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
749 if (le32_to_cpu(lmm1->lmv_stripe_count) > LMV_MAX_STRIPE_COUNT)
752 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
755 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
756 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
760 /* Shrink and/or grow reply buffers */
761 int mdt_fix_reply(struct mdt_thread_info *info)
763 struct req_capsule *pill = info->mti_pill;
764 struct mdt_body *body;
765 int md_size, md_packed = 0;
770 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
771 LASSERT(body != NULL);
773 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
775 md_size = body->mbo_eadatasize;
779 acl_size = body->mbo_aclsize;
781 /* this replay - not send info to client */
782 if (info->mti_spec.no_create) {
787 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
792 &RMF_ACL, or &RMF_LOGCOOKIES
793 (optional) &RMF_CAPA1,
794 (optional) &RMF_CAPA2,
795 (optional) something else
798 /* MDT_MD buffer may be bigger than packed value, let's shrink all
799 * buffers before growing it */
800 if (info->mti_big_lmm_used) {
801 /* big_lmm buffer may be used even without packing the result
802 * into reply, just for internal server needs */
803 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
804 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
807 /* free big lmm if md_size is not needed */
808 if (md_size == 0 || md_packed == 0) {
809 info->mti_big_lmm_used = 0;
811 /* buffer must be allocated separately */
812 LASSERT(info->mti_attr.ma_lmm !=
813 req_capsule_server_get(pill, &RMF_MDT_MD));
814 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
816 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
817 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
820 if (info->mti_big_acl_used) {
822 info->mti_big_acl_used = 0;
824 req_capsule_shrink(pill, &RMF_ACL, 0, RCL_SERVER);
825 } else if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER)) {
826 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
827 } else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
828 req_capsule_shrink(pill, &RMF_LOGCOOKIES, acl_size, RCL_SERVER);
831 /* Shrink optional SECCTX buffer if it is not used */
832 if (req_capsule_has_field(pill, &RMF_FILE_SECCTX, RCL_SERVER) &&
833 req_capsule_get_size(pill, &RMF_FILE_SECCTX, RCL_SERVER) != 0 &&
834 !(body->mbo_valid & OBD_MD_SECCTX))
835 req_capsule_shrink(pill, &RMF_FILE_SECCTX, 0, RCL_SERVER);
837 /* Shrink optional ENCCTX buffer if it is not used */
838 if (req_capsule_has_field(pill, &RMF_FILE_ENCCTX, RCL_SERVER) &&
839 req_capsule_get_size(pill, &RMF_FILE_ENCCTX, RCL_SERVER) != 0 &&
840 !(body->mbo_valid & OBD_MD_ENCCTX))
841 req_capsule_shrink(pill, &RMF_FILE_ENCCTX, 0, RCL_SERVER);
843 /* Shrink optional default LMV buffer if it is not used */
844 if (req_capsule_has_field(pill, &RMF_DEFAULT_MDT_MD, RCL_SERVER) &&
845 req_capsule_get_size(pill, &RMF_DEFAULT_MDT_MD, RCL_SERVER) != 0 &&
846 !(body->mbo_valid & OBD_MD_DEFAULT_MEA))
847 req_capsule_shrink(pill, &RMF_DEFAULT_MDT_MD, 0, RCL_SERVER);
850 * Some more field should be shrinked if needed.
851 * This should be done by those who added fields to reply message.
854 /* Grow MD buffer if needed finally */
855 if (info->mti_big_lmm_used) {
858 LASSERT(md_size > md_packed);
859 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
860 md_size - md_packed);
862 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
864 /* we can't answer with proper LOV EA, drop flags,
865 * the rc is also returned so this request is
866 * considered as failed */
867 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
868 /* don't return transno along with error */
869 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
871 /* now we need to pack right LOV/LMV EA */
872 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
873 if (info->mti_attr.ma_valid & MA_LOV) {
874 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
876 info->mti_attr.ma_lmm_size);
877 memcpy(lmm, info->mti_attr.ma_lmm,
878 info->mti_attr.ma_lmm_size);
879 } else if (info->mti_attr.ma_valid & MA_LMV) {
880 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
882 info->mti_attr.ma_lmv_size);
883 memcpy(lmm, info->mti_attr.ma_lmv,
884 info->mti_attr.ma_lmv_size);
888 /* update mdt_max_mdsize so clients will be aware about that */
889 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
890 info->mti_mdt->mdt_max_mdsize =
891 info->mti_attr.ma_lmm_size;
892 info->mti_big_lmm_used = 0;
895 if (info->mti_big_acl_used) {
896 CDEBUG(D_INFO, "Enlarge reply ACL buffer to %d bytes\n",
899 rc = req_capsule_server_grow(pill, &RMF_ACL, acl_size);
901 body->mbo_valid &= ~OBD_MD_FLACL;
903 void *acl = req_capsule_server_get(pill, &RMF_ACL);
905 memcpy(acl, info->mti_big_acl, acl_size);
908 info->mti_big_acl_used = 0;
915 /* if object is dying, pack the lov/llog data,
916 * parameter info->mti_attr should be valid at this point!
917 * Also implements RAoLU policy */
918 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
921 struct mdt_body *repbody = NULL;
922 const struct lu_attr *la = &ma->ma_attr;
923 struct coordinator *cdt = &info->mti_mdt->mdt_coordinator;
926 struct hsm_action_item hai = {
927 .hai_len = sizeof(hai),
928 .hai_action = HSMA_REMOVE,
929 .hai_extent.length = -1,
937 if (mdt_info_req(info) != NULL) {
938 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
939 LASSERT(repbody != NULL);
941 CDEBUG(D_INFO, "not running in a request/reply context\n");
944 if ((ma->ma_valid & MA_INODE) && repbody != NULL)
945 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
947 if (ma->ma_valid & MA_LOV) {
948 CERROR("No need in LOV EA upon unlink\n");
952 repbody->mbo_eadatasize = 0;
954 /* Only check unlinked and archived if RAoLU and upon last close */
955 if (!cdt->cdt_remove_archive_on_last_unlink ||
956 atomic_read(&mo->mot_open_count) != 0)
959 /* mdt_attr_get_complex will clear ma_valid, so check here first */
960 if ((ma->ma_valid & MA_INODE) && (ma->ma_attr.la_nlink != 0))
963 if ((ma->ma_valid & MA_HSM) && (!(ma->ma_hsm.mh_flags & HS_EXISTS)))
966 need |= (MA_INODE | MA_HSM) & ~ma->ma_valid;
968 /* ma->ma_valid is missing either MA_INODE, MA_HSM, or both,
969 * try setting them */
971 rc = mdt_attr_get_complex(info, mo, ma);
973 CERROR("%s: unable to fetch missing attributes of"
974 DFID": rc=%d\n", mdt_obd_name(info->mti_mdt),
975 PFID(mdt_object_fid(mo)), rc);
979 if (need & MA_INODE) {
980 if (ma->ma_valid & MA_INODE) {
981 if (ma->ma_attr.la_nlink != 0)
989 if (ma->ma_valid & MA_HSM) {
990 if (!(ma->ma_hsm.mh_flags & HS_EXISTS))
998 /* RAoLU policy is active, last close on file has occured,
999 * file is unlinked, file is archived, so create remove request
1001 * If CDT is not running, requests will be logged for later. */
1002 if (ma->ma_hsm.mh_arch_id != 0)
1003 archive_id = ma->ma_hsm.mh_arch_id;
1005 archive_id = cdt->cdt_default_archive_id;
1007 hai.hai_fid = *mdt_object_fid(mo);
1009 rc = mdt_agent_record_add(info->mti_env, info->mti_mdt, archive_id, 0,
1012 CERROR("%s: unable to add HSM remove request for "DFID
1013 ": rc=%d\n", mdt_obd_name(info->mti_mdt),
1014 PFID(mdt_object_fid(mo)), rc);
1019 static __u64 mdt_attr_valid_xlate(enum mds_attr_flags in,
1020 struct mdt_reint_record *rr,
1026 if (in & MDS_ATTR_MODE)
1028 if (in & MDS_ATTR_UID)
1030 if (in & MDS_ATTR_GID)
1032 if (in & MDS_ATTR_SIZE)
1034 if (in & MDS_ATTR_BLOCKS)
1036 if (in & MDS_ATTR_ATIME_SET)
1038 if (in & MDS_ATTR_CTIME_SET)
1040 if (in & MDS_ATTR_MTIME_SET)
1042 if (in & MDS_ATTR_ATTR_FLAG)
1044 if (in & MDS_ATTR_KILL_SUID)
1045 out |= LA_KILL_SUID;
1046 if (in & MDS_ATTR_KILL_SGID)
1047 out |= LA_KILL_SGID;
1048 if (in & MDS_ATTR_PROJID)
1050 if (in & MDS_ATTR_LSIZE)
1052 if (in & MDS_ATTR_LBLOCKS)
1055 if (in & MDS_ATTR_FROM_OPEN)
1056 rr->rr_flags |= MRF_OPEN_TRUNC;
1057 if (in & MDS_ATTR_OVERRIDE)
1058 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
1059 if (in & MDS_ATTR_FORCE)
1060 ma->ma_attr_flags |= MDS_PERM_BYPASS;
1062 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID | MDS_ATTR_PROJID |
1063 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
1064 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
1065 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
1066 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
1067 MDS_ATTR_FROM_OPEN | MDS_ATTR_LSIZE | MDS_ATTR_LBLOCKS |
1070 CDEBUG(D_INFO, "Unknown attr bits: %#llx\n", (u64)in);
1077 int mdt_name_unpack(struct req_capsule *pill,
1078 const struct req_msg_field *field,
1080 enum mdt_name_flags flags)
1082 ln->ln_name = req_capsule_client_get(pill, field);
1083 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
1085 if (!lu_name_is_valid(ln)) {
1092 if ((flags & MNF_FIX_ANON) &&
1093 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
1094 /* Newer (3.x) kernels use a name of "/" for the
1095 * "anonymous" disconnected dentries from NFS
1096 * filehandle conversion. See d_obtain_alias(). */
1104 static int mdt_file_secctx_unpack(struct req_capsule *pill,
1105 const char **secctx_name,
1106 void **secctx, size_t *secctx_size)
1111 *secctx_name = NULL;
1115 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT) ||
1116 !req_capsule_field_present(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT))
1119 name_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX_NAME,
1124 if (name_size > XATTR_NAME_MAX + 1)
1127 name = req_capsule_client_get(pill, &RMF_FILE_SECCTX_NAME);
1128 if (strnlen(name, name_size) != name_size - 1)
1131 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX, RCL_CLIENT) ||
1132 !req_capsule_field_present(pill, &RMF_FILE_SECCTX, RCL_CLIENT))
1135 *secctx_name = name;
1136 *secctx = req_capsule_client_get(pill, &RMF_FILE_SECCTX);
1137 *secctx_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX, RCL_CLIENT);
1142 static int mdt_file_encctx_unpack(struct req_capsule *pill,
1143 void **encctx, size_t *encctx_size)
1148 if (!exp_connect_encrypt(pill->rc_req->rq_export))
1151 if (!req_capsule_has_field(pill, &RMF_FILE_ENCCTX, RCL_CLIENT) ||
1152 !req_capsule_field_present(pill, &RMF_FILE_ENCCTX, RCL_CLIENT))
1155 *encctx_size = req_capsule_get_size(pill, &RMF_FILE_ENCCTX, RCL_CLIENT);
1156 if (*encctx_size == 0)
1159 *encctx = req_capsule_client_get(pill, &RMF_FILE_ENCCTX);
1164 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
1166 struct lu_ucred *uc = mdt_ucred(info);
1167 struct md_attr *ma = &info->mti_attr;
1168 struct lu_attr *la = &ma->ma_attr;
1169 struct req_capsule *pill = info->mti_pill;
1170 struct mdt_reint_record *rr = &info->mti_rr;
1171 struct mdt_rec_setattr *rec;
1172 struct lu_nodemap *nodemap;
1176 BUILD_BUG_ON(sizeof(*rec) != sizeof(struct mdt_rec_reint));
1177 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1181 /* This prior initialization is needed for old_init_ucred_reint() */
1182 uc->uc_fsuid = rec->sa_fsuid;
1183 uc->uc_fsgid = rec->sa_fsgid;
1184 uc->uc_cap = CAP_EMPTY_SET;
1185 ll_set_capability_u32(&uc->uc_cap, rec->sa_cap);
1186 uc->uc_suppgids[0] = rec->sa_suppgid;
1187 uc->uc_suppgids[1] = -1;
1189 rr->rr_fid1 = &rec->sa_fid;
1190 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
1191 la->la_mode = rec->sa_mode;
1192 la->la_flags = rec->sa_attr_flags;
1194 nodemap = nodemap_get_from_exp(info->mti_exp);
1195 if (IS_ERR(nodemap))
1196 RETURN(PTR_ERR(nodemap));
1198 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
1199 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
1200 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
1201 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
1202 la->la_projid = nodemap_map_id(nodemap, NODEMAP_PROJID,
1203 NODEMAP_CLIENT_TO_FS, rec->sa_projid);
1204 nodemap_putref(nodemap);
1206 la->la_size = rec->sa_size;
1207 la->la_blocks = rec->sa_blocks;
1208 la->la_ctime = rec->sa_ctime;
1209 la->la_atime = rec->sa_atime;
1210 la->la_mtime = rec->sa_mtime;
1211 ma->ma_valid = MA_INODE;
1213 ma->ma_attr_flags |= rec->sa_bias & (MDS_CLOSE_INTENT |
1214 MDS_DATA_MODIFIED | MDS_TRUNC_KEEP_LEASE |
1215 MDS_PCC_ATTACH | MDS_CLOSE_LAYOUT_SWAP_HSM);
1219 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
1221 struct req_capsule *pill = info->mti_pill;
1222 struct mdt_ioepoch *ioepoch;
1225 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
1226 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
1230 if (ioepoch == NULL)
1233 info->mti_open_handle = ioepoch->mio_open_handle;
1238 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
1239 struct req_capsule *pill = info->mti_pill;
1241 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
1242 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
1243 if (info->mti_dlm_req == NULL)
1250 static int mdt_setattr_unpack(struct mdt_thread_info *info)
1252 struct mdt_reint_record *rr = &info->mti_rr;
1253 struct md_attr *ma = &info->mti_attr;
1254 struct req_capsule *pill = info->mti_pill;
1258 rc = mdt_setattr_unpack_rec(info);
1262 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1263 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1264 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1267 if (rr->rr_eadatalen > 0) {
1268 const struct lmv_user_md *lum;
1270 lum = rr->rr_eadata;
1271 /* Sigh ma_valid(from req) does not indicate whether
1272 * it will set LOV/LMV EA, so we have to check magic */
1273 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1274 ma->ma_valid |= MA_LMV;
1275 ma->ma_lmv = (void *)rr->rr_eadata;
1276 ma->ma_lmv_size = rr->rr_eadatalen;
1278 ma->ma_valid |= MA_LOV;
1279 ma->ma_lmm = (void *)rr->rr_eadata;
1280 ma->ma_lmm_size = rr->rr_eadatalen;
1285 rc = mdt_dlmreq_unpack(info);
1289 static int mdt_close_intent_unpack(struct mdt_thread_info *info)
1291 struct md_attr *ma = &info->mti_attr;
1292 struct req_capsule *pill = info->mti_pill;
1295 if (!(ma->ma_attr_flags & MDS_CLOSE_INTENT))
1298 req_capsule_extend(pill, &RQF_MDS_CLOSE_INTENT);
1300 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1301 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1307 int mdt_close_unpack(struct mdt_thread_info *info)
1312 rc = mdt_close_handle_unpack(info);
1316 rc = mdt_setattr_unpack_rec(info);
1320 rc = mdt_close_intent_unpack(info);
1324 RETURN(mdt_init_ucred_reint(info));
1327 static int mdt_create_unpack(struct mdt_thread_info *info)
1329 struct lu_ucred *uc = mdt_ucred(info);
1330 struct mdt_rec_create *rec;
1331 struct lu_attr *attr = &info->mti_attr.ma_attr;
1332 struct mdt_reint_record *rr = &info->mti_rr;
1333 struct req_capsule *pill = info->mti_pill;
1334 struct md_op_spec *sp = &info->mti_spec;
1339 BUILD_BUG_ON(sizeof(*rec) != sizeof(struct mdt_rec_reint));
1340 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1344 /* This prior initialization is needed for old_init_ucred_reint() */
1345 uc->uc_fsuid = rec->cr_fsuid;
1346 uc->uc_fsgid = rec->cr_fsgid;
1347 uc->uc_cap = CAP_EMPTY_SET;
1348 ll_set_capability_u32(&uc->uc_cap, rec->cr_cap);
1349 uc->uc_suppgids[0] = rec->cr_suppgid1;
1350 uc->uc_suppgids[1] = -1;
1351 uc->uc_umask = rec->cr_umask;
1353 rr->rr_fid1 = &rec->cr_fid1;
1354 rr->rr_fid2 = &rec->cr_fid2;
1355 attr->la_mode = rec->cr_mode;
1356 attr->la_rdev = rec->cr_rdev;
1357 attr->la_uid = rec->cr_fsuid;
1358 attr->la_gid = rec->cr_fsgid;
1359 attr->la_ctime = rec->cr_time;
1360 attr->la_mtime = rec->cr_time;
1361 attr->la_atime = rec->cr_time;
1362 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1363 LA_CTIME | LA_MTIME | LA_ATIME;
1364 memset(&sp->u, 0, sizeof(sp->u));
1365 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1367 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1371 if (S_ISLNK(attr->la_mode)) {
1372 const char *tgt = NULL;
1375 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1376 sz = req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT);
1378 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1379 sp->u.sp_symname.ln_name = tgt;
1380 sp->u.sp_symname.ln_namelen = sz - 1; /* skip NUL */
1385 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_ACL);
1386 if (S_ISDIR(attr->la_mode)) {
1387 struct obd_export *exp = mdt_info_req(info)->rq_export;
1389 sp->sp_dmv_imp_inherit =
1390 info->mti_mdt->mdt_enable_dmv_implicit_inherit;
1391 if (req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT)
1393 sp->u.sp_ea.eadata =
1394 req_capsule_client_get(pill,
1396 sp->u.sp_ea.eadatalen =
1397 req_capsule_get_size(pill, &RMF_EADATA,
1399 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1401 if (OCD_HAS_FLAG2(&exp->exp_connect_data,
1403 if ((sp->sp_cr_flags & MDS_OPEN_DEFAULT_LMV) &&
1404 !(sp->sp_cr_flags & MDS_OPEN_HAS_EA))
1406 } else if (sp->sp_cr_flags & MDS_OPEN_DEFAULT_LMV) {
1412 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1413 &sp->sp_cr_file_secctx,
1414 &sp->sp_cr_file_secctx_size);
1418 rc = mdt_file_encctx_unpack(pill, &sp->sp_cr_file_encctx,
1419 &sp->sp_cr_file_encctx_size);
1423 rc = req_check_sepol(pill);
1427 rc = mdt_dlmreq_unpack(info);
1431 static int mdt_link_unpack(struct mdt_thread_info *info)
1433 struct lu_ucred *uc = mdt_ucred(info);
1434 struct mdt_rec_link *rec;
1435 struct lu_attr *attr = &info->mti_attr.ma_attr;
1436 struct mdt_reint_record *rr = &info->mti_rr;
1437 struct req_capsule *pill = info->mti_pill;
1442 BUILD_BUG_ON(sizeof(*rec) != sizeof(struct mdt_rec_reint));
1443 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1447 /* This prior initialization is needed for old_init_ucred_reint() */
1448 uc->uc_fsuid = rec->lk_fsuid;
1449 uc->uc_fsgid = rec->lk_fsgid;
1450 uc->uc_cap = CAP_EMPTY_SET;
1451 ll_set_capability_u32(&uc->uc_cap, rec->lk_cap);
1452 uc->uc_suppgids[0] = rec->lk_suppgid1;
1453 uc->uc_suppgids[1] = rec->lk_suppgid2;
1455 attr->la_uid = rec->lk_fsuid;
1456 attr->la_gid = rec->lk_fsgid;
1457 rr->rr_fid1 = &rec->lk_fid1;
1458 rr->rr_fid2 = &rec->lk_fid2;
1459 attr->la_ctime = rec->lk_time;
1460 attr->la_mtime = rec->lk_time;
1461 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1463 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1467 rc = req_check_sepol(pill);
1471 rc = mdt_dlmreq_unpack(info);
1476 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1478 struct lu_ucred *uc = mdt_ucred(info);
1479 struct mdt_rec_unlink *rec;
1480 struct lu_attr *attr = &info->mti_attr.ma_attr;
1481 struct mdt_reint_record *rr = &info->mti_rr;
1482 struct req_capsule *pill = info->mti_pill;
1487 BUILD_BUG_ON(sizeof(*rec) != sizeof(struct mdt_rec_reint));
1488 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1492 /* This prior initialization is needed for old_init_ucred_reint() */
1493 uc->uc_fsuid = rec->ul_fsuid;
1494 uc->uc_fsgid = rec->ul_fsgid;
1495 uc->uc_cap = CAP_EMPTY_SET;
1496 ll_set_capability_u32(&uc->uc_cap, rec->ul_cap);
1497 uc->uc_suppgids[0] = rec->ul_suppgid1;
1498 uc->uc_suppgids[1] = -1;
1500 attr->la_uid = rec->ul_fsuid;
1501 attr->la_gid = rec->ul_fsgid;
1502 rr->rr_fid1 = &rec->ul_fid1;
1503 rr->rr_fid2 = &rec->ul_fid2;
1504 attr->la_ctime = rec->ul_time;
1505 attr->la_mtime = rec->ul_time;
1506 attr->la_mode = rec->ul_mode;
1507 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1508 if (rec->ul_bias & MDS_FID_OP)
1509 info->mti_spec.sp_cr_flags |= MDS_OP_WITH_FID;
1511 info->mti_spec.sp_cr_flags &= ~MDS_OP_WITH_FID;
1513 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1517 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1519 rc = req_check_sepol(pill);
1523 rc = mdt_dlmreq_unpack(info);
1527 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1529 info->mti_spec.sp_rm_entry = 1;
1530 return mdt_unlink_unpack(info);
1533 static int mdt_rename_unpack(struct mdt_thread_info *info)
1535 struct lu_ucred *uc = mdt_ucred(info);
1536 struct mdt_rec_rename *rec;
1537 struct lu_attr *attr = &info->mti_attr.ma_attr;
1538 struct mdt_reint_record *rr = &info->mti_rr;
1539 struct req_capsule *pill = info->mti_pill;
1540 struct md_op_spec *spec = &info->mti_spec;
1545 BUILD_BUG_ON(sizeof(*rec) != sizeof(struct mdt_rec_reint));
1546 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1550 /* This prior initialization is needed for old_init_ucred_reint() */
1551 uc->uc_fsuid = rec->rn_fsuid;
1552 uc->uc_fsgid = rec->rn_fsgid;
1553 uc->uc_cap = CAP_EMPTY_SET;
1554 ll_set_capability_u32(&uc->uc_cap, rec->rn_cap);
1555 uc->uc_suppgids[0] = rec->rn_suppgid1;
1556 uc->uc_suppgids[1] = rec->rn_suppgid2;
1558 attr->la_uid = rec->rn_fsuid;
1559 attr->la_gid = rec->rn_fsgid;
1560 rr->rr_fid1 = &rec->rn_fid1;
1561 rr->rr_fid2 = &rec->rn_fid2;
1562 attr->la_ctime = rec->rn_time;
1563 attr->la_mtime = rec->rn_time;
1564 /* rename_tgt contains the mode already */
1565 attr->la_mode = rec->rn_mode;
1566 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1568 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1572 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1576 spec->no_create = !!req_is_replay(mdt_info_req(info));
1578 rc = req_check_sepol(pill);
1582 rc = mdt_dlmreq_unpack(info);
1587 static int mdt_migrate_unpack(struct mdt_thread_info *info)
1589 struct lu_ucred *uc = mdt_ucred(info);
1590 struct mdt_rec_rename *rec;
1591 struct lu_attr *attr = &info->mti_attr.ma_attr;
1592 struct mdt_reint_record *rr = &info->mti_rr;
1593 struct req_capsule *pill = info->mti_pill;
1594 struct md_op_spec *spec = &info->mti_spec;
1599 BUILD_BUG_ON(sizeof(*rec) != sizeof(struct mdt_rec_reint));
1600 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1604 /* This prior initialization is needed for old_init_ucred_reint() */
1605 uc->uc_fsuid = rec->rn_fsuid;
1606 uc->uc_fsgid = rec->rn_fsgid;
1607 uc->uc_cap = CAP_EMPTY_SET;
1608 ll_set_capability_u32(&uc->uc_cap, rec->rn_cap);
1609 uc->uc_suppgids[0] = rec->rn_suppgid1;
1610 uc->uc_suppgids[1] = rec->rn_suppgid2;
1612 attr->la_uid = rec->rn_fsuid;
1613 attr->la_gid = rec->rn_fsgid;
1614 rr->rr_fid1 = &rec->rn_fid1;
1615 rr->rr_fid2 = &rec->rn_fid2;
1616 attr->la_ctime = rec->rn_time;
1617 attr->la_mtime = rec->rn_time;
1618 /* rename_tgt contains the mode already */
1619 attr->la_mode = rec->rn_mode;
1620 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1621 spec->sp_cr_flags = 0;
1623 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1627 if (rec->rn_bias & MDS_CLOSE_MIGRATE) {
1628 rc = mdt_close_handle_unpack(info);
1632 spec->sp_migrate_close = 1;
1634 spec->sp_migrate_close = 0;
1637 spec->sp_migrate_nsonly = !!(rec->rn_bias & MDS_MIGRATE_NSONLY);
1639 /* lustre version > 2.11 migration packs lum */
1640 if (req_capsule_has_field(pill, &RMF_EADATA, RCL_CLIENT)) {
1641 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1642 rr->rr_eadatalen = req_capsule_get_size(pill,
1646 if (rr->rr_eadatalen > 0) {
1647 struct lmv_user_md_v1 *lmu;
1649 lmu = req_capsule_client_get(pill, &RMF_EADATA);
1650 lmu->lum_hash_type |=
1651 cpu_to_le32(LMV_HASH_FLAG_FIXED);
1652 rr->rr_eadata = lmu;
1653 spec->u.sp_ea.eadatalen = rr->rr_eadatalen;
1654 spec->u.sp_ea.eadata = rr->rr_eadata;
1655 spec->sp_cr_flags |= MDS_OPEN_HAS_EA;
1658 /* old client doesn't provide lum. */
1659 RETURN(-EOPNOTSUPP);
1663 spec->no_create = !!req_is_replay(mdt_info_req(info));
1665 rc = mdt_dlmreq_unpack(info);
1671 * please see comment above LOV_MAGIC_V1_DEFINED
1673 void mdt_fix_lov_magic(struct mdt_thread_info *info, void *eadata)
1675 struct lov_user_md_v1 *v1 = eadata;
1679 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1680 if ((v1->lmm_magic & LOV_MAGIC_MASK) == LOV_MAGIC_MAGIC)
1681 v1->lmm_magic |= LOV_MAGIC_DEFINED;
1682 else if ((v1->lmm_magic & __swab32(LOV_MAGIC_MAGIC)) ==
1683 __swab32(LOV_MAGIC_MAGIC))
1684 v1->lmm_magic |= __swab32(LOV_MAGIC_DEFINED);
1688 static int mdt_open_unpack(struct mdt_thread_info *info)
1690 struct lu_ucred *uc = mdt_ucred(info);
1691 struct mdt_rec_create *rec;
1692 struct lu_attr *attr = &info->mti_attr.ma_attr;
1693 struct req_capsule *pill = info->mti_pill;
1694 struct mdt_reint_record *rr = &info->mti_rr;
1695 struct ptlrpc_request *req = mdt_info_req(info);
1696 struct md_op_spec *sp = &info->mti_spec;
1700 BUILD_BUG_ON(sizeof(struct mdt_rec_create) !=
1701 sizeof(struct mdt_rec_reint));
1702 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1706 /* This prior initialization is needed for old_init_ucred_reint() */
1707 uc->uc_fsuid = rec->cr_fsuid;
1708 uc->uc_fsgid = rec->cr_fsgid;
1709 uc->uc_cap = CAP_EMPTY_SET;
1710 ll_set_capability_u32(&uc->uc_cap, rec->cr_cap);
1711 uc->uc_suppgids[0] = rec->cr_suppgid1;
1712 uc->uc_suppgids[1] = rec->cr_suppgid2;
1713 uc->uc_umask = rec->cr_umask;
1715 rr->rr_fid1 = &rec->cr_fid1;
1716 rr->rr_fid2 = &rec->cr_fid2;
1717 rr->rr_open_handle = &rec->cr_open_handle_old;
1718 attr->la_mode = rec->cr_mode;
1719 attr->la_rdev = rec->cr_rdev;
1720 attr->la_uid = rec->cr_fsuid;
1721 attr->la_gid = rec->cr_fsgid;
1722 attr->la_ctime = rec->cr_time;
1723 attr->la_mtime = rec->cr_time;
1724 attr->la_atime = rec->cr_time;
1725 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1726 LA_CTIME | LA_MTIME | LA_ATIME;
1727 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1728 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1729 /* Do not trigger ASSERTION if client miss to set such flags. */
1730 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1733 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1735 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1737 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1738 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1741 if (rr->rr_eadatalen > 0) {
1742 rr->rr_eadata = req_capsule_client_get(pill,
1744 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1745 sp->u.sp_ea.eadata = rr->rr_eadata;
1746 sp->sp_archive_id = rec->cr_archive_id;
1747 sp->no_create = !!req_is_replay(req);
1748 mdt_fix_lov_magic(info, rr->rr_eadata);
1752 * Client default md_size may be 0 right after client start,
1753 * until all osc are connected, set here just some reasonable
1754 * value to prevent misbehavior.
1756 if (rr->rr_eadatalen == 0 &&
1757 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1758 rr->rr_eadatalen = MIN_MD_SIZE;
1761 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1762 &sp->sp_cr_file_secctx,
1763 &sp->sp_cr_file_secctx_size);
1767 rc = mdt_file_encctx_unpack(pill, &sp->sp_cr_file_encctx,
1768 &sp->sp_cr_file_encctx_size);
1772 rc = req_check_sepol(pill);
1779 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1781 struct mdt_reint_record *rr = &info->mti_rr;
1782 struct lu_ucred *uc = mdt_ucred(info);
1783 struct lu_attr *attr = &info->mti_attr.ma_attr;
1784 struct req_capsule *pill = info->mti_pill;
1785 struct mdt_rec_setxattr *rec;
1790 BUILD_BUG_ON(sizeof(struct mdt_rec_setxattr) !=
1791 sizeof(struct mdt_rec_reint));
1792 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1796 /* This prior initialization is needed for old_init_ucred_reint() */
1797 uc->uc_fsuid = rec->sx_fsuid;
1798 uc->uc_fsgid = rec->sx_fsgid;
1799 uc->uc_cap = CAP_EMPTY_SET;
1800 ll_set_capability_u32(&uc->uc_cap, rec->sx_cap);
1801 uc->uc_suppgids[0] = rec->sx_suppgid1;
1802 uc->uc_suppgids[1] = -1;
1804 rr->rr_opcode = rec->sx_opcode;
1805 rr->rr_fid1 = &rec->sx_fid;
1806 attr->la_valid = rec->sx_valid;
1807 attr->la_ctime = rec->sx_time;
1808 attr->la_size = rec->sx_size;
1809 attr->la_flags = rec->sx_flags;
1811 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1815 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1816 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1819 if (rr->rr_eadatalen > info->mti_mdt->mdt_max_ea_size)
1822 if (rr->rr_eadatalen > 0) {
1823 rr->rr_eadata = req_capsule_client_get(pill,
1825 if (rr->rr_eadata == NULL)
1828 rr->rr_eadata = NULL;
1830 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1831 CDEBUG(D_INFO, "no xattr data supplied\n");
1835 rc = req_check_sepol(pill);
1839 if (mdt_dlmreq_unpack(info) < 0)
1845 static int mdt_resync_unpack(struct mdt_thread_info *info)
1847 struct req_capsule *pill = info->mti_pill;
1848 struct mdt_reint_record *rr = &info->mti_rr;
1849 struct lu_ucred *uc = mdt_ucred(info);
1850 struct mdt_rec_resync *rec;
1853 BUILD_BUG_ON(sizeof(*rec) != sizeof(struct mdt_rec_reint));
1854 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1858 /* This prior initialization is needed for old_init_ucred_reint() */
1859 uc->uc_fsuid = rec->rs_fsuid;
1860 uc->uc_fsgid = rec->rs_fsgid;
1861 uc->uc_cap = CAP_EMPTY_SET;
1862 ll_set_capability_u32(&uc->uc_cap, rec->rs_cap);
1864 rr->rr_fid1 = &rec->rs_fid;
1865 rr->rr_mirror_id = rec->rs_mirror_id;
1867 /* cookie doesn't need to be swapped but it has been swapped
1868 * in lustre_swab_mdt_rec_reint() as rr_mtime, so here it needs
1870 if (req_capsule_req_need_swab(pill))
1871 __swab64s(&rec->rs_lease_handle.cookie);
1872 rr->rr_lease_handle = &rec->rs_lease_handle;
1874 RETURN(mdt_dlmreq_unpack(info));
1877 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1879 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1880 [REINT_SETATTR] = mdt_setattr_unpack,
1881 [REINT_CREATE] = mdt_create_unpack,
1882 [REINT_LINK] = mdt_link_unpack,
1883 [REINT_UNLINK] = mdt_unlink_unpack,
1884 [REINT_RENAME] = mdt_rename_unpack,
1885 [REINT_OPEN] = mdt_open_unpack,
1886 [REINT_SETXATTR] = mdt_setxattr_unpack,
1887 [REINT_RMENTRY] = mdt_rmentry_unpack,
1888 [REINT_MIGRATE] = mdt_migrate_unpack,
1889 [REINT_RESYNC] = mdt_resync_unpack,
1892 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1897 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1898 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1899 info->mti_rr.rr_opcode = op;
1900 rc = mdt_reint_unpackers[op](info);
1902 CERROR("Unexpected opcode %d\n", op);
1908 int mdt_pack_secctx_in_reply(struct mdt_thread_info *info,
1909 struct mdt_object *child)
1912 struct lu_buf *buffer;
1913 struct mdt_body *repbody;
1914 struct req_capsule *pill = info->mti_pill;
1917 if (req_capsule_has_field(pill, &RMF_FILE_SECCTX, RCL_SERVER) &&
1918 req_capsule_get_size(pill, &RMF_FILE_SECCTX, RCL_SERVER) != 0) {
1920 req_capsule_client_get(pill, &RMF_FILE_SECCTX_NAME);
1921 buffer = &info->mti_buf;
1923 /* fill reply buffer with security context now */
1924 buffer->lb_len = req_capsule_get_size(pill, &RMF_FILE_SECCTX,
1926 buffer->lb_buf = req_capsule_server_get(info->mti_pill,
1928 rc = mo_xattr_get(info->mti_env, mdt_object_child(child),
1929 buffer, secctx_name);
1932 "found security context of size %d for "DFID"\n",
1933 rc, PFID(mdt_object_fid(child)));
1935 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1936 repbody->mbo_valid |= OBD_MD_SECCTX;
1937 if (rc < buffer->lb_len)
1938 req_capsule_shrink(pill, &RMF_FILE_SECCTX, rc,
1943 "security context not found for "DFID": rc = %d\n",
1944 PFID(mdt_object_fid(child)), rc);
1945 req_capsule_shrink(pill, &RMF_FILE_SECCTX, 0,
1947 /* handling -ENOENT is important because it may change
1948 * object state in DNE env dropping LOHA_EXISTS flag,
1949 * it is important to return that to the caller.
1950 * Check LU-13115 for details.
1959 /* check whether two FIDs belong to different MDTs.
1960 * \retval 1 on different MDTs.
1961 * 0 on the same MDT.
1964 int mdt_fids_different_target(struct mdt_thread_info *info,
1965 const struct lu_fid *fid1,
1966 const struct lu_fid *fid2)
1968 const struct lu_env *env = info->mti_env;
1969 struct mdt_device *mdt = info->mti_mdt;
1970 struct lu_seq_range *range = &info->mti_range;
1971 struct seq_server_site *ss;
1972 __u32 index1, index2;
1975 if (fid_seq(fid1) == fid_seq(fid2))
1978 ss = mdt->mdt_lu_dev.ld_site->ld_seq_site;
1980 range->lsr_flags = LU_SEQ_RANGE_MDT;
1981 rc = fld_server_lookup(env, ss->ss_server_fld, fid1->f_seq, range);
1985 index1 = range->lsr_index;
1987 rc = fld_server_lookup(env, ss->ss_server_fld, fid2->f_seq, range);
1991 index2 = range->lsr_index;
1993 return index1 != index2;
1997 * Check whether \a child is remote object on \a parent.
1999 * \param[in] info thread environment
2000 * \param[in] parent parent object, it's the same as child object in
2002 * \param[in] child child object
2004 * \retval 1 is remote object.
2005 * \retval 0 isn't remote object.
2006 * \retval < 1 error code
2008 int mdt_is_remote_object(struct mdt_thread_info *info,
2009 struct mdt_object *parent,
2010 struct mdt_object *child)
2012 struct lu_buf *buf = &info->mti_big_buf;
2013 struct linkea_data ldata = { NULL };
2014 struct link_ea_header *leh;
2015 struct link_ea_entry *lee;
2016 struct lu_name name;
2024 if (fid_is_root(mdt_object_fid(child)))
2027 if (likely(parent != child)) {
2028 if (mdt_object_remote(parent) ^ mdt_object_remote(child))
2031 if (!mdt_object_remote(parent) && !mdt_object_remote(child))
2034 rc = mdt_fids_different_target(info, mdt_object_fid(parent),
2035 mdt_object_fid(child));
2039 /* client < 2.13.52 getattr_by_fid parent and child are the same */
2040 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
2045 rc = mdt_links_read(info, child, &ldata);
2046 /* can't read linkea, just assume it's remote object */
2047 if (rc == -ENOENT || rc == -ENODATA)
2053 lee = (struct link_ea_entry *)(leh + 1);
2054 for (i = 0; i < leh->leh_reccount; i++) {
2055 linkea_entry_unpack(lee, &reclen, &name, &pfid);
2056 lee = (struct link_ea_entry *) ((char *)lee + reclen);
2057 rc = mdt_fids_different_target(info, &pfid,
2058 mdt_object_fid(child));
2066 int mdt_pack_encctx_in_reply(struct mdt_thread_info *info,
2067 struct mdt_object *child)
2069 struct lu_buf *buffer;
2070 struct mdt_body *repbody;
2071 struct req_capsule *pill = info->mti_pill;
2072 struct obd_export *exp = mdt_info_req(info)->rq_export;
2075 if (!exp_connect_encrypt(exp))
2078 if (req_capsule_has_field(pill, &RMF_FILE_ENCCTX, RCL_SERVER) &&
2079 req_capsule_get_size(pill, &RMF_FILE_ENCCTX, RCL_SERVER) != 0) {
2080 struct lu_attr la = { 0 };
2081 struct dt_object *dt = mdt_obj2dt(child);
2083 if (dt && dt->do_ops && dt->do_ops->do_attr_get)
2084 dt_attr_get(info->mti_env, mdt_obj2dt(child), &la);
2086 if (la.la_valid & LA_FLAGS && la.la_flags & LUSTRE_ENCRYPT_FL) {
2087 buffer = &info->mti_buf;
2089 /* fill reply buffer with encryption context now */
2091 req_capsule_get_size(pill, &RMF_FILE_ENCCTX,
2094 req_capsule_server_get(pill, &RMF_FILE_ENCCTX);
2095 rc = mo_xattr_get(info->mti_env,
2096 mdt_object_child(child),
2098 LL_XATTR_NAME_ENCRYPTION_CONTEXT);
2099 if (unlikely(rc == -ENODATA))
2100 /* For compatibility with 2.14 */
2101 rc = mo_xattr_get(info->mti_env,
2102 mdt_object_child(child),
2104 LL_XATTR_NAME_ENCRYPTION_CONTEXT_OLD);
2107 "found encryption ctx of size %d for "DFID"\n",
2108 rc, PFID(mdt_object_fid(child)));
2110 repbody = req_capsule_server_get(pill,
2112 repbody->mbo_valid |= OBD_MD_ENCCTX;
2113 if (rc < buffer->lb_len)
2114 req_capsule_shrink(pill,
2115 &RMF_FILE_ENCCTX, rc,
2120 "encryption ctx not found for "DFID": rc = %d\n",
2121 PFID(mdt_object_fid(child)), rc);
2122 req_capsule_shrink(pill, &RMF_FILE_ENCCTX, 0,
2124 /* handling -ENOENT is important because it may
2125 * change object state in DNE env dropping
2126 * LOHA_EXISTS flag, it is important to return
2127 * that to the caller.
2128 * Check LU-13115 for details.
2134 req_capsule_shrink(pill, &RMF_FILE_ENCCTX, 0,