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 void mdt_exit_ucred(struct mdt_thread_info *info)
67 struct lu_ucred *uc = mdt_ucred(info);
68 struct mdt_device *mdt = info->mti_mdt;
71 if (uc->uc_valid != UCRED_INIT) {
72 uc->uc_suppgids[0] = uc->uc_suppgids[1] = -1;
74 put_group_info(uc->uc_ginfo);
77 if (uc->uc_identity) {
78 mdt_identity_put(mdt->mdt_identity_cache,
80 uc->uc_identity = NULL;
82 uc->uc_valid = UCRED_INIT;
86 static int match_nosquash_list(struct rw_semaphore *sem,
87 struct list_head *nidlist,
93 rc = cfs_match_nid(peernid, nidlist);
98 /* root_squash for inter-MDS operations */
99 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t 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_sem,
110 &squash->rsi_nosquash_nids,
112 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
113 libcfs_nid2str(peernid));
117 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
118 libcfs_nid2str(peernid),
119 ucred->uc_fsuid, ucred->uc_fsgid, 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;
125 ucred->uc_suppgids[0] = -1;
126 ucred->uc_suppgids[1] = -1;
131 static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc)
133 struct ptlrpc_request *req = mdt_info_req(info);
134 const char *jobid = mdt_req_get_jobid(req);
136 /* set jobid if specified. */
138 strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid));
140 uc->uc_jobid[0] = '\0';
143 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
144 void *buf, bool drop_fs_cap)
146 struct ptlrpc_request *req = mdt_info_req(info);
147 struct mdt_device *mdt = info->mti_mdt;
148 struct ptlrpc_user_desc *pud = req->rq_user_desc;
149 struct lu_ucred *ucred = mdt_ucred(info);
150 lnet_nid_t peernid = req->rq_peer.nid;
158 LASSERT(req->rq_auth_gss);
159 LASSERT(!req->rq_auth_usr_mdt);
160 LASSERT(req->rq_user_desc);
161 LASSERT(ucred != NULL);
163 ucred->uc_valid = UCRED_INVALID;
165 ucred->uc_o_uid = pud->pud_uid;
166 ucred->uc_o_gid = pud->pud_gid;
167 ucred->uc_o_fsuid = pud->pud_fsuid;
168 ucred->uc_o_fsgid = pud->pud_fsgid;
170 if (type == BODY_INIT) {
171 struct mdt_body *body = (struct mdt_body *)buf;
173 ucred->uc_suppgids[0] = body->mbo_suppgid;
174 ucred->uc_suppgids[1] = -1;
177 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
178 req->rq_auth_uid != pud->pud_uid) {
179 CDEBUG(D_SEC, "local client %s: auth uid %u "
180 "while client claims %u:%u/%u:%u\n",
181 libcfs_nid2str(peernid), req->rq_auth_uid,
182 pud->pud_uid, pud->pud_gid,
183 pud->pud_fsuid, pud->pud_fsgid);
187 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
188 ucred->uc_identity = NULL;
189 perm = CFS_SETUID_PERM | CFS_SETGID_PERM | CFS_SETGRP_PERM;
191 struct md_identity *identity;
193 identity = mdt_identity_get(mdt->mdt_identity_cache,
195 if (IS_ERR(identity)) {
196 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
197 ucred->uc_identity = NULL;
198 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
202 "Deny access without identity: uid %u\n",
207 ucred->uc_identity = identity;
208 perm = mdt_identity_get_perm(ucred->uc_identity,
213 /* find out the setuid/setgid attempt */
214 setuid = (pud->pud_uid != pud->pud_fsuid);
215 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
216 (ucred->uc_identity &&
217 (pud->pud_gid != ucred->uc_identity->mi_gid)));
219 /* check permission of setuid */
220 if (setuid && !(perm & CFS_SETUID_PERM)) {
221 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
222 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
223 GOTO(out, rc = -EACCES);
226 /* check permission of setgid */
227 if (setgid && !(perm & CFS_SETGID_PERM)) {
228 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
229 "from %s\n", pud->pud_uid, pud->pud_gid,
230 pud->pud_fsuid, pud->pud_fsgid,
231 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
232 GOTO(out, rc = -EACCES);
235 if (perm & CFS_SETGRP_PERM) {
236 if (pud->pud_ngroups) {
237 /* setgroups for local client */
238 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
239 if (!ucred->uc_ginfo) {
240 CERROR("failed to alloc %d groups\n",
242 GOTO(out, rc = -ENOMEM);
245 lustre_groups_from_list(ucred->uc_ginfo,
247 lustre_groups_sort(ucred->uc_ginfo);
249 ucred->uc_ginfo = NULL;
252 ucred->uc_suppgids[0] = -1;
253 ucred->uc_suppgids[1] = -1;
254 ucred->uc_ginfo = NULL;
257 ucred->uc_uid = pud->pud_uid;
258 ucred->uc_gid = pud->pud_gid;
259 ucred->uc_fsuid = pud->pud_fsuid;
260 ucred->uc_fsgid = pud->pud_fsgid;
262 /* process root_squash here. */
263 mdt_root_squash(info, peernid);
265 /* remove fs privilege for non-root user. */
266 if (ucred->uc_fsuid && drop_fs_cap)
267 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
269 ucred->uc_cap = pud->pud_cap;
270 ucred->uc_valid = UCRED_NEW;
271 ucred_set_jobid(info, ucred);
277 if (ucred->uc_ginfo) {
278 put_group_info(ucred->uc_ginfo);
279 ucred->uc_ginfo = NULL;
281 if (ucred->uc_identity) {
282 mdt_identity_put(mdt->mdt_identity_cache,
284 ucred->uc_identity = NULL;
292 * Check whether allow the client to set supplementary group IDs or not.
294 * \param[in] info pointer to the thread context
295 * \param[in] uc pointer to the RPC user descriptor
297 * \retval true if allow to set supplementary group IDs
298 * \retval false for other cases
300 bool allow_client_chgrp(struct mdt_thread_info *info, struct lu_ucred *uc)
304 /* 1. If identity_upcall is disabled,
305 * permit local client to do anything. */
306 if (is_identity_get_disabled(info->mti_mdt->mdt_identity_cache))
309 /* 2. If fail to get related identities, then forbid any client to
310 * set supplementary group IDs. */
311 if (uc->uc_identity == NULL)
314 /* 3. Check the permission in the identities. */
315 perm = mdt_identity_get_perm(uc->uc_identity,
316 mdt_info_req(info)->rq_peer.nid);
317 if (perm & CFS_SETGRP_PERM)
323 int mdt_check_ucred(struct mdt_thread_info *info)
325 struct ptlrpc_request *req = mdt_info_req(info);
326 struct mdt_device *mdt = info->mti_mdt;
327 struct ptlrpc_user_desc *pud = req->rq_user_desc;
328 struct lu_ucred *ucred = mdt_ucred(info);
329 struct md_identity *identity = NULL;
330 lnet_nid_t peernid = req->rq_peer.nid;
338 LASSERT(ucred != NULL);
339 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
342 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
345 /* sanity check: if we use strong authentication, we expect the
346 * uid which client claimed is true */
347 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
348 req->rq_auth_uid != pud->pud_uid) {
349 CDEBUG(D_SEC, "local client %s: auth uid %u "
350 "while client claims %u:%u/%u:%u\n",
351 libcfs_nid2str(peernid), req->rq_auth_uid,
352 pud->pud_uid, pud->pud_gid,
353 pud->pud_fsuid, pud->pud_fsgid);
357 if (is_identity_get_disabled(mdt->mdt_identity_cache))
360 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
361 if (IS_ERR(identity)) {
362 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
365 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
371 perm = mdt_identity_get_perm(identity, peernid);
372 /* find out the setuid/setgid attempt */
373 setuid = (pud->pud_uid != pud->pud_fsuid);
374 setgid = (pud->pud_gid != pud->pud_fsgid ||
375 pud->pud_gid != identity->mi_gid);
377 /* check permission of setuid */
378 if (setuid && !(perm & CFS_SETUID_PERM)) {
379 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
380 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
381 GOTO(out, rc = -EACCES);
384 /* check permission of setgid */
385 if (setgid && !(perm & CFS_SETGID_PERM)) {
386 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
387 "from %s\n", pud->pud_uid, pud->pud_gid,
388 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
389 libcfs_nid2str(peernid));
390 GOTO(out, rc = -EACCES);
396 mdt_identity_put(mdt->mdt_identity_cache, identity);
400 static int old_init_ucred_common(struct mdt_thread_info *info,
401 struct lu_nodemap *nodemap,
404 struct lu_ucred *uc = mdt_ucred(info);
405 struct mdt_device *mdt = info->mti_mdt;
406 struct md_identity *identity = NULL;
408 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
409 identity = mdt_identity_get(mdt->mdt_identity_cache,
411 if (IS_ERR(identity)) {
412 if (unlikely(PTR_ERR(identity) == -EREMCHG ||
413 uc->uc_cap & CFS_CAP_FS_MASK)) {
416 CDEBUG(D_SEC, "Deny access without identity: "
417 "uid %u\n", uc->uc_fsuid);
422 uc->uc_identity = identity;
424 if (nodemap && uc->uc_o_uid == nodemap->nm_squash_uid) {
425 uc->uc_fsuid = nodemap->nm_squash_uid;
426 uc->uc_fsgid = nodemap->nm_squash_gid;
428 uc->uc_suppgids[0] = -1;
429 uc->uc_suppgids[1] = -1;
432 /* process root_squash here. */
433 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
435 /* remove fs privilege for non-root user. */
436 if (uc->uc_fsuid && drop_fs_cap)
437 uc->uc_cap &= ~CFS_CAP_FS_MASK;
438 uc->uc_valid = UCRED_OLD;
439 ucred_set_jobid(info, uc);
444 static int old_init_ucred(struct mdt_thread_info *info,
445 struct mdt_body *body, bool drop_fs_cap)
447 struct lu_ucred *uc = mdt_ucred(info);
448 struct lu_nodemap *nodemap;
452 nodemap = nodemap_get_from_exp(info->mti_exp);
454 RETURN(PTR_ERR(nodemap));
456 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
457 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
458 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
459 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
460 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
461 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
462 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
463 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
466 uc->uc_valid = UCRED_INVALID;
467 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
468 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
469 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
470 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
471 uc->uc_suppgids[0] = body->mbo_suppgid;
472 uc->uc_suppgids[1] = -1;
474 uc->uc_cap = body->mbo_capability;
476 rc = old_init_ucred_common(info, nodemap, drop_fs_cap);
477 nodemap_putref(nodemap);
482 static int old_init_ucred_reint(struct mdt_thread_info *info)
484 struct lu_ucred *uc = mdt_ucred(info);
485 struct lu_nodemap *nodemap;
489 nodemap = nodemap_get_from_exp(info->mti_exp);
491 RETURN(PTR_ERR(nodemap));
495 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
496 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
497 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
498 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
500 uc->uc_valid = UCRED_INVALID;
501 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
502 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
505 rc = old_init_ucred_common(info, nodemap, true); /* drop_fs_cap=true */
506 nodemap_putref(nodemap);
511 static inline int __mdt_init_ucred(struct mdt_thread_info *info,
512 struct mdt_body *body,
515 struct ptlrpc_request *req = mdt_info_req(info);
516 struct lu_ucred *uc = mdt_ucred(info);
519 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
522 mdt_exit_ucred(info);
524 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
525 return old_init_ucred(info, body, drop_fs_cap);
527 return new_init_ucred(info, BODY_INIT, body, drop_fs_cap);
530 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
532 return __mdt_init_ucred(info, body, true);
535 /* LU-6528 when "no_subtree_check" is set for NFS export, nfsd_set_fh_dentry()
536 * doesn't set correct fsuid explicitely, but raise capability to allow
537 * exportfs_decode_fh() to reconnect disconnected dentry into dcache. So for
538 * lookup (i.e. intent_getattr), we should keep FS capability, otherwise it
539 * will fail permission check. */
540 int mdt_init_ucred_intent_getattr(struct mdt_thread_info *info,
541 struct mdt_body *body)
543 return __mdt_init_ucred(info, body, false);
546 int mdt_init_ucred_reint(struct mdt_thread_info *info)
548 struct ptlrpc_request *req = mdt_info_req(info);
549 struct lu_ucred *uc = mdt_ucred(info);
552 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
555 mdt_exit_ucred(info);
557 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
558 return old_init_ucred_reint(info);
560 return new_init_ucred(info, REC_INIT, NULL, true);
563 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
564 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
566 const struct lov_ost_data_v1 *lod;
570 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
573 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
575 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
576 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
577 le32_to_cpu(lmm->lmm_pattern));
578 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
579 le32_to_cpu(lmm->lmm_stripe_size), count);
581 /* If it's a directory or a released file, then there are
582 * no actual objects to print, so bail out. */
583 if (valid & OBD_MD_FLDIREA ||
584 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
587 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
588 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
591 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
592 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
593 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
597 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
599 const struct lmv_mds_md_v1 *lmm1;
602 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
605 lmm1 = &lmv->lmv_md_v1;
606 CDEBUG(level, "magic 0x%08X, master %#X stripe_count %#x\n",
607 le32_to_cpu(lmm1->lmv_magic),
608 le32_to_cpu(lmm1->lmv_master_mdt_index),
609 le32_to_cpu(lmm1->lmv_stripe_count));
611 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
614 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
617 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
618 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
622 /* Shrink and/or grow reply buffers */
623 int mdt_fix_reply(struct mdt_thread_info *info)
625 struct req_capsule *pill = info->mti_pill;
626 struct mdt_body *body;
627 int md_size, md_packed = 0;
632 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
633 LASSERT(body != NULL);
635 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
637 md_size = body->mbo_eadatasize;
641 acl_size = body->mbo_aclsize;
643 /* this replay - not send info to client */
644 if (info->mti_spec.no_create) {
649 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
654 &RMF_ACL, or &RMF_LOGCOOKIES
655 (optional) &RMF_CAPA1,
656 (optional) &RMF_CAPA2,
657 (optional) something else
660 /* MDT_MD buffer may be bigger than packed value, let's shrink all
661 * buffers before growing it */
662 if (info->mti_big_lmm_used) {
663 /* big_lmm buffer may be used even without packing the result
664 * into reply, just for internal server needs */
665 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
666 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
669 /* free big lmm if md_size is not needed */
670 if (md_size == 0 || md_packed == 0) {
671 info->mti_big_lmm_used = 0;
673 /* buffer must be allocated separately */
674 LASSERT(info->mti_attr.ma_lmm !=
675 req_capsule_server_get(pill, &RMF_MDT_MD));
676 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
678 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
679 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
682 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
683 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
684 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
685 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
686 acl_size, RCL_SERVER);
688 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
689 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
690 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
692 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
693 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
694 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
697 * Some more field should be shrinked if needed.
698 * This should be done by those who added fields to reply message.
701 /* Grow MD buffer if needed finally */
702 if (info->mti_big_lmm_used) {
705 LASSERT(md_size > md_packed);
706 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
707 md_size - md_packed);
708 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
710 /* we can't answer with proper LOV EA, drop flags,
711 * the rc is also returned so this request is
712 * considered as failed */
713 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
714 /* don't return transno along with error */
715 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
717 /* now we need to pack right LOV/LMV EA */
718 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
719 if (info->mti_attr.ma_valid & MA_LOV) {
720 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
722 info->mti_attr.ma_lmm_size);
723 memcpy(lmm, info->mti_attr.ma_lmm,
724 info->mti_attr.ma_lmm_size);
725 } else if (info->mti_attr.ma_valid & MA_LMV) {
726 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
728 info->mti_attr.ma_lmv_size);
729 memcpy(lmm, info->mti_attr.ma_lmv,
730 info->mti_attr.ma_lmv_size);
733 /* update mdt_max_mdsize so clients will be aware about that */
734 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
735 info->mti_mdt->mdt_max_mdsize =
736 info->mti_attr.ma_lmm_size;
737 info->mti_big_lmm_used = 0;
743 /* if object is dying, pack the lov/llog data,
744 * parameter info->mti_attr should be valid at this point! */
745 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
746 const struct md_attr *ma)
748 struct mdt_body *repbody;
749 const struct lu_attr *la = &ma->ma_attr;
752 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
753 LASSERT(repbody != NULL);
755 if (ma->ma_valid & MA_INODE)
756 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
758 if (ma->ma_valid & MA_LOV) {
759 CERROR("No need in LOV EA upon unlink\n");
762 repbody->mbo_eadatasize = 0;
767 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
773 if (in & MDS_ATTR_MODE)
775 if (in & MDS_ATTR_UID)
777 if (in & MDS_ATTR_GID)
779 if (in & MDS_ATTR_SIZE)
781 if (in & MDS_ATTR_BLOCKS)
783 if (in & MDS_ATTR_ATIME_SET)
785 if (in & MDS_ATTR_CTIME_SET)
787 if (in & MDS_ATTR_MTIME_SET)
789 if (in & MDS_ATTR_ATTR_FLAG)
791 if (in & MDS_ATTR_KILL_SUID)
793 if (in & MDS_ATTR_KILL_SGID)
796 if (in & MDS_ATTR_FROM_OPEN)
797 rr->rr_flags |= MRF_OPEN_TRUNC;
798 if (in & MDS_OPEN_OWNEROVERRIDE)
799 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
800 if (in & MDS_ATTR_FORCE)
801 ma->ma_attr_flags |= MDS_PERM_BYPASS;
803 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID |
804 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
805 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
806 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
807 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
808 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
810 CERROR("Unknown attr bits: "LPX64"\n", in);
816 int mdt_name_unpack(struct req_capsule *pill,
817 const struct req_msg_field *field,
819 enum mdt_name_flags flags)
821 ln->ln_name = req_capsule_client_get(pill, field);
822 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
824 if (!lu_name_is_valid(ln)) {
831 if ((flags & MNF_FIX_ANON) &&
832 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
833 /* Newer (3.x) kernels use a name of "/" for the
834 * "anonymous" disconnected dentries from NFS
835 * filehandle conversion. See d_obtain_alias(). */
843 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
845 struct lu_ucred *uc = mdt_ucred(info);
846 struct md_attr *ma = &info->mti_attr;
847 struct lu_attr *la = &ma->ma_attr;
848 struct req_capsule *pill = info->mti_pill;
849 struct mdt_reint_record *rr = &info->mti_rr;
850 struct mdt_rec_setattr *rec;
851 struct lu_nodemap *nodemap;
854 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
855 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
859 /* This prior initialization is needed for old_init_ucred_reint() */
860 uc->uc_fsuid = rec->sa_fsuid;
861 uc->uc_fsgid = rec->sa_fsgid;
862 uc->uc_cap = rec->sa_cap;
863 uc->uc_suppgids[0] = rec->sa_suppgid;
864 uc->uc_suppgids[1] = -1;
866 rr->rr_fid1 = &rec->sa_fid;
867 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
868 la->la_mode = rec->sa_mode;
869 la->la_flags = rec->sa_attr_flags;
871 nodemap = nodemap_get_from_exp(info->mti_exp);
873 RETURN(PTR_ERR(nodemap));
875 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
876 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
877 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
878 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
879 nodemap_putref(nodemap);
881 la->la_size = rec->sa_size;
882 la->la_blocks = rec->sa_blocks;
883 la->la_ctime = rec->sa_ctime;
884 la->la_atime = rec->sa_atime;
885 la->la_mtime = rec->sa_mtime;
886 ma->ma_valid = MA_INODE;
888 if (rec->sa_bias & MDS_DATA_MODIFIED)
889 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
891 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
893 if (rec->sa_bias & MDS_HSM_RELEASE)
894 ma->ma_attr_flags |= MDS_HSM_RELEASE;
896 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
898 if (rec->sa_bias & MDS_CLOSE_LAYOUT_SWAP)
899 ma->ma_attr_flags |= MDS_CLOSE_LAYOUT_SWAP;
901 ma->ma_attr_flags &= ~MDS_CLOSE_LAYOUT_SWAP;
906 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
908 struct req_capsule *pill = info->mti_pill;
909 struct mdt_ioepoch *ioepoch;
912 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
913 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
920 info->mti_close_handle = ioepoch->mio_handle;
925 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
926 struct req_capsule *pill = info->mti_pill;
928 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
929 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
930 if (info->mti_dlm_req == NULL)
937 static int mdt_setattr_unpack(struct mdt_thread_info *info)
939 struct mdt_reint_record *rr = &info->mti_rr;
940 struct md_attr *ma = &info->mti_attr;
941 struct req_capsule *pill = info->mti_pill;
945 rc = mdt_setattr_unpack_rec(info);
949 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
950 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
951 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
953 if (rr->rr_eadatalen > 0) {
954 const struct lmv_user_md *lum;
957 /* Sigh ma_valid(from req) does not indicate whether
958 * it will set LOV/LMV EA, so we have to check magic */
959 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
960 ma->ma_valid |= MA_LMV;
961 ma->ma_lmv = (void *)rr->rr_eadata;
962 ma->ma_lmv_size = rr->rr_eadatalen;
964 ma->ma_valid |= MA_LOV;
965 ma->ma_lmm = (void *)rr->rr_eadata;
966 ma->ma_lmm_size = rr->rr_eadatalen;
971 rc = mdt_dlmreq_unpack(info);
975 static int mdt_intent_close_unpack(struct mdt_thread_info *info)
977 struct md_attr *ma = &info->mti_attr;
978 struct req_capsule *pill = info->mti_pill;
981 if (!(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
984 req_capsule_extend(pill, &RQF_MDS_INTENT_CLOSE);
986 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
987 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
993 int mdt_close_unpack(struct mdt_thread_info *info)
998 rc = mdt_close_handle_unpack(info);
1002 rc = mdt_setattr_unpack_rec(info);
1006 rc = mdt_intent_close_unpack(info);
1010 RETURN(mdt_init_ucred_reint(info));
1013 static int mdt_create_unpack(struct mdt_thread_info *info)
1015 struct lu_ucred *uc = mdt_ucred(info);
1016 struct mdt_rec_create *rec;
1017 struct lu_attr *attr = &info->mti_attr.ma_attr;
1018 struct mdt_reint_record *rr = &info->mti_rr;
1019 struct req_capsule *pill = info->mti_pill;
1020 struct md_op_spec *sp = &info->mti_spec;
1024 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1025 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1029 /* This prior initialization is needed for old_init_ucred_reint() */
1030 uc->uc_fsuid = rec->cr_fsuid;
1031 uc->uc_fsgid = rec->cr_fsgid;
1032 uc->uc_cap = rec->cr_cap;
1033 uc->uc_suppgids[0] = rec->cr_suppgid1;
1034 uc->uc_suppgids[1] = -1;
1035 uc->uc_umask = rec->cr_umask;
1037 rr->rr_fid1 = &rec->cr_fid1;
1038 rr->rr_fid2 = &rec->cr_fid2;
1039 attr->la_mode = rec->cr_mode;
1040 attr->la_rdev = rec->cr_rdev;
1041 attr->la_uid = rec->cr_fsuid;
1042 attr->la_gid = rec->cr_fsgid;
1043 attr->la_ctime = rec->cr_time;
1044 attr->la_mtime = rec->cr_time;
1045 attr->la_atime = rec->cr_time;
1046 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1047 LA_CTIME | LA_MTIME | LA_ATIME;
1048 memset(&sp->u, 0, sizeof(sp->u));
1049 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1051 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1055 if (S_ISLNK(attr->la_mode)) {
1056 const char *tgt = NULL;
1058 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1059 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1060 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1061 sp->u.sp_symname = tgt;
1066 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_ACL);
1067 if (S_ISDIR(attr->la_mode) &&
1068 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1069 sp->u.sp_ea.eadata =
1070 req_capsule_client_get(pill, &RMF_EADATA);
1071 sp->u.sp_ea.eadatalen =
1072 req_capsule_get_size(pill, &RMF_EADATA,
1074 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1078 rc = mdt_dlmreq_unpack(info);
1082 static int mdt_link_unpack(struct mdt_thread_info *info)
1084 struct lu_ucred *uc = mdt_ucred(info);
1085 struct mdt_rec_link *rec;
1086 struct lu_attr *attr = &info->mti_attr.ma_attr;
1087 struct mdt_reint_record *rr = &info->mti_rr;
1088 struct req_capsule *pill = info->mti_pill;
1092 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1093 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1097 /* This prior initialization is needed for old_init_ucred_reint() */
1098 uc->uc_fsuid = rec->lk_fsuid;
1099 uc->uc_fsgid = rec->lk_fsgid;
1100 uc->uc_cap = rec->lk_cap;
1101 uc->uc_suppgids[0] = rec->lk_suppgid1;
1102 uc->uc_suppgids[1] = rec->lk_suppgid2;
1104 attr->la_uid = rec->lk_fsuid;
1105 attr->la_gid = rec->lk_fsgid;
1106 rr->rr_fid1 = &rec->lk_fid1;
1107 rr->rr_fid2 = &rec->lk_fid2;
1108 attr->la_ctime = rec->lk_time;
1109 attr->la_mtime = rec->lk_time;
1110 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1112 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1116 rc = mdt_dlmreq_unpack(info);
1121 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1123 struct lu_ucred *uc = mdt_ucred(info);
1124 struct mdt_rec_unlink *rec;
1125 struct md_attr *ma = &info->mti_attr;
1126 struct lu_attr *attr = &info->mti_attr.ma_attr;
1127 struct mdt_reint_record *rr = &info->mti_rr;
1128 struct req_capsule *pill = info->mti_pill;
1132 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1133 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1137 /* This prior initialization is needed for old_init_ucred_reint() */
1138 uc->uc_fsuid = rec->ul_fsuid;
1139 uc->uc_fsgid = rec->ul_fsgid;
1140 uc->uc_cap = rec->ul_cap;
1141 uc->uc_suppgids[0] = rec->ul_suppgid1;
1142 uc->uc_suppgids[1] = -1;
1144 attr->la_uid = rec->ul_fsuid;
1145 attr->la_gid = rec->ul_fsgid;
1146 rr->rr_fid1 = &rec->ul_fid1;
1147 rr->rr_fid2 = &rec->ul_fid2;
1148 attr->la_ctime = rec->ul_time;
1149 attr->la_mtime = rec->ul_time;
1150 attr->la_mode = rec->ul_mode;
1151 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1153 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1157 if (rec->ul_bias & MDS_VTX_BYPASS)
1158 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1160 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1162 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1164 rc = mdt_dlmreq_unpack(info);
1168 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1170 info->mti_spec.sp_rm_entry = 1;
1171 return mdt_unlink_unpack(info);
1174 static int mdt_rename_unpack(struct mdt_thread_info *info)
1176 struct lu_ucred *uc = mdt_ucred(info);
1177 struct mdt_rec_rename *rec;
1178 struct md_attr *ma = &info->mti_attr;
1179 struct lu_attr *attr = &info->mti_attr.ma_attr;
1180 struct mdt_reint_record *rr = &info->mti_rr;
1181 struct req_capsule *pill = info->mti_pill;
1185 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1186 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1190 /* This prior initialization is needed for old_init_ucred_reint() */
1191 uc->uc_fsuid = rec->rn_fsuid;
1192 uc->uc_fsgid = rec->rn_fsgid;
1193 uc->uc_cap = rec->rn_cap;
1194 uc->uc_suppgids[0] = rec->rn_suppgid1;
1195 uc->uc_suppgids[1] = rec->rn_suppgid2;
1197 attr->la_uid = rec->rn_fsuid;
1198 attr->la_gid = rec->rn_fsgid;
1199 rr->rr_fid1 = &rec->rn_fid1;
1200 rr->rr_fid2 = &rec->rn_fid2;
1201 attr->la_ctime = rec->rn_time;
1202 attr->la_mtime = rec->rn_time;
1203 /* rename_tgt contains the mode already */
1204 attr->la_mode = rec->rn_mode;
1205 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1207 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1211 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1215 if (rec->rn_bias & MDS_VTX_BYPASS)
1216 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1218 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1220 if (rec->rn_bias & MDS_RENAME_MIGRATE) {
1221 req_capsule_extend(info->mti_pill, &RQF_MDS_REINT_MIGRATE);
1222 rc = mdt_close_handle_unpack(info);
1225 info->mti_spec.sp_migrate_close = 1;
1228 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1231 rc = mdt_dlmreq_unpack(info);
1237 * please see comment above LOV_MAGIC_V1_DEF
1239 static void mdt_fix_lov_magic(struct mdt_thread_info *info)
1241 struct mdt_reint_record *rr = &info->mti_rr;
1242 struct lov_user_md_v1 *v1;
1244 v1 = (void *)rr->rr_eadata;
1247 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1248 if (v1->lmm_magic == LOV_USER_MAGIC_V1) {
1249 v1->lmm_magic = LOV_MAGIC_V1_DEF;
1250 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
1251 v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF);
1252 } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
1253 v1->lmm_magic = LOV_MAGIC_V3_DEF;
1254 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
1255 v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF);
1260 static int mdt_open_unpack(struct mdt_thread_info *info)
1262 struct lu_ucred *uc = mdt_ucred(info);
1263 struct mdt_rec_create *rec;
1264 struct lu_attr *attr = &info->mti_attr.ma_attr;
1265 struct req_capsule *pill = info->mti_pill;
1266 struct mdt_reint_record *rr = &info->mti_rr;
1267 struct ptlrpc_request *req = mdt_info_req(info);
1268 struct md_op_spec *sp = &info->mti_spec;
1271 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1272 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1276 /* This prior initialization is needed for old_init_ucred_reint() */
1277 uc->uc_fsuid = rec->cr_fsuid;
1278 uc->uc_fsgid = rec->cr_fsgid;
1279 uc->uc_cap = rec->cr_cap;
1280 uc->uc_suppgids[0] = rec->cr_suppgid1;
1281 uc->uc_suppgids[1] = rec->cr_suppgid2;
1282 uc->uc_umask = rec->cr_umask;
1284 rr->rr_fid1 = &rec->cr_fid1;
1285 rr->rr_fid2 = &rec->cr_fid2;
1286 rr->rr_handle = &rec->cr_old_handle;
1287 attr->la_mode = rec->cr_mode;
1288 attr->la_rdev = rec->cr_rdev;
1289 attr->la_uid = rec->cr_fsuid;
1290 attr->la_gid = rec->cr_fsgid;
1291 attr->la_ctime = rec->cr_time;
1292 attr->la_mtime = rec->cr_time;
1293 attr->la_atime = rec->cr_time;
1294 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1295 LA_CTIME | LA_MTIME | LA_ATIME;
1296 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1297 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1298 /* Do not trigger ASSERTION if client miss to set such flags. */
1299 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1302 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1304 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1306 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1307 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1309 if (rr->rr_eadatalen > 0) {
1310 rr->rr_eadata = req_capsule_client_get(pill,
1312 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1313 sp->u.sp_ea.eadata = rr->rr_eadata;
1314 sp->no_create = !!req_is_replay(req);
1315 mdt_fix_lov_magic(info);
1319 * Client default md_size may be 0 right after client start,
1320 * until all osc are connected, set here just some reasonable
1321 * value to prevent misbehavior.
1323 if (rr->rr_eadatalen == 0 &&
1324 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1325 rr->rr_eadatalen = MIN_MD_SIZE;
1331 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1333 struct mdt_reint_record *rr = &info->mti_rr;
1334 struct lu_ucred *uc = mdt_ucred(info);
1335 struct lu_attr *attr = &info->mti_attr.ma_attr;
1336 struct req_capsule *pill = info->mti_pill;
1337 struct mdt_rec_setxattr *rec;
1342 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1343 sizeof(struct mdt_rec_reint));
1345 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1349 /* This prior initialization is needed for old_init_ucred_reint() */
1350 uc->uc_fsuid = rec->sx_fsuid;
1351 uc->uc_fsgid = rec->sx_fsgid;
1352 uc->uc_cap = rec->sx_cap;
1353 uc->uc_suppgids[0] = rec->sx_suppgid1;
1354 uc->uc_suppgids[1] = -1;
1356 rr->rr_opcode = rec->sx_opcode;
1357 rr->rr_fid1 = &rec->sx_fid;
1358 attr->la_valid = rec->sx_valid;
1359 attr->la_ctime = rec->sx_time;
1360 attr->la_size = rec->sx_size;
1361 attr->la_flags = rec->sx_flags;
1363 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1367 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1368 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1370 if (rr->rr_eadatalen > 0) {
1371 rr->rr_eadata = req_capsule_client_get(pill,
1373 if (rr->rr_eadata == NULL)
1376 rr->rr_eadata = NULL;
1378 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1379 CDEBUG(D_INFO, "no xattr data supplied\n");
1383 if (mdt_dlmreq_unpack(info) < 0)
1390 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1392 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1393 [REINT_SETATTR] = mdt_setattr_unpack,
1394 [REINT_CREATE] = mdt_create_unpack,
1395 [REINT_LINK] = mdt_link_unpack,
1396 [REINT_UNLINK] = mdt_unlink_unpack,
1397 [REINT_RENAME] = mdt_rename_unpack,
1398 [REINT_OPEN] = mdt_open_unpack,
1399 [REINT_SETXATTR] = mdt_setxattr_unpack,
1400 [REINT_RMENTRY] = mdt_rmentry_unpack,
1401 [REINT_MIGRATE] = mdt_rename_unpack,
1404 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1409 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1410 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1411 info->mti_rr.rr_opcode = op;
1412 rc = mdt_reint_unpackers[op](info);
1414 CERROR("Unexpected opcode %d\n", op);