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_lib.c
34 * Lustre Metadata Target (mdt) request unpacking helper.
36 * Author: Peter Braam <braam@clusterfs.com>
37 * Author: Andreas Dilger <adilger@clusterfs.com>
38 * Author: Phil Schwan <phil@clusterfs.com>
39 * Author: Mike Shaver <shaver@clusterfs.com>
40 * Author: Nikita Danilov <nikita@clusterfs.com>
41 * Author: Huang Hua <huanghua@clusterfs.com>
42 * Author: Fan Yong <fanyong@clusterfs.com>
45 #define DEBUG_SUBSYSTEM S_MDS
47 #include <linux/user_namespace.h>
48 #ifdef HAVE_UIDGID_HEADER
49 # include <linux/uidgid.h>
51 #include "mdt_internal.h"
52 #include <lnet/nidstr.h>
53 #include <lustre_nodemap.h>
55 typedef enum ucred_init_type {
61 static __u64 get_mrc_cr_flags(struct mdt_rec_create *mrc)
63 return (__u64)(mrc->cr_flags_l) | ((__u64)mrc->cr_flags_h << 32);
66 void mdt_exit_ucred(struct mdt_thread_info *info)
68 struct lu_ucred *uc = mdt_ucred(info);
69 struct mdt_device *mdt = info->mti_mdt;
72 if (uc->uc_valid != UCRED_INIT) {
73 uc->uc_suppgids[0] = uc->uc_suppgids[1] = -1;
75 put_group_info(uc->uc_ginfo);
78 if (uc->uc_identity) {
79 mdt_identity_put(mdt->mdt_identity_cache,
81 uc->uc_identity = NULL;
83 uc->uc_valid = UCRED_INIT;
87 static int match_nosquash_list(struct rw_semaphore *sem,
88 struct list_head *nidlist,
94 rc = cfs_match_nid(peernid, nidlist);
99 /* root_squash for inter-MDS operations */
100 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid)
102 struct lu_ucred *ucred = mdt_ucred(info);
103 struct root_squash_info *squash = &info->mti_mdt->mdt_squash;
106 LASSERT(ucred != NULL);
107 if (!squash->rsi_uid || ucred->uc_fsuid)
110 if (match_nosquash_list(&squash->rsi_sem,
111 &squash->rsi_nosquash_nids,
113 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
114 libcfs_nid2str(peernid));
118 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
119 libcfs_nid2str(peernid),
120 ucred->uc_fsuid, ucred->uc_fsgid, ucred->uc_cap,
121 squash->rsi_uid, squash->rsi_gid, 0);
123 ucred->uc_fsuid = squash->rsi_uid;
124 ucred->uc_fsgid = squash->rsi_gid;
126 ucred->uc_suppgids[0] = -1;
127 ucred->uc_suppgids[1] = -1;
132 static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc)
134 struct ptlrpc_request *req = mdt_info_req(info);
135 const char *jobid = mdt_req_get_jobid(req);
137 /* set jobid if specified. */
139 strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid));
141 uc->uc_jobid[0] = '\0';
144 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
145 void *buf, bool drop_fs_cap)
147 struct ptlrpc_request *req = mdt_info_req(info);
148 struct mdt_device *mdt = info->mti_mdt;
149 struct ptlrpc_user_desc *pud = req->rq_user_desc;
150 struct lu_ucred *ucred = mdt_ucred(info);
151 lnet_nid_t peernid = req->rq_peer.nid;
159 LASSERT(req->rq_auth_gss);
160 LASSERT(!req->rq_auth_usr_mdt);
161 LASSERT(req->rq_user_desc);
162 LASSERT(ucred != NULL);
164 ucred->uc_valid = UCRED_INVALID;
166 ucred->uc_o_uid = pud->pud_uid;
167 ucred->uc_o_gid = pud->pud_gid;
168 ucred->uc_o_fsuid = pud->pud_fsuid;
169 ucred->uc_o_fsgid = pud->pud_fsgid;
171 if (type == BODY_INIT) {
172 struct mdt_body *body = (struct mdt_body *)buf;
174 ucred->uc_suppgids[0] = body->mbo_suppgid;
175 ucred->uc_suppgids[1] = -1;
178 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
179 req->rq_auth_uid != pud->pud_uid) {
180 CDEBUG(D_SEC, "local client %s: auth uid %u "
181 "while client claims %u:%u/%u:%u\n",
182 libcfs_nid2str(peernid), req->rq_auth_uid,
183 pud->pud_uid, pud->pud_gid,
184 pud->pud_fsuid, pud->pud_fsgid);
188 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
189 ucred->uc_identity = NULL;
190 perm = CFS_SETUID_PERM | CFS_SETGID_PERM | CFS_SETGRP_PERM;
192 struct md_identity *identity;
194 identity = mdt_identity_get(mdt->mdt_identity_cache,
196 if (IS_ERR(identity)) {
197 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
198 ucred->uc_identity = NULL;
199 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
203 "Deny access without identity: uid %u\n",
208 ucred->uc_identity = identity;
209 perm = mdt_identity_get_perm(ucred->uc_identity,
214 /* find out the setuid/setgid attempt */
215 setuid = (pud->pud_uid != pud->pud_fsuid);
216 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
217 (ucred->uc_identity &&
218 (pud->pud_gid != ucred->uc_identity->mi_gid)));
220 /* check permission of setuid */
221 if (setuid && !(perm & CFS_SETUID_PERM)) {
222 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
223 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
224 GOTO(out, rc = -EACCES);
227 /* check permission of setgid */
228 if (setgid && !(perm & CFS_SETGID_PERM)) {
229 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
230 "from %s\n", pud->pud_uid, pud->pud_gid,
231 pud->pud_fsuid, pud->pud_fsgid,
232 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
233 GOTO(out, rc = -EACCES);
236 if (perm & CFS_SETGRP_PERM) {
237 if (pud->pud_ngroups) {
238 /* setgroups for local client */
239 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
240 if (!ucred->uc_ginfo) {
241 CERROR("failed to alloc %d groups\n",
243 GOTO(out, rc = -ENOMEM);
246 lustre_groups_from_list(ucred->uc_ginfo,
248 lustre_groups_sort(ucred->uc_ginfo);
250 ucred->uc_ginfo = NULL;
253 ucred->uc_suppgids[0] = -1;
254 ucred->uc_suppgids[1] = -1;
255 ucred->uc_ginfo = NULL;
258 ucred->uc_uid = pud->pud_uid;
259 ucred->uc_gid = pud->pud_gid;
260 ucred->uc_fsuid = pud->pud_fsuid;
261 ucred->uc_fsgid = pud->pud_fsgid;
263 /* process root_squash here. */
264 mdt_root_squash(info, peernid);
266 /* remove fs privilege for non-root user. */
267 if (ucred->uc_fsuid && drop_fs_cap)
268 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
270 ucred->uc_cap = pud->pud_cap;
271 ucred->uc_valid = UCRED_NEW;
272 ucred_set_jobid(info, ucred);
278 if (ucred->uc_ginfo) {
279 put_group_info(ucred->uc_ginfo);
280 ucred->uc_ginfo = NULL;
282 if (ucred->uc_identity) {
283 mdt_identity_put(mdt->mdt_identity_cache,
285 ucred->uc_identity = NULL;
293 * Check whether allow the client to set supplementary group IDs or not.
295 * \param[in] info pointer to the thread context
296 * \param[in] uc pointer to the RPC user descriptor
298 * \retval true if allow to set supplementary group IDs
299 * \retval false for other cases
301 bool allow_client_chgrp(struct mdt_thread_info *info, struct lu_ucred *uc)
305 /* 1. If identity_upcall is disabled,
306 * permit local client to do anything. */
307 if (is_identity_get_disabled(info->mti_mdt->mdt_identity_cache))
310 /* 2. If fail to get related identities, then forbid any client to
311 * set supplementary group IDs. */
312 if (uc->uc_identity == NULL)
315 /* 3. Check the permission in the identities. */
316 perm = mdt_identity_get_perm(uc->uc_identity,
317 mdt_info_req(info)->rq_peer.nid);
318 if (perm & CFS_SETGRP_PERM)
324 int mdt_check_ucred(struct mdt_thread_info *info)
326 struct ptlrpc_request *req = mdt_info_req(info);
327 struct mdt_device *mdt = info->mti_mdt;
328 struct ptlrpc_user_desc *pud = req->rq_user_desc;
329 struct lu_ucred *ucred = mdt_ucred(info);
330 struct md_identity *identity = NULL;
331 lnet_nid_t peernid = req->rq_peer.nid;
339 LASSERT(ucred != NULL);
340 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
343 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
346 /* sanity check: if we use strong authentication, we expect the
347 * uid which client claimed is true */
348 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
349 req->rq_auth_uid != pud->pud_uid) {
350 CDEBUG(D_SEC, "local client %s: auth uid %u "
351 "while client claims %u:%u/%u:%u\n",
352 libcfs_nid2str(peernid), req->rq_auth_uid,
353 pud->pud_uid, pud->pud_gid,
354 pud->pud_fsuid, pud->pud_fsgid);
358 if (is_identity_get_disabled(mdt->mdt_identity_cache))
361 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
362 if (IS_ERR(identity)) {
363 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
366 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
372 perm = mdt_identity_get_perm(identity, peernid);
373 /* find out the setuid/setgid attempt */
374 setuid = (pud->pud_uid != pud->pud_fsuid);
375 setgid = (pud->pud_gid != pud->pud_fsgid ||
376 pud->pud_gid != identity->mi_gid);
378 /* check permission of setuid */
379 if (setuid && !(perm & CFS_SETUID_PERM)) {
380 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
381 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
382 GOTO(out, rc = -EACCES);
385 /* check permission of setgid */
386 if (setgid && !(perm & CFS_SETGID_PERM)) {
387 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
388 "from %s\n", pud->pud_uid, pud->pud_gid,
389 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
390 libcfs_nid2str(peernid));
391 GOTO(out, rc = -EACCES);
397 mdt_identity_put(mdt->mdt_identity_cache, identity);
401 static int old_init_ucred_common(struct mdt_thread_info *info,
402 struct lu_nodemap *nodemap,
405 struct lu_ucred *uc = mdt_ucred(info);
406 struct mdt_device *mdt = info->mti_mdt;
407 struct md_identity *identity = NULL;
409 if (nodemap && uc->uc_o_uid == nodemap->nm_squash_uid) {
410 /* deny access before we get identity ref */
411 if (nodemap->nmf_deny_unknown)
414 uc->uc_fsuid = nodemap->nm_squash_uid;
415 uc->uc_fsgid = nodemap->nm_squash_gid;
417 uc->uc_suppgids[0] = -1;
418 uc->uc_suppgids[1] = -1;
421 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
422 identity = mdt_identity_get(mdt->mdt_identity_cache,
424 if (IS_ERR(identity)) {
425 if (unlikely(PTR_ERR(identity) == -EREMCHG ||
426 uc->uc_cap & CFS_CAP_FS_MASK)) {
429 CDEBUG(D_SEC, "Deny access without identity: "
430 "uid %u\n", uc->uc_fsuid);
435 uc->uc_identity = identity;
437 /* process root_squash here. */
438 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
440 /* remove fs privilege for non-root user. */
441 if (uc->uc_fsuid && drop_fs_cap)
442 uc->uc_cap &= ~CFS_CAP_FS_MASK;
443 uc->uc_valid = UCRED_OLD;
444 ucred_set_jobid(info, uc);
451 static int old_init_ucred(struct mdt_thread_info *info,
452 struct mdt_body *body, bool drop_fs_cap)
454 struct lu_ucred *uc = mdt_ucred(info);
455 struct lu_nodemap *nodemap;
459 nodemap = nodemap_get_from_exp(info->mti_exp);
461 RETURN(PTR_ERR(nodemap));
463 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
464 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
465 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
466 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
467 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
468 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
469 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
470 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
473 uc->uc_valid = UCRED_INVALID;
474 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
475 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
476 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
477 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
478 uc->uc_suppgids[0] = body->mbo_suppgid;
479 uc->uc_suppgids[1] = -1;
481 uc->uc_cap = body->mbo_capability;
483 rc = old_init_ucred_common(info, nodemap, drop_fs_cap);
484 nodemap_putref(nodemap);
489 static int old_init_ucred_reint(struct mdt_thread_info *info)
491 struct lu_ucred *uc = mdt_ucred(info);
492 struct lu_nodemap *nodemap;
496 nodemap = nodemap_get_from_exp(info->mti_exp);
498 RETURN(PTR_ERR(nodemap));
502 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
503 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
504 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
505 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
507 uc->uc_valid = UCRED_INVALID;
508 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
509 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
512 rc = old_init_ucred_common(info, nodemap, true); /* drop_fs_cap=true */
513 nodemap_putref(nodemap);
518 static inline int __mdt_init_ucred(struct mdt_thread_info *info,
519 struct mdt_body *body,
522 struct ptlrpc_request *req = mdt_info_req(info);
523 struct lu_ucred *uc = mdt_ucred(info);
526 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
529 mdt_exit_ucred(info);
531 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
532 return old_init_ucred(info, body, drop_fs_cap);
534 return new_init_ucred(info, BODY_INIT, body, drop_fs_cap);
537 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
539 return __mdt_init_ucred(info, body, true);
542 /* LU-6528 when "no_subtree_check" is set for NFS export, nfsd_set_fh_dentry()
543 * doesn't set correct fsuid explicitely, but raise capability to allow
544 * exportfs_decode_fh() to reconnect disconnected dentry into dcache. So for
545 * lookup (i.e. intent_getattr), we should keep FS capability, otherwise it
546 * will fail permission check. */
547 int mdt_init_ucred_intent_getattr(struct mdt_thread_info *info,
548 struct mdt_body *body)
550 return __mdt_init_ucred(info, body, false);
553 int mdt_init_ucred_reint(struct mdt_thread_info *info)
555 struct ptlrpc_request *req = mdt_info_req(info);
556 struct lu_ucred *uc = mdt_ucred(info);
557 struct md_attr *ma = &info->mti_attr;
560 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
563 /* LU-5564: for normal close request, skip permission check */
564 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE &&
565 !(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
566 uc->uc_cap |= CFS_CAP_FS_MASK;
568 mdt_exit_ucred(info);
570 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
571 return old_init_ucred_reint(info);
573 return new_init_ucred(info, REC_INIT, NULL, true);
576 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
577 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
579 const struct lov_ost_data_v1 *lod;
583 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
586 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
588 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
589 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
590 le32_to_cpu(lmm->lmm_pattern));
591 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
592 le32_to_cpu(lmm->lmm_stripe_size), count);
594 /* If it's a directory or a released file, then there are
595 * no actual objects to print, so bail out. */
596 if (valid & OBD_MD_FLDIREA ||
597 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
600 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
601 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
604 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
605 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
606 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
610 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
612 const struct lmv_mds_md_v1 *lmm1;
615 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
618 lmm1 = &lmv->lmv_md_v1;
620 "magic 0x%08X, master %#X stripe_count %#x hash_type %#x\n",
621 le32_to_cpu(lmm1->lmv_magic),
622 le32_to_cpu(lmm1->lmv_master_mdt_index),
623 le32_to_cpu(lmm1->lmv_stripe_count),
624 le32_to_cpu(lmm1->lmv_hash_type));
626 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
629 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
632 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
633 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
637 /* Shrink and/or grow reply buffers */
638 int mdt_fix_reply(struct mdt_thread_info *info)
640 struct req_capsule *pill = info->mti_pill;
641 struct mdt_body *body;
642 int md_size, md_packed = 0;
647 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
648 LASSERT(body != NULL);
650 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
652 md_size = body->mbo_eadatasize;
656 acl_size = body->mbo_aclsize;
658 /* this replay - not send info to client */
659 if (info->mti_spec.no_create) {
664 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
669 &RMF_ACL, or &RMF_LOGCOOKIES
670 (optional) &RMF_CAPA1,
671 (optional) &RMF_CAPA2,
672 (optional) something else
675 /* MDT_MD buffer may be bigger than packed value, let's shrink all
676 * buffers before growing it */
677 if (info->mti_big_lmm_used) {
678 /* big_lmm buffer may be used even without packing the result
679 * into reply, just for internal server needs */
680 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
681 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
684 /* free big lmm if md_size is not needed */
685 if (md_size == 0 || md_packed == 0) {
686 info->mti_big_lmm_used = 0;
688 /* buffer must be allocated separately */
689 LASSERT(info->mti_attr.ma_lmm !=
690 req_capsule_server_get(pill, &RMF_MDT_MD));
691 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
693 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
694 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
697 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
698 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
699 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
700 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
701 acl_size, RCL_SERVER);
703 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
704 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
705 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
707 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
708 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
709 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
712 * Some more field should be shrinked if needed.
713 * This should be done by those who added fields to reply message.
716 /* Grow MD buffer if needed finally */
717 if (info->mti_big_lmm_used) {
720 LASSERT(md_size > md_packed);
721 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
722 md_size - md_packed);
723 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
725 /* we can't answer with proper LOV EA, drop flags,
726 * the rc is also returned so this request is
727 * considered as failed */
728 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
729 /* don't return transno along with error */
730 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
732 /* now we need to pack right LOV/LMV EA */
733 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
734 if (info->mti_attr.ma_valid & MA_LOV) {
735 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
737 info->mti_attr.ma_lmm_size);
738 memcpy(lmm, info->mti_attr.ma_lmm,
739 info->mti_attr.ma_lmm_size);
740 } else if (info->mti_attr.ma_valid & MA_LMV) {
741 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
743 info->mti_attr.ma_lmv_size);
744 memcpy(lmm, info->mti_attr.ma_lmv,
745 info->mti_attr.ma_lmv_size);
748 /* update mdt_max_mdsize so clients will be aware about that */
749 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
750 info->mti_mdt->mdt_max_mdsize =
751 info->mti_attr.ma_lmm_size;
752 info->mti_big_lmm_used = 0;
758 /* if object is dying, pack the lov/llog data,
759 * parameter info->mti_attr should be valid at this point! */
760 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
761 const struct md_attr *ma)
763 struct mdt_body *repbody;
764 const struct lu_attr *la = &ma->ma_attr;
767 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
768 LASSERT(repbody != NULL);
770 if (ma->ma_valid & MA_INODE)
771 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
773 if (ma->ma_valid & MA_LOV) {
774 CERROR("No need in LOV EA upon unlink\n");
777 repbody->mbo_eadatasize = 0;
782 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
788 if (in & MDS_ATTR_MODE)
790 if (in & MDS_ATTR_UID)
792 if (in & MDS_ATTR_GID)
794 if (in & MDS_ATTR_SIZE)
796 if (in & MDS_ATTR_BLOCKS)
798 if (in & MDS_ATTR_ATIME_SET)
800 if (in & MDS_ATTR_CTIME_SET)
802 if (in & MDS_ATTR_MTIME_SET)
804 if (in & MDS_ATTR_ATTR_FLAG)
806 if (in & MDS_ATTR_KILL_SUID)
808 if (in & MDS_ATTR_KILL_SGID)
811 if (in & MDS_ATTR_FROM_OPEN)
812 rr->rr_flags |= MRF_OPEN_TRUNC;
813 if (in & MDS_OPEN_OWNEROVERRIDE)
814 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
815 if (in & MDS_ATTR_FORCE)
816 ma->ma_attr_flags |= MDS_PERM_BYPASS;
818 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID |
819 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
820 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
821 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
822 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
823 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
825 CERROR("Unknown attr bits: %#llx\n", in);
831 int mdt_name_unpack(struct req_capsule *pill,
832 const struct req_msg_field *field,
834 enum mdt_name_flags flags)
836 ln->ln_name = req_capsule_client_get(pill, field);
837 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
839 if (!lu_name_is_valid(ln)) {
846 if ((flags & MNF_FIX_ANON) &&
847 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
848 /* Newer (3.x) kernels use a name of "/" for the
849 * "anonymous" disconnected dentries from NFS
850 * filehandle conversion. See d_obtain_alias(). */
858 static int mdt_file_secctx_unpack(struct req_capsule *pill,
859 const char **secctx_name,
860 void **secctx, size_t *secctx_size)
869 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT) ||
870 !req_capsule_field_present(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT))
873 name_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX_NAME,
878 name = req_capsule_client_get(pill, &RMF_FILE_SECCTX_NAME);
879 if (strnlen(name, name_size) != name_size - 1)
882 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX, RCL_CLIENT) ||
883 !req_capsule_field_present(pill, &RMF_FILE_SECCTX, RCL_CLIENT))
887 *secctx = req_capsule_client_get(pill, &RMF_FILE_SECCTX);
888 *secctx_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX, RCL_CLIENT);
893 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
895 struct lu_ucred *uc = mdt_ucred(info);
896 struct md_attr *ma = &info->mti_attr;
897 struct lu_attr *la = &ma->ma_attr;
898 struct req_capsule *pill = info->mti_pill;
899 struct mdt_reint_record *rr = &info->mti_rr;
900 struct mdt_rec_setattr *rec;
901 struct lu_nodemap *nodemap;
904 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
905 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
909 /* This prior initialization is needed for old_init_ucred_reint() */
910 uc->uc_fsuid = rec->sa_fsuid;
911 uc->uc_fsgid = rec->sa_fsgid;
912 uc->uc_cap = rec->sa_cap;
913 uc->uc_suppgids[0] = rec->sa_suppgid;
914 uc->uc_suppgids[1] = -1;
916 rr->rr_fid1 = &rec->sa_fid;
917 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
918 la->la_mode = rec->sa_mode;
919 la->la_flags = rec->sa_attr_flags;
921 nodemap = nodemap_get_from_exp(info->mti_exp);
923 RETURN(PTR_ERR(nodemap));
925 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
926 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
927 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
928 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
929 nodemap_putref(nodemap);
931 la->la_size = rec->sa_size;
932 la->la_blocks = rec->sa_blocks;
933 la->la_ctime = rec->sa_ctime;
934 la->la_atime = rec->sa_atime;
935 la->la_mtime = rec->sa_mtime;
936 ma->ma_valid = MA_INODE;
938 if (rec->sa_bias & MDS_DATA_MODIFIED)
939 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
941 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
943 if (rec->sa_bias & MDS_HSM_RELEASE)
944 ma->ma_attr_flags |= MDS_HSM_RELEASE;
946 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
948 if (rec->sa_bias & MDS_CLOSE_LAYOUT_SWAP)
949 ma->ma_attr_flags |= MDS_CLOSE_LAYOUT_SWAP;
951 ma->ma_attr_flags &= ~MDS_CLOSE_LAYOUT_SWAP;
956 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
958 struct req_capsule *pill = info->mti_pill;
959 struct mdt_ioepoch *ioepoch;
962 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
963 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
970 info->mti_close_handle = ioepoch->mio_handle;
975 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
976 struct req_capsule *pill = info->mti_pill;
978 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
979 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
980 if (info->mti_dlm_req == NULL)
987 static int mdt_setattr_unpack(struct mdt_thread_info *info)
989 struct mdt_reint_record *rr = &info->mti_rr;
990 struct md_attr *ma = &info->mti_attr;
991 struct req_capsule *pill = info->mti_pill;
995 rc = mdt_setattr_unpack_rec(info);
999 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1000 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1001 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1003 if (rr->rr_eadatalen > 0) {
1004 const struct lmv_user_md *lum;
1006 lum = rr->rr_eadata;
1007 /* Sigh ma_valid(from req) does not indicate whether
1008 * it will set LOV/LMV EA, so we have to check magic */
1009 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1010 ma->ma_valid |= MA_LMV;
1011 ma->ma_lmv = (void *)rr->rr_eadata;
1012 ma->ma_lmv_size = rr->rr_eadatalen;
1014 ma->ma_valid |= MA_LOV;
1015 ma->ma_lmm = (void *)rr->rr_eadata;
1016 ma->ma_lmm_size = rr->rr_eadatalen;
1021 rc = mdt_dlmreq_unpack(info);
1025 static int mdt_intent_close_unpack(struct mdt_thread_info *info)
1027 struct md_attr *ma = &info->mti_attr;
1028 struct req_capsule *pill = info->mti_pill;
1031 if (!(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
1034 req_capsule_extend(pill, &RQF_MDS_INTENT_CLOSE);
1036 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1037 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1043 int mdt_close_unpack(struct mdt_thread_info *info)
1048 rc = mdt_close_handle_unpack(info);
1052 rc = mdt_setattr_unpack_rec(info);
1056 rc = mdt_intent_close_unpack(info);
1060 RETURN(mdt_init_ucred_reint(info));
1063 static int mdt_create_unpack(struct mdt_thread_info *info)
1065 struct lu_ucred *uc = mdt_ucred(info);
1066 struct mdt_rec_create *rec;
1067 struct lu_attr *attr = &info->mti_attr.ma_attr;
1068 struct mdt_reint_record *rr = &info->mti_rr;
1069 struct req_capsule *pill = info->mti_pill;
1070 struct md_op_spec *sp = &info->mti_spec;
1074 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1075 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1079 /* This prior initialization is needed for old_init_ucred_reint() */
1080 uc->uc_fsuid = rec->cr_fsuid;
1081 uc->uc_fsgid = rec->cr_fsgid;
1082 uc->uc_cap = rec->cr_cap;
1083 uc->uc_suppgids[0] = rec->cr_suppgid1;
1084 uc->uc_suppgids[1] = -1;
1085 uc->uc_umask = rec->cr_umask;
1087 rr->rr_fid1 = &rec->cr_fid1;
1088 rr->rr_fid2 = &rec->cr_fid2;
1089 attr->la_mode = rec->cr_mode;
1090 attr->la_rdev = rec->cr_rdev;
1091 attr->la_uid = rec->cr_fsuid;
1092 attr->la_gid = rec->cr_fsgid;
1093 attr->la_ctime = rec->cr_time;
1094 attr->la_mtime = rec->cr_time;
1095 attr->la_atime = rec->cr_time;
1096 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1097 LA_CTIME | LA_MTIME | LA_ATIME;
1098 memset(&sp->u, 0, sizeof(sp->u));
1099 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1101 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1105 if (S_ISLNK(attr->la_mode)) {
1106 const char *tgt = NULL;
1108 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1109 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1110 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1111 sp->u.sp_symname = tgt;
1116 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_ACL);
1117 if (S_ISDIR(attr->la_mode) &&
1118 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1119 sp->u.sp_ea.eadata =
1120 req_capsule_client_get(pill, &RMF_EADATA);
1121 sp->u.sp_ea.eadatalen =
1122 req_capsule_get_size(pill, &RMF_EADATA,
1124 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1128 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1129 &sp->sp_cr_file_secctx,
1130 &sp->sp_cr_file_secctx_size);
1134 rc = mdt_dlmreq_unpack(info);
1138 static int mdt_link_unpack(struct mdt_thread_info *info)
1140 struct lu_ucred *uc = mdt_ucred(info);
1141 struct mdt_rec_link *rec;
1142 struct lu_attr *attr = &info->mti_attr.ma_attr;
1143 struct mdt_reint_record *rr = &info->mti_rr;
1144 struct req_capsule *pill = info->mti_pill;
1148 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1149 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1153 /* This prior initialization is needed for old_init_ucred_reint() */
1154 uc->uc_fsuid = rec->lk_fsuid;
1155 uc->uc_fsgid = rec->lk_fsgid;
1156 uc->uc_cap = rec->lk_cap;
1157 uc->uc_suppgids[0] = rec->lk_suppgid1;
1158 uc->uc_suppgids[1] = rec->lk_suppgid2;
1160 attr->la_uid = rec->lk_fsuid;
1161 attr->la_gid = rec->lk_fsgid;
1162 rr->rr_fid1 = &rec->lk_fid1;
1163 rr->rr_fid2 = &rec->lk_fid2;
1164 attr->la_ctime = rec->lk_time;
1165 attr->la_mtime = rec->lk_time;
1166 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1168 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1172 rc = mdt_dlmreq_unpack(info);
1177 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1179 struct lu_ucred *uc = mdt_ucred(info);
1180 struct mdt_rec_unlink *rec;
1181 struct md_attr *ma = &info->mti_attr;
1182 struct lu_attr *attr = &info->mti_attr.ma_attr;
1183 struct mdt_reint_record *rr = &info->mti_rr;
1184 struct req_capsule *pill = info->mti_pill;
1188 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1189 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1193 /* This prior initialization is needed for old_init_ucred_reint() */
1194 uc->uc_fsuid = rec->ul_fsuid;
1195 uc->uc_fsgid = rec->ul_fsgid;
1196 uc->uc_cap = rec->ul_cap;
1197 uc->uc_suppgids[0] = rec->ul_suppgid1;
1198 uc->uc_suppgids[1] = -1;
1200 attr->la_uid = rec->ul_fsuid;
1201 attr->la_gid = rec->ul_fsgid;
1202 rr->rr_fid1 = &rec->ul_fid1;
1203 rr->rr_fid2 = &rec->ul_fid2;
1204 attr->la_ctime = rec->ul_time;
1205 attr->la_mtime = rec->ul_time;
1206 attr->la_mode = rec->ul_mode;
1207 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1209 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1213 if (rec->ul_bias & MDS_VTX_BYPASS)
1214 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1216 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1218 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1220 rc = mdt_dlmreq_unpack(info);
1224 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1226 info->mti_spec.sp_rm_entry = 1;
1227 return mdt_unlink_unpack(info);
1230 static int mdt_rename_unpack(struct mdt_thread_info *info)
1232 struct lu_ucred *uc = mdt_ucred(info);
1233 struct mdt_rec_rename *rec;
1234 struct md_attr *ma = &info->mti_attr;
1235 struct lu_attr *attr = &info->mti_attr.ma_attr;
1236 struct mdt_reint_record *rr = &info->mti_rr;
1237 struct req_capsule *pill = info->mti_pill;
1241 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1242 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1246 /* This prior initialization is needed for old_init_ucred_reint() */
1247 uc->uc_fsuid = rec->rn_fsuid;
1248 uc->uc_fsgid = rec->rn_fsgid;
1249 uc->uc_cap = rec->rn_cap;
1250 uc->uc_suppgids[0] = rec->rn_suppgid1;
1251 uc->uc_suppgids[1] = rec->rn_suppgid2;
1253 attr->la_uid = rec->rn_fsuid;
1254 attr->la_gid = rec->rn_fsgid;
1255 rr->rr_fid1 = &rec->rn_fid1;
1256 rr->rr_fid2 = &rec->rn_fid2;
1257 attr->la_ctime = rec->rn_time;
1258 attr->la_mtime = rec->rn_time;
1259 /* rename_tgt contains the mode already */
1260 attr->la_mode = rec->rn_mode;
1261 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1263 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1267 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1271 if (rec->rn_bias & MDS_VTX_BYPASS)
1272 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1274 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1276 if (rec->rn_bias & MDS_RENAME_MIGRATE) {
1277 req_capsule_extend(info->mti_pill, &RQF_MDS_REINT_MIGRATE);
1278 rc = mdt_close_handle_unpack(info);
1281 info->mti_spec.sp_migrate_close = 1;
1284 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1287 rc = mdt_dlmreq_unpack(info);
1293 * please see comment above LOV_MAGIC_V1_DEF
1295 static void mdt_fix_lov_magic(struct mdt_thread_info *info)
1297 struct mdt_reint_record *rr = &info->mti_rr;
1298 struct lov_user_md_v1 *v1;
1300 v1 = (void *)rr->rr_eadata;
1303 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1304 if (v1->lmm_magic == LOV_USER_MAGIC_V1) {
1305 v1->lmm_magic = LOV_MAGIC_V1_DEF;
1306 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
1307 v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF);
1308 } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
1309 v1->lmm_magic = LOV_MAGIC_V3_DEF;
1310 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
1311 v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF);
1316 static int mdt_open_unpack(struct mdt_thread_info *info)
1318 struct lu_ucred *uc = mdt_ucred(info);
1319 struct mdt_rec_create *rec;
1320 struct lu_attr *attr = &info->mti_attr.ma_attr;
1321 struct req_capsule *pill = info->mti_pill;
1322 struct mdt_reint_record *rr = &info->mti_rr;
1323 struct ptlrpc_request *req = mdt_info_req(info);
1324 struct md_op_spec *sp = &info->mti_spec;
1328 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1329 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1333 /* This prior initialization is needed for old_init_ucred_reint() */
1334 uc->uc_fsuid = rec->cr_fsuid;
1335 uc->uc_fsgid = rec->cr_fsgid;
1336 uc->uc_cap = rec->cr_cap;
1337 uc->uc_suppgids[0] = rec->cr_suppgid1;
1338 uc->uc_suppgids[1] = rec->cr_suppgid2;
1339 uc->uc_umask = rec->cr_umask;
1341 rr->rr_fid1 = &rec->cr_fid1;
1342 rr->rr_fid2 = &rec->cr_fid2;
1343 rr->rr_handle = &rec->cr_old_handle;
1344 attr->la_mode = rec->cr_mode;
1345 attr->la_rdev = rec->cr_rdev;
1346 attr->la_uid = rec->cr_fsuid;
1347 attr->la_gid = rec->cr_fsgid;
1348 attr->la_ctime = rec->cr_time;
1349 attr->la_mtime = rec->cr_time;
1350 attr->la_atime = rec->cr_time;
1351 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1352 LA_CTIME | LA_MTIME | LA_ATIME;
1353 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1354 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1355 /* Do not trigger ASSERTION if client miss to set such flags. */
1356 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1359 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1361 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1363 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1364 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1366 if (rr->rr_eadatalen > 0) {
1367 rr->rr_eadata = req_capsule_client_get(pill,
1369 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1370 sp->u.sp_ea.eadata = rr->rr_eadata;
1371 sp->no_create = !!req_is_replay(req);
1372 mdt_fix_lov_magic(info);
1376 * Client default md_size may be 0 right after client start,
1377 * until all osc are connected, set here just some reasonable
1378 * value to prevent misbehavior.
1380 if (rr->rr_eadatalen == 0 &&
1381 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1382 rr->rr_eadatalen = MIN_MD_SIZE;
1385 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1386 &sp->sp_cr_file_secctx,
1387 &sp->sp_cr_file_secctx_size);
1392 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1394 struct mdt_reint_record *rr = &info->mti_rr;
1395 struct lu_ucred *uc = mdt_ucred(info);
1396 struct lu_attr *attr = &info->mti_attr.ma_attr;
1397 struct req_capsule *pill = info->mti_pill;
1398 struct mdt_rec_setxattr *rec;
1403 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1404 sizeof(struct mdt_rec_reint));
1406 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1410 /* This prior initialization is needed for old_init_ucred_reint() */
1411 uc->uc_fsuid = rec->sx_fsuid;
1412 uc->uc_fsgid = rec->sx_fsgid;
1413 uc->uc_cap = rec->sx_cap;
1414 uc->uc_suppgids[0] = rec->sx_suppgid1;
1415 uc->uc_suppgids[1] = -1;
1417 rr->rr_opcode = rec->sx_opcode;
1418 rr->rr_fid1 = &rec->sx_fid;
1419 attr->la_valid = rec->sx_valid;
1420 attr->la_ctime = rec->sx_time;
1421 attr->la_size = rec->sx_size;
1422 attr->la_flags = rec->sx_flags;
1424 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1428 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1429 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1431 if (rr->rr_eadatalen > 0) {
1432 rr->rr_eadata = req_capsule_client_get(pill,
1434 if (rr->rr_eadata == NULL)
1437 rr->rr_eadata = NULL;
1439 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1440 CDEBUG(D_INFO, "no xattr data supplied\n");
1444 if (mdt_dlmreq_unpack(info) < 0)
1451 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1453 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1454 [REINT_SETATTR] = mdt_setattr_unpack,
1455 [REINT_CREATE] = mdt_create_unpack,
1456 [REINT_LINK] = mdt_link_unpack,
1457 [REINT_UNLINK] = mdt_unlink_unpack,
1458 [REINT_RENAME] = mdt_rename_unpack,
1459 [REINT_OPEN] = mdt_open_unpack,
1460 [REINT_SETXATTR] = mdt_setxattr_unpack,
1461 [REINT_RMENTRY] = mdt_rmentry_unpack,
1462 [REINT_MIGRATE] = mdt_rename_unpack,
1465 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1470 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1471 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1472 info->mti_rr.rr_opcode = op;
1473 rc = mdt_reint_unpackers[op](info);
1475 CERROR("Unexpected opcode %d\n", op);