4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_lib.c
38 * Lustre Metadata Target (mdt) request unpacking helper.
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Fan Yong <fanyong@clusterfs.com>
49 #define DEBUG_SUBSYSTEM S_MDS
51 #include <linux/user_namespace.h>
52 #ifdef HAVE_UIDGID_HEADER
53 # include <linux/uidgid.h>
55 #include "mdt_internal.h"
56 #include <lnet/nidstr.h>
57 #include <lustre_nodemap.h>
59 typedef enum ucred_init_type {
65 static __u64 get_mrc_cr_flags(struct mdt_rec_create *mrc)
67 return (__u64)(mrc->cr_flags_l) | ((__u64)mrc->cr_flags_h << 32);
70 void mdt_exit_ucred(struct mdt_thread_info *info)
72 struct lu_ucred *uc = mdt_ucred(info);
73 struct mdt_device *mdt = info->mti_mdt;
76 if (uc->uc_valid != UCRED_INIT) {
77 uc->uc_suppgids[0] = uc->uc_suppgids[1] = -1;
79 put_group_info(uc->uc_ginfo);
82 if (uc->uc_identity) {
83 mdt_identity_put(mdt->mdt_identity_cache,
85 uc->uc_identity = NULL;
87 uc->uc_valid = UCRED_INIT;
91 static int match_nosquash_list(struct rw_semaphore *sem,
92 struct list_head *nidlist,
98 rc = cfs_match_nid(peernid, nidlist);
103 /* root_squash for inter-MDS operations */
104 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid)
106 struct lu_ucred *ucred = mdt_ucred(info);
107 struct root_squash_info *squash = &info->mti_mdt->mdt_squash;
110 LASSERT(ucred != NULL);
111 if (!squash->rsi_uid || ucred->uc_fsuid)
114 if (match_nosquash_list(&squash->rsi_sem,
115 &squash->rsi_nosquash_nids,
117 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
118 libcfs_nid2str(peernid));
122 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
123 libcfs_nid2str(peernid),
124 ucred->uc_fsuid, ucred->uc_fsgid, ucred->uc_cap,
125 squash->rsi_uid, squash->rsi_gid, 0);
127 ucred->uc_fsuid = squash->rsi_uid;
128 ucred->uc_fsgid = squash->rsi_gid;
130 ucred->uc_suppgids[0] = -1;
131 ucred->uc_suppgids[1] = -1;
136 static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc)
138 struct ptlrpc_request *req = mdt_info_req(info);
139 const char *jobid = mdt_req_get_jobid(req);
141 /* set jobid if specified. */
143 strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid));
145 uc->uc_jobid[0] = '\0';
148 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
149 void *buf, bool drop_fs_cap)
151 struct ptlrpc_request *req = mdt_info_req(info);
152 struct mdt_device *mdt = info->mti_mdt;
153 struct ptlrpc_user_desc *pud = req->rq_user_desc;
154 struct lu_ucred *ucred = mdt_ucred(info);
155 lnet_nid_t peernid = req->rq_peer.nid;
163 LASSERT(req->rq_auth_gss);
164 LASSERT(!req->rq_auth_usr_mdt);
165 LASSERT(req->rq_user_desc);
166 LASSERT(ucred != NULL);
168 ucred->uc_valid = UCRED_INVALID;
170 ucred->uc_o_uid = pud->pud_uid;
171 ucred->uc_o_gid = pud->pud_gid;
172 ucred->uc_o_fsuid = pud->pud_fsuid;
173 ucred->uc_o_fsgid = pud->pud_fsgid;
175 if (type == BODY_INIT) {
176 struct mdt_body *body = (struct mdt_body *)buf;
178 ucred->uc_suppgids[0] = body->mbo_suppgid;
179 ucred->uc_suppgids[1] = -1;
182 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
183 req->rq_auth_uid != pud->pud_uid) {
184 CDEBUG(D_SEC, "local client %s: auth uid %u "
185 "while client claims %u:%u/%u:%u\n",
186 libcfs_nid2str(peernid), req->rq_auth_uid,
187 pud->pud_uid, pud->pud_gid,
188 pud->pud_fsuid, pud->pud_fsgid);
192 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
193 ucred->uc_identity = NULL;
194 perm = CFS_SETUID_PERM | CFS_SETGID_PERM | CFS_SETGRP_PERM;
196 struct md_identity *identity;
198 identity = mdt_identity_get(mdt->mdt_identity_cache,
200 if (IS_ERR(identity)) {
201 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
202 ucred->uc_identity = NULL;
203 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
207 "Deny access without identity: uid %u\n",
212 ucred->uc_identity = identity;
213 perm = mdt_identity_get_perm(ucred->uc_identity,
218 /* find out the setuid/setgid attempt */
219 setuid = (pud->pud_uid != pud->pud_fsuid);
220 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
221 (ucred->uc_identity &&
222 (pud->pud_gid != ucred->uc_identity->mi_gid)));
224 /* check permission of setuid */
225 if (setuid && !(perm & CFS_SETUID_PERM)) {
226 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
227 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
228 GOTO(out, rc = -EACCES);
231 /* check permission of setgid */
232 if (setgid && !(perm & CFS_SETGID_PERM)) {
233 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
234 "from %s\n", pud->pud_uid, pud->pud_gid,
235 pud->pud_fsuid, pud->pud_fsgid,
236 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
237 GOTO(out, rc = -EACCES);
240 if (perm & CFS_SETGRP_PERM) {
241 if (pud->pud_ngroups) {
242 /* setgroups for local client */
243 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
244 if (!ucred->uc_ginfo) {
245 CERROR("failed to alloc %d groups\n",
247 GOTO(out, rc = -ENOMEM);
250 lustre_groups_from_list(ucred->uc_ginfo,
252 lustre_groups_sort(ucred->uc_ginfo);
254 ucred->uc_ginfo = NULL;
257 ucred->uc_suppgids[0] = -1;
258 ucred->uc_suppgids[1] = -1;
259 ucred->uc_ginfo = NULL;
262 ucred->uc_uid = pud->pud_uid;
263 ucred->uc_gid = pud->pud_gid;
264 ucred->uc_fsuid = pud->pud_fsuid;
265 ucred->uc_fsgid = pud->pud_fsgid;
267 /* process root_squash here. */
268 mdt_root_squash(info, peernid);
270 /* remove fs privilege for non-root user. */
271 if (ucred->uc_fsuid && drop_fs_cap)
272 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
274 ucred->uc_cap = pud->pud_cap;
275 ucred->uc_valid = UCRED_NEW;
276 ucred_set_jobid(info, ucred);
282 if (ucred->uc_ginfo) {
283 put_group_info(ucred->uc_ginfo);
284 ucred->uc_ginfo = NULL;
286 if (ucred->uc_identity) {
287 mdt_identity_put(mdt->mdt_identity_cache,
289 ucred->uc_identity = NULL;
297 * Check whether allow the client to set supplementary group IDs or not.
299 * \param[in] info pointer to the thread context
300 * \param[in] uc pointer to the RPC user descriptor
302 * \retval true if allow to set supplementary group IDs
303 * \retval false for other cases
305 bool allow_client_chgrp(struct mdt_thread_info *info, struct lu_ucred *uc)
309 /* 1. If identity_upcall is disabled,
310 * permit local client to do anything. */
311 if (is_identity_get_disabled(info->mti_mdt->mdt_identity_cache))
314 /* 2. If fail to get related identities, then forbid any client to
315 * set supplementary group IDs. */
316 if (uc->uc_identity == NULL)
319 /* 3. Check the permission in the identities. */
320 perm = mdt_identity_get_perm(uc->uc_identity,
321 mdt_info_req(info)->rq_peer.nid);
322 if (perm & CFS_SETGRP_PERM)
328 int mdt_check_ucred(struct mdt_thread_info *info)
330 struct ptlrpc_request *req = mdt_info_req(info);
331 struct mdt_device *mdt = info->mti_mdt;
332 struct ptlrpc_user_desc *pud = req->rq_user_desc;
333 struct lu_ucred *ucred = mdt_ucred(info);
334 struct md_identity *identity = NULL;
335 lnet_nid_t peernid = req->rq_peer.nid;
343 LASSERT(ucred != NULL);
344 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
347 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
350 /* sanity check: if we use strong authentication, we expect the
351 * uid which client claimed is true */
352 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
353 req->rq_auth_uid != pud->pud_uid) {
354 CDEBUG(D_SEC, "local client %s: auth uid %u "
355 "while client claims %u:%u/%u:%u\n",
356 libcfs_nid2str(peernid), req->rq_auth_uid,
357 pud->pud_uid, pud->pud_gid,
358 pud->pud_fsuid, pud->pud_fsgid);
362 if (is_identity_get_disabled(mdt->mdt_identity_cache))
365 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
366 if (IS_ERR(identity)) {
367 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
370 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
376 perm = mdt_identity_get_perm(identity, peernid);
377 /* find out the setuid/setgid attempt */
378 setuid = (pud->pud_uid != pud->pud_fsuid);
379 setgid = (pud->pud_gid != pud->pud_fsgid ||
380 pud->pud_gid != identity->mi_gid);
382 /* check permission of setuid */
383 if (setuid && !(perm & CFS_SETUID_PERM)) {
384 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
385 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
386 GOTO(out, rc = -EACCES);
389 /* check permission of setgid */
390 if (setgid && !(perm & CFS_SETGID_PERM)) {
391 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
392 "from %s\n", pud->pud_uid, pud->pud_gid,
393 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
394 libcfs_nid2str(peernid));
395 GOTO(out, rc = -EACCES);
401 mdt_identity_put(mdt->mdt_identity_cache, identity);
405 static int old_init_ucred_common(struct mdt_thread_info *info,
406 struct lu_nodemap *nodemap,
409 struct lu_ucred *uc = mdt_ucred(info);
410 struct mdt_device *mdt = info->mti_mdt;
411 struct md_identity *identity = NULL;
413 if (nodemap && uc->uc_o_uid == nodemap->nm_squash_uid) {
414 /* deny access before we get identity ref */
415 if (nodemap->nmf_deny_unknown)
418 uc->uc_fsuid = nodemap->nm_squash_uid;
419 uc->uc_fsgid = nodemap->nm_squash_gid;
421 uc->uc_suppgids[0] = -1;
422 uc->uc_suppgids[1] = -1;
425 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
426 identity = mdt_identity_get(mdt->mdt_identity_cache,
428 if (IS_ERR(identity)) {
429 if (unlikely(PTR_ERR(identity) == -EREMCHG ||
430 uc->uc_cap & CFS_CAP_FS_MASK)) {
433 CDEBUG(D_SEC, "Deny access without identity: "
434 "uid %u\n", uc->uc_fsuid);
439 uc->uc_identity = identity;
441 /* process root_squash here. */
442 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
444 /* remove fs privilege for non-root user. */
445 if (uc->uc_fsuid && drop_fs_cap)
446 uc->uc_cap &= ~CFS_CAP_FS_MASK;
447 uc->uc_valid = UCRED_OLD;
448 ucred_set_jobid(info, uc);
455 static int old_init_ucred(struct mdt_thread_info *info,
456 struct mdt_body *body, bool drop_fs_cap)
458 struct lu_ucred *uc = mdt_ucred(info);
459 struct lu_nodemap *nodemap;
463 nodemap = nodemap_get_from_exp(info->mti_exp);
465 RETURN(PTR_ERR(nodemap));
467 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
468 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
469 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
470 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
471 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
472 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
473 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
474 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
477 uc->uc_valid = UCRED_INVALID;
478 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
479 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
480 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
481 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
482 uc->uc_suppgids[0] = body->mbo_suppgid;
483 uc->uc_suppgids[1] = -1;
485 uc->uc_cap = body->mbo_capability;
487 rc = old_init_ucred_common(info, nodemap, drop_fs_cap);
488 nodemap_putref(nodemap);
493 static int old_init_ucred_reint(struct mdt_thread_info *info)
495 struct lu_ucred *uc = mdt_ucred(info);
496 struct lu_nodemap *nodemap;
500 nodemap = nodemap_get_from_exp(info->mti_exp);
502 RETURN(PTR_ERR(nodemap));
506 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
507 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
508 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
509 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
511 uc->uc_valid = UCRED_INVALID;
512 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
513 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
516 rc = old_init_ucred_common(info, nodemap, true); /* drop_fs_cap=true */
517 nodemap_putref(nodemap);
522 static inline int __mdt_init_ucred(struct mdt_thread_info *info,
523 struct mdt_body *body,
526 struct ptlrpc_request *req = mdt_info_req(info);
527 struct lu_ucred *uc = mdt_ucred(info);
530 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
533 mdt_exit_ucred(info);
535 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
536 return old_init_ucred(info, body, drop_fs_cap);
538 return new_init_ucred(info, BODY_INIT, body, drop_fs_cap);
541 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
543 return __mdt_init_ucred(info, body, true);
546 /* LU-6528 when "no_subtree_check" is set for NFS export, nfsd_set_fh_dentry()
547 * doesn't set correct fsuid explicitely, but raise capability to allow
548 * exportfs_decode_fh() to reconnect disconnected dentry into dcache. So for
549 * lookup (i.e. intent_getattr), we should keep FS capability, otherwise it
550 * will fail permission check. */
551 int mdt_init_ucred_intent_getattr(struct mdt_thread_info *info,
552 struct mdt_body *body)
554 return __mdt_init_ucred(info, body, false);
557 int mdt_init_ucred_reint(struct mdt_thread_info *info)
559 struct ptlrpc_request *req = mdt_info_req(info);
560 struct lu_ucred *uc = mdt_ucred(info);
561 struct md_attr *ma = &info->mti_attr;
564 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
567 /* LU-5564: for normal close request, skip permission check */
568 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE &&
569 !(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
570 uc->uc_cap |= CFS_CAP_FS_MASK;
572 mdt_exit_ucred(info);
574 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
575 return old_init_ucred_reint(info);
577 return new_init_ucred(info, REC_INIT, NULL, true);
580 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
581 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
583 const struct lov_ost_data_v1 *lod;
587 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
590 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
592 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
593 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
594 le32_to_cpu(lmm->lmm_pattern));
595 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
596 le32_to_cpu(lmm->lmm_stripe_size), count);
598 /* If it's a directory or a released file, then there are
599 * no actual objects to print, so bail out. */
600 if (valid & OBD_MD_FLDIREA ||
601 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
604 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
605 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
608 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
609 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
610 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
614 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
616 const struct lmv_mds_md_v1 *lmm1;
619 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
622 lmm1 = &lmv->lmv_md_v1;
623 CDEBUG(level, "magic 0x%08X, master %#X stripe_count %#x\n",
624 le32_to_cpu(lmm1->lmv_magic),
625 le32_to_cpu(lmm1->lmv_master_mdt_index),
626 le32_to_cpu(lmm1->lmv_stripe_count));
628 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
631 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
634 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
635 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
639 /* Shrink and/or grow reply buffers */
640 int mdt_fix_reply(struct mdt_thread_info *info)
642 struct req_capsule *pill = info->mti_pill;
643 struct mdt_body *body;
644 int md_size, md_packed = 0;
649 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
650 LASSERT(body != NULL);
652 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
654 md_size = body->mbo_eadatasize;
658 acl_size = body->mbo_aclsize;
660 /* this replay - not send info to client */
661 if (info->mti_spec.no_create) {
666 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
671 &RMF_ACL, or &RMF_LOGCOOKIES
672 (optional) &RMF_CAPA1,
673 (optional) &RMF_CAPA2,
674 (optional) something else
677 /* MDT_MD buffer may be bigger than packed value, let's shrink all
678 * buffers before growing it */
679 if (info->mti_big_lmm_used) {
680 /* big_lmm buffer may be used even without packing the result
681 * into reply, just for internal server needs */
682 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
683 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
686 /* free big lmm if md_size is not needed */
687 if (md_size == 0 || md_packed == 0) {
688 info->mti_big_lmm_used = 0;
690 /* buffer must be allocated separately */
691 LASSERT(info->mti_attr.ma_lmm !=
692 req_capsule_server_get(pill, &RMF_MDT_MD));
693 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
695 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
696 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
699 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
700 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
701 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
702 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
703 acl_size, RCL_SERVER);
705 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
706 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
707 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
709 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
710 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
711 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
714 * Some more field should be shrinked if needed.
715 * This should be done by those who added fields to reply message.
718 /* Grow MD buffer if needed finally */
719 if (info->mti_big_lmm_used) {
722 LASSERT(md_size > md_packed);
723 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
724 md_size - md_packed);
725 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
727 /* we can't answer with proper LOV EA, drop flags,
728 * the rc is also returned so this request is
729 * considered as failed */
730 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
731 /* don't return transno along with error */
732 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
734 /* now we need to pack right LOV/LMV EA */
735 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
736 if (info->mti_attr.ma_valid & MA_LOV) {
737 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
739 info->mti_attr.ma_lmm_size);
740 memcpy(lmm, info->mti_attr.ma_lmm,
741 info->mti_attr.ma_lmm_size);
742 } else if (info->mti_attr.ma_valid & MA_LMV) {
743 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
745 info->mti_attr.ma_lmv_size);
746 memcpy(lmm, info->mti_attr.ma_lmv,
747 info->mti_attr.ma_lmv_size);
750 /* update mdt_max_mdsize so clients will be aware about that */
751 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
752 info->mti_mdt->mdt_max_mdsize =
753 info->mti_attr.ma_lmm_size;
754 info->mti_big_lmm_used = 0;
760 /* if object is dying, pack the lov/llog data,
761 * parameter info->mti_attr should be valid at this point! */
762 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
763 const struct md_attr *ma)
765 struct mdt_body *repbody;
766 const struct lu_attr *la = &ma->ma_attr;
769 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
770 LASSERT(repbody != NULL);
772 if (ma->ma_valid & MA_INODE)
773 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
775 if (ma->ma_valid & MA_LOV) {
776 CERROR("No need in LOV EA upon unlink\n");
779 repbody->mbo_eadatasize = 0;
784 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
790 if (in & MDS_ATTR_MODE)
792 if (in & MDS_ATTR_UID)
794 if (in & MDS_ATTR_GID)
796 if (in & MDS_ATTR_SIZE)
798 if (in & MDS_ATTR_BLOCKS)
800 if (in & MDS_ATTR_ATIME_SET)
802 if (in & MDS_ATTR_CTIME_SET)
804 if (in & MDS_ATTR_MTIME_SET)
806 if (in & MDS_ATTR_ATTR_FLAG)
808 if (in & MDS_ATTR_KILL_SUID)
810 if (in & MDS_ATTR_KILL_SGID)
813 if (in & MDS_ATTR_FROM_OPEN)
814 rr->rr_flags |= MRF_OPEN_TRUNC;
815 if (in & MDS_OPEN_OWNEROVERRIDE)
816 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
817 if (in & MDS_ATTR_FORCE)
818 ma->ma_attr_flags |= MDS_PERM_BYPASS;
820 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID |
821 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
822 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
823 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
824 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
825 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
827 CERROR("Unknown attr bits: "LPX64"\n", in);
833 int mdt_name_unpack(struct req_capsule *pill,
834 const struct req_msg_field *field,
836 enum mdt_name_flags flags)
838 ln->ln_name = req_capsule_client_get(pill, field);
839 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
841 if (!lu_name_is_valid(ln)) {
848 if ((flags & MNF_FIX_ANON) &&
849 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
850 /* Newer (3.x) kernels use a name of "/" for the
851 * "anonymous" disconnected dentries from NFS
852 * filehandle conversion. See d_obtain_alias(). */
860 static int mdt_file_secctx_unpack(struct req_capsule *pill,
861 const char **secctx_name,
862 void **secctx, size_t *secctx_size)
871 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT) ||
872 !req_capsule_field_present(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT))
875 name_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX_NAME,
880 name = req_capsule_client_get(pill, &RMF_FILE_SECCTX_NAME);
881 if (strnlen(name, name_size) != name_size - 1)
884 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX, RCL_CLIENT) ||
885 !req_capsule_field_present(pill, &RMF_FILE_SECCTX, RCL_CLIENT))
889 *secctx = req_capsule_client_get(pill, &RMF_FILE_SECCTX);
890 *secctx_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX, RCL_CLIENT);
895 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
897 struct lu_ucred *uc = mdt_ucred(info);
898 struct md_attr *ma = &info->mti_attr;
899 struct lu_attr *la = &ma->ma_attr;
900 struct req_capsule *pill = info->mti_pill;
901 struct mdt_reint_record *rr = &info->mti_rr;
902 struct mdt_rec_setattr *rec;
903 struct lu_nodemap *nodemap;
906 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
907 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
911 /* This prior initialization is needed for old_init_ucred_reint() */
912 uc->uc_fsuid = rec->sa_fsuid;
913 uc->uc_fsgid = rec->sa_fsgid;
914 uc->uc_cap = rec->sa_cap;
915 uc->uc_suppgids[0] = rec->sa_suppgid;
916 uc->uc_suppgids[1] = -1;
918 rr->rr_fid1 = &rec->sa_fid;
919 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
920 la->la_mode = rec->sa_mode;
921 la->la_flags = rec->sa_attr_flags;
923 nodemap = nodemap_get_from_exp(info->mti_exp);
925 RETURN(PTR_ERR(nodemap));
927 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
928 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
929 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
930 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
931 nodemap_putref(nodemap);
933 la->la_size = rec->sa_size;
934 la->la_blocks = rec->sa_blocks;
935 la->la_ctime = rec->sa_ctime;
936 la->la_atime = rec->sa_atime;
937 la->la_mtime = rec->sa_mtime;
938 ma->ma_valid = MA_INODE;
940 if (rec->sa_bias & MDS_DATA_MODIFIED)
941 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
943 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
945 if (rec->sa_bias & MDS_HSM_RELEASE)
946 ma->ma_attr_flags |= MDS_HSM_RELEASE;
948 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
950 if (rec->sa_bias & MDS_CLOSE_LAYOUT_SWAP)
951 ma->ma_attr_flags |= MDS_CLOSE_LAYOUT_SWAP;
953 ma->ma_attr_flags &= ~MDS_CLOSE_LAYOUT_SWAP;
958 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
960 struct req_capsule *pill = info->mti_pill;
961 struct mdt_ioepoch *ioepoch;
964 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
965 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
972 info->mti_close_handle = ioepoch->mio_handle;
977 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
978 struct req_capsule *pill = info->mti_pill;
980 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
981 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
982 if (info->mti_dlm_req == NULL)
989 static int mdt_setattr_unpack(struct mdt_thread_info *info)
991 struct mdt_reint_record *rr = &info->mti_rr;
992 struct md_attr *ma = &info->mti_attr;
993 struct req_capsule *pill = info->mti_pill;
997 rc = mdt_setattr_unpack_rec(info);
1001 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1002 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1003 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1005 if (rr->rr_eadatalen > 0) {
1006 const struct lmv_user_md *lum;
1008 lum = rr->rr_eadata;
1009 /* Sigh ma_valid(from req) does not indicate whether
1010 * it will set LOV/LMV EA, so we have to check magic */
1011 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1012 ma->ma_valid |= MA_LMV;
1013 ma->ma_lmv = (void *)rr->rr_eadata;
1014 ma->ma_lmv_size = rr->rr_eadatalen;
1016 ma->ma_valid |= MA_LOV;
1017 ma->ma_lmm = (void *)rr->rr_eadata;
1018 ma->ma_lmm_size = rr->rr_eadatalen;
1023 rc = mdt_dlmreq_unpack(info);
1027 static int mdt_intent_close_unpack(struct mdt_thread_info *info)
1029 struct md_attr *ma = &info->mti_attr;
1030 struct req_capsule *pill = info->mti_pill;
1033 if (!(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
1036 req_capsule_extend(pill, &RQF_MDS_INTENT_CLOSE);
1038 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1039 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1045 int mdt_close_unpack(struct mdt_thread_info *info)
1050 rc = mdt_close_handle_unpack(info);
1054 rc = mdt_setattr_unpack_rec(info);
1058 rc = mdt_intent_close_unpack(info);
1062 RETURN(mdt_init_ucred_reint(info));
1065 static int mdt_create_unpack(struct mdt_thread_info *info)
1067 struct lu_ucred *uc = mdt_ucred(info);
1068 struct mdt_rec_create *rec;
1069 struct lu_attr *attr = &info->mti_attr.ma_attr;
1070 struct mdt_reint_record *rr = &info->mti_rr;
1071 struct req_capsule *pill = info->mti_pill;
1072 struct md_op_spec *sp = &info->mti_spec;
1076 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1077 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1081 /* This prior initialization is needed for old_init_ucred_reint() */
1082 uc->uc_fsuid = rec->cr_fsuid;
1083 uc->uc_fsgid = rec->cr_fsgid;
1084 uc->uc_cap = rec->cr_cap;
1085 uc->uc_suppgids[0] = rec->cr_suppgid1;
1086 uc->uc_suppgids[1] = -1;
1087 uc->uc_umask = rec->cr_umask;
1089 rr->rr_fid1 = &rec->cr_fid1;
1090 rr->rr_fid2 = &rec->cr_fid2;
1091 attr->la_mode = rec->cr_mode;
1092 attr->la_rdev = rec->cr_rdev;
1093 attr->la_uid = rec->cr_fsuid;
1094 attr->la_gid = rec->cr_fsgid;
1095 attr->la_ctime = rec->cr_time;
1096 attr->la_mtime = rec->cr_time;
1097 attr->la_atime = rec->cr_time;
1098 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1099 LA_CTIME | LA_MTIME | LA_ATIME;
1100 memset(&sp->u, 0, sizeof(sp->u));
1101 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1103 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1107 if (S_ISLNK(attr->la_mode)) {
1108 const char *tgt = NULL;
1110 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1111 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1112 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1113 sp->u.sp_symname = tgt;
1118 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_ACL);
1119 if (S_ISDIR(attr->la_mode) &&
1120 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1121 sp->u.sp_ea.eadata =
1122 req_capsule_client_get(pill, &RMF_EADATA);
1123 sp->u.sp_ea.eadatalen =
1124 req_capsule_get_size(pill, &RMF_EADATA,
1126 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1130 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1131 &sp->sp_cr_file_secctx,
1132 &sp->sp_cr_file_secctx_size);
1136 rc = mdt_dlmreq_unpack(info);
1140 static int mdt_link_unpack(struct mdt_thread_info *info)
1142 struct lu_ucred *uc = mdt_ucred(info);
1143 struct mdt_rec_link *rec;
1144 struct lu_attr *attr = &info->mti_attr.ma_attr;
1145 struct mdt_reint_record *rr = &info->mti_rr;
1146 struct req_capsule *pill = info->mti_pill;
1150 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1151 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1155 /* This prior initialization is needed for old_init_ucred_reint() */
1156 uc->uc_fsuid = rec->lk_fsuid;
1157 uc->uc_fsgid = rec->lk_fsgid;
1158 uc->uc_cap = rec->lk_cap;
1159 uc->uc_suppgids[0] = rec->lk_suppgid1;
1160 uc->uc_suppgids[1] = rec->lk_suppgid2;
1162 attr->la_uid = rec->lk_fsuid;
1163 attr->la_gid = rec->lk_fsgid;
1164 rr->rr_fid1 = &rec->lk_fid1;
1165 rr->rr_fid2 = &rec->lk_fid2;
1166 attr->la_ctime = rec->lk_time;
1167 attr->la_mtime = rec->lk_time;
1168 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1170 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1174 rc = mdt_dlmreq_unpack(info);
1179 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1181 struct lu_ucred *uc = mdt_ucred(info);
1182 struct mdt_rec_unlink *rec;
1183 struct md_attr *ma = &info->mti_attr;
1184 struct lu_attr *attr = &info->mti_attr.ma_attr;
1185 struct mdt_reint_record *rr = &info->mti_rr;
1186 struct req_capsule *pill = info->mti_pill;
1190 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1191 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1195 /* This prior initialization is needed for old_init_ucred_reint() */
1196 uc->uc_fsuid = rec->ul_fsuid;
1197 uc->uc_fsgid = rec->ul_fsgid;
1198 uc->uc_cap = rec->ul_cap;
1199 uc->uc_suppgids[0] = rec->ul_suppgid1;
1200 uc->uc_suppgids[1] = -1;
1202 attr->la_uid = rec->ul_fsuid;
1203 attr->la_gid = rec->ul_fsgid;
1204 rr->rr_fid1 = &rec->ul_fid1;
1205 rr->rr_fid2 = &rec->ul_fid2;
1206 attr->la_ctime = rec->ul_time;
1207 attr->la_mtime = rec->ul_time;
1208 attr->la_mode = rec->ul_mode;
1209 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1211 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1215 if (rec->ul_bias & MDS_VTX_BYPASS)
1216 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1218 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1220 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1222 rc = mdt_dlmreq_unpack(info);
1226 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1228 info->mti_spec.sp_rm_entry = 1;
1229 return mdt_unlink_unpack(info);
1232 static int mdt_rename_unpack(struct mdt_thread_info *info)
1234 struct lu_ucred *uc = mdt_ucred(info);
1235 struct mdt_rec_rename *rec;
1236 struct md_attr *ma = &info->mti_attr;
1237 struct lu_attr *attr = &info->mti_attr.ma_attr;
1238 struct mdt_reint_record *rr = &info->mti_rr;
1239 struct req_capsule *pill = info->mti_pill;
1243 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1244 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1248 /* This prior initialization is needed for old_init_ucred_reint() */
1249 uc->uc_fsuid = rec->rn_fsuid;
1250 uc->uc_fsgid = rec->rn_fsgid;
1251 uc->uc_cap = rec->rn_cap;
1252 uc->uc_suppgids[0] = rec->rn_suppgid1;
1253 uc->uc_suppgids[1] = rec->rn_suppgid2;
1255 attr->la_uid = rec->rn_fsuid;
1256 attr->la_gid = rec->rn_fsgid;
1257 rr->rr_fid1 = &rec->rn_fid1;
1258 rr->rr_fid2 = &rec->rn_fid2;
1259 attr->la_ctime = rec->rn_time;
1260 attr->la_mtime = rec->rn_time;
1261 /* rename_tgt contains the mode already */
1262 attr->la_mode = rec->rn_mode;
1263 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1265 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1269 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1273 if (rec->rn_bias & MDS_VTX_BYPASS)
1274 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1276 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1278 if (rec->rn_bias & MDS_RENAME_MIGRATE) {
1279 req_capsule_extend(info->mti_pill, &RQF_MDS_REINT_MIGRATE);
1280 rc = mdt_close_handle_unpack(info);
1283 info->mti_spec.sp_migrate_close = 1;
1286 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1289 rc = mdt_dlmreq_unpack(info);
1295 * please see comment above LOV_MAGIC_V1_DEF
1297 static void mdt_fix_lov_magic(struct mdt_thread_info *info)
1299 struct mdt_reint_record *rr = &info->mti_rr;
1300 struct lov_user_md_v1 *v1;
1302 v1 = (void *)rr->rr_eadata;
1305 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1306 if (v1->lmm_magic == LOV_USER_MAGIC_V1) {
1307 v1->lmm_magic = LOV_MAGIC_V1_DEF;
1308 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
1309 v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF);
1310 } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
1311 v1->lmm_magic = LOV_MAGIC_V3_DEF;
1312 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
1313 v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF);
1318 static int mdt_open_unpack(struct mdt_thread_info *info)
1320 struct lu_ucred *uc = mdt_ucred(info);
1321 struct mdt_rec_create *rec;
1322 struct lu_attr *attr = &info->mti_attr.ma_attr;
1323 struct req_capsule *pill = info->mti_pill;
1324 struct mdt_reint_record *rr = &info->mti_rr;
1325 struct ptlrpc_request *req = mdt_info_req(info);
1326 struct md_op_spec *sp = &info->mti_spec;
1330 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1331 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1335 /* This prior initialization is needed for old_init_ucred_reint() */
1336 uc->uc_fsuid = rec->cr_fsuid;
1337 uc->uc_fsgid = rec->cr_fsgid;
1338 uc->uc_cap = rec->cr_cap;
1339 uc->uc_suppgids[0] = rec->cr_suppgid1;
1340 uc->uc_suppgids[1] = rec->cr_suppgid2;
1341 uc->uc_umask = rec->cr_umask;
1343 rr->rr_fid1 = &rec->cr_fid1;
1344 rr->rr_fid2 = &rec->cr_fid2;
1345 rr->rr_handle = &rec->cr_old_handle;
1346 attr->la_mode = rec->cr_mode;
1347 attr->la_rdev = rec->cr_rdev;
1348 attr->la_uid = rec->cr_fsuid;
1349 attr->la_gid = rec->cr_fsgid;
1350 attr->la_ctime = rec->cr_time;
1351 attr->la_mtime = rec->cr_time;
1352 attr->la_atime = rec->cr_time;
1353 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1354 LA_CTIME | LA_MTIME | LA_ATIME;
1355 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1356 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1357 /* Do not trigger ASSERTION if client miss to set such flags. */
1358 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1361 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1363 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1365 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1366 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1368 if (rr->rr_eadatalen > 0) {
1369 rr->rr_eadata = req_capsule_client_get(pill,
1371 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1372 sp->u.sp_ea.eadata = rr->rr_eadata;
1373 sp->no_create = !!req_is_replay(req);
1374 mdt_fix_lov_magic(info);
1378 * Client default md_size may be 0 right after client start,
1379 * until all osc are connected, set here just some reasonable
1380 * value to prevent misbehavior.
1382 if (rr->rr_eadatalen == 0 &&
1383 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1384 rr->rr_eadatalen = MIN_MD_SIZE;
1387 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1388 &sp->sp_cr_file_secctx,
1389 &sp->sp_cr_file_secctx_size);
1394 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1396 struct mdt_reint_record *rr = &info->mti_rr;
1397 struct lu_ucred *uc = mdt_ucred(info);
1398 struct lu_attr *attr = &info->mti_attr.ma_attr;
1399 struct req_capsule *pill = info->mti_pill;
1400 struct mdt_rec_setxattr *rec;
1405 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1406 sizeof(struct mdt_rec_reint));
1408 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1412 /* This prior initialization is needed for old_init_ucred_reint() */
1413 uc->uc_fsuid = rec->sx_fsuid;
1414 uc->uc_fsgid = rec->sx_fsgid;
1415 uc->uc_cap = rec->sx_cap;
1416 uc->uc_suppgids[0] = rec->sx_suppgid1;
1417 uc->uc_suppgids[1] = -1;
1419 rr->rr_opcode = rec->sx_opcode;
1420 rr->rr_fid1 = &rec->sx_fid;
1421 attr->la_valid = rec->sx_valid;
1422 attr->la_ctime = rec->sx_time;
1423 attr->la_size = rec->sx_size;
1424 attr->la_flags = rec->sx_flags;
1426 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1430 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1431 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1433 if (rr->rr_eadatalen > 0) {
1434 rr->rr_eadata = req_capsule_client_get(pill,
1436 if (rr->rr_eadata == NULL)
1439 rr->rr_eadata = NULL;
1441 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1442 CDEBUG(D_INFO, "no xattr data supplied\n");
1446 if (mdt_dlmreq_unpack(info) < 0)
1453 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1455 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1456 [REINT_SETATTR] = mdt_setattr_unpack,
1457 [REINT_CREATE] = mdt_create_unpack,
1458 [REINT_LINK] = mdt_link_unpack,
1459 [REINT_UNLINK] = mdt_unlink_unpack,
1460 [REINT_RENAME] = mdt_rename_unpack,
1461 [REINT_OPEN] = mdt_open_unpack,
1462 [REINT_SETXATTR] = mdt_setxattr_unpack,
1463 [REINT_RMENTRY] = mdt_rmentry_unpack,
1464 [REINT_MIGRATE] = mdt_rename_unpack,
1467 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1472 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1473 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1474 info->mti_rr.rr_opcode = op;
1475 rc = mdt_reint_unpackers[op](info);
1477 CERROR("Unexpected opcode %d\n", op);