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, 2014, 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,
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;
152 __u32 remote = exp_connect_rmtclient(info->mti_exp);
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 /* sanity check: we expect the uid which client claimed is true */
180 if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_mapped_uid))) {
181 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
185 if (ptlrpc_user_desc_do_idmap(req, pud))
188 if (req->rq_auth_mapped_uid != pud->pud_uid) {
189 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
190 "while client claims %u:%u/%u:%u\n",
191 libcfs_nid2str(peernid), req->rq_auth_uid,
192 req->rq_auth_mapped_uid,
193 pud->pud_uid, pud->pud_gid,
194 pud->pud_fsuid, pud->pud_fsgid);
198 if (req->rq_auth_uid != pud->pud_uid) {
199 CDEBUG(D_SEC, "local client %s: auth uid %u "
200 "while client claims %u:%u/%u:%u\n",
201 libcfs_nid2str(peernid), req->rq_auth_uid,
202 pud->pud_uid, pud->pud_gid,
203 pud->pud_fsuid, pud->pud_fsgid);
208 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
210 CDEBUG(D_SEC, "remote client must run with identity_get "
214 ucred->uc_identity = NULL;
215 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
219 struct md_identity *identity;
221 identity = mdt_identity_get(mdt->mdt_identity_cache,
223 if (IS_ERR(identity)) {
224 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
226 ucred->uc_identity = NULL;
227 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
230 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
235 ucred->uc_identity = identity;
236 perm = mdt_identity_get_perm(ucred->uc_identity,
241 /* find out the setuid/setgid attempt */
242 setuid = (pud->pud_uid != pud->pud_fsuid);
243 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
244 (ucred->uc_identity &&
245 (pud->pud_gid != ucred->uc_identity->mi_gid)));
247 /* check permission of setuid */
248 if (setuid && !(perm & CFS_SETUID_PERM)) {
249 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
250 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
251 GOTO(out, rc = -EACCES);
254 /* check permission of setgid */
255 if (setgid && !(perm & CFS_SETGID_PERM)) {
256 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
257 "from %s\n", pud->pud_uid, pud->pud_gid,
258 pud->pud_fsuid, pud->pud_fsgid,
259 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
260 GOTO(out, rc = -EACCES);
264 * NB: remote client not allowed to setgroups anyway.
266 if (!remote && perm & CFS_SETGRP_PERM) {
267 if (pud->pud_ngroups) {
268 /* setgroups for local client */
269 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
270 if (!ucred->uc_ginfo) {
271 CERROR("failed to alloc %d groups\n",
273 GOTO(out, rc = -ENOMEM);
276 lustre_groups_from_list(ucred->uc_ginfo,
278 lustre_groups_sort(ucred->uc_ginfo);
280 ucred->uc_ginfo = NULL;
283 ucred->uc_suppgids[0] = -1;
284 ucred->uc_suppgids[1] = -1;
285 ucred->uc_ginfo = NULL;
288 ucred->uc_uid = pud->pud_uid;
289 ucred->uc_gid = pud->pud_gid;
290 ucred->uc_fsuid = pud->pud_fsuid;
291 ucred->uc_fsgid = pud->pud_fsgid;
293 /* process root_squash here. */
294 mdt_root_squash(info, peernid);
296 /* remove fs privilege for non-root user. */
298 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
300 ucred->uc_cap = pud->pud_cap;
301 if (remote && !(perm & CFS_RMTOWN_PERM))
302 ucred->uc_cap &= ~(CFS_CAP_SYS_RESOURCE_MASK |
304 ucred->uc_valid = UCRED_NEW;
305 ucred_set_jobid(info, ucred);
311 if (ucred->uc_ginfo) {
312 put_group_info(ucred->uc_ginfo);
313 ucred->uc_ginfo = NULL;
315 if (ucred->uc_identity) {
316 mdt_identity_put(mdt->mdt_identity_cache,
318 ucred->uc_identity = NULL;
326 * Check whether allow the client to set supplementary group IDs or not.
328 * \param[in] info pointer to the thread context
329 * \param[in] uc pointer to the RPC user descriptor
331 * \retval true if allow to set supplementary group IDs
332 * \retval false for other cases
334 bool allow_client_chgrp(struct mdt_thread_info *info, struct lu_ucred *uc)
336 __u32 remote = exp_connect_rmtclient(info->mti_exp);
339 /* 1. If identity_upcall is disabled, then forbid remote client to set
340 * supplementary group IDs, but permit local client to do that. */
341 if (is_identity_get_disabled(info->mti_mdt->mdt_identity_cache)) {
348 /* 2. If fail to get related identities, then forbid any client to
349 * set supplementary group IDs. */
350 if (uc->uc_identity == NULL)
353 /* 3. Check the permission in the identities. */
354 perm = mdt_identity_get_perm(uc->uc_identity, remote,
355 mdt_info_req(info)->rq_peer.nid);
356 if (perm & CFS_SETGRP_PERM)
362 int mdt_check_ucred(struct mdt_thread_info *info)
364 struct ptlrpc_request *req = mdt_info_req(info);
365 struct mdt_device *mdt = info->mti_mdt;
366 struct ptlrpc_user_desc *pud = req->rq_user_desc;
367 struct lu_ucred *ucred = mdt_ucred(info);
368 struct md_identity *identity = NULL;
369 lnet_nid_t peernid = req->rq_peer.nid;
371 __u32 remote = exp_connect_rmtclient(info->mti_exp);
378 LASSERT(ucred != NULL);
379 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
382 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
385 /* sanity check: if we use strong authentication, we expect the
386 * uid which client claimed is true */
388 if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_mapped_uid))) {
389 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
393 if (ptlrpc_user_desc_do_idmap(req, pud))
396 if (req->rq_auth_mapped_uid != pud->pud_uid) {
397 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
398 "while client claims %u:%u/%u:%u\n",
399 libcfs_nid2str(peernid), req->rq_auth_uid,
400 req->rq_auth_mapped_uid,
401 pud->pud_uid, pud->pud_gid,
402 pud->pud_fsuid, pud->pud_fsgid);
406 if (req->rq_auth_uid != pud->pud_uid) {
407 CDEBUG(D_SEC, "local client %s: auth uid %u "
408 "while client claims %u:%u/%u:%u\n",
409 libcfs_nid2str(peernid), req->rq_auth_uid,
410 pud->pud_uid, pud->pud_gid,
411 pud->pud_fsuid, pud->pud_fsgid);
416 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
418 CDEBUG(D_SEC, "remote client must run with identity_get "
425 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
426 if (IS_ERR(identity)) {
427 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
431 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
437 perm = mdt_identity_get_perm(identity, remote, peernid);
438 /* find out the setuid/setgid attempt */
439 setuid = (pud->pud_uid != pud->pud_fsuid);
440 setgid = (pud->pud_gid != pud->pud_fsgid ||
441 pud->pud_gid != identity->mi_gid);
443 /* check permission of setuid */
444 if (setuid && !(perm & CFS_SETUID_PERM)) {
445 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
446 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
447 GOTO(out, rc = -EACCES);
450 /* check permission of setgid */
451 if (setgid && !(perm & CFS_SETGID_PERM)) {
452 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
453 "from %s\n", pud->pud_uid, pud->pud_gid,
454 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
455 libcfs_nid2str(peernid));
456 GOTO(out, rc = -EACCES);
462 mdt_identity_put(mdt->mdt_identity_cache, identity);
466 static void mdt_squash_nodemap_id(struct lu_ucred *ucred,
467 struct lu_nodemap *nodemap)
469 if (ucred->uc_o_uid == nodemap->nm_squash_uid) {
470 ucred->uc_fsuid = nodemap->nm_squash_uid;
471 ucred->uc_fsgid = nodemap->nm_squash_gid;
473 ucred->uc_suppgids[0] = -1;
474 ucred->uc_suppgids[1] = -1;
479 static int old_init_ucred(struct mdt_thread_info *info,
480 struct mdt_body *body)
482 struct lu_ucred *uc = mdt_ucred(info);
483 struct mdt_device *mdt = info->mti_mdt;
484 struct md_identity *identity = NULL;
485 struct lu_nodemap *nodemap =
486 info->mti_exp->exp_target_data.ted_nodemap;
489 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
490 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
491 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
492 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
493 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
494 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
495 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
496 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
499 uc->uc_valid = UCRED_INVALID;
500 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
501 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
502 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
503 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
504 uc->uc_suppgids[0] = body->mbo_suppgid;
505 uc->uc_suppgids[1] = -1;
507 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
508 identity = mdt_identity_get(mdt->mdt_identity_cache,
510 if (IS_ERR(identity)) {
511 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
514 CDEBUG(D_SEC, "Deny access without identity: "
515 "uid %u\n", uc->uc_fsuid);
520 uc->uc_identity = identity;
522 mdt_squash_nodemap_id(uc, nodemap);
524 /* process root_squash here. */
525 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
527 /* remove fs privilege for non-root user. */
529 uc->uc_cap = body->mbo_capability & ~CFS_CAP_FS_MASK;
531 uc->uc_cap = body->mbo_capability;
532 uc->uc_valid = UCRED_OLD;
533 ucred_set_jobid(info, uc);
538 static int old_init_ucred_reint(struct mdt_thread_info *info)
540 struct lu_ucred *uc = mdt_ucred(info);
541 struct mdt_device *mdt = info->mti_mdt;
542 struct md_identity *identity = NULL;
543 struct lu_nodemap *nodemap =
544 info->mti_exp->exp_target_data.ted_nodemap;
549 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
550 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
551 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
552 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
554 uc->uc_valid = UCRED_INVALID;
555 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
556 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
559 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
560 identity = mdt_identity_get(mdt->mdt_identity_cache,
562 if (IS_ERR(identity)) {
563 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
566 CDEBUG(D_SEC, "Deny access without identity: "
567 "uid %u\n", uc->uc_fsuid);
572 uc->uc_identity = identity;
574 /* process root_squash here. */
575 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
577 /* remove fs privilege for non-root user. */
579 uc->uc_cap &= ~CFS_CAP_FS_MASK;
580 uc->uc_valid = UCRED_OLD;
581 ucred_set_jobid(info, uc);
586 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
588 struct ptlrpc_request *req = mdt_info_req(info);
589 struct lu_ucred *uc = mdt_ucred(info);
592 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
595 mdt_exit_ucred(info);
597 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
598 return old_init_ucred(info, body);
600 return new_init_ucred(info, BODY_INIT, body);
603 int mdt_init_ucred_reint(struct mdt_thread_info *info)
605 struct ptlrpc_request *req = mdt_info_req(info);
606 struct lu_ucred *uc = mdt_ucred(info);
609 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
612 mdt_exit_ucred(info);
614 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
615 return old_init_ucred_reint(info);
617 return new_init_ucred(info, REC_INIT, NULL);
620 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
621 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
623 const struct lov_ost_data_v1 *lod;
627 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
630 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
632 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
633 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
634 le32_to_cpu(lmm->lmm_pattern));
635 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
636 le32_to_cpu(lmm->lmm_stripe_size), count);
638 /* If it's a directory or a released file, then there are
639 * no actual objects to print, so bail out. */
640 if (valid & OBD_MD_FLDIREA ||
641 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
644 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
645 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
648 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
649 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
650 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
654 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
656 const struct lmv_mds_md_v1 *lmm1;
659 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
662 lmm1 = &lmv->lmv_md_v1;
663 CDEBUG(level, "magic 0x%08X, master %#X stripe_count %#x\n",
664 le32_to_cpu(lmm1->lmv_magic),
665 le32_to_cpu(lmm1->lmv_master_mdt_index),
666 le32_to_cpu(lmm1->lmv_stripe_count));
668 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
671 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
674 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
675 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
679 /* Shrink and/or grow reply buffers */
680 int mdt_fix_reply(struct mdt_thread_info *info)
682 struct req_capsule *pill = info->mti_pill;
683 struct mdt_body *body;
684 int md_size, md_packed = 0;
689 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
690 LASSERT(body != NULL);
692 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
694 md_size = body->mbo_eadatasize;
698 acl_size = body->mbo_aclsize;
700 /* this replay - not send info to client */
701 if (info->mti_spec.no_create) {
706 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
711 &RMF_ACL, or &RMF_LOGCOOKIES
712 (optional) &RMF_CAPA1,
713 (optional) &RMF_CAPA2,
714 (optional) something else
717 /* MDT_MD buffer may be bigger than packed value, let's shrink all
718 * buffers before growing it */
719 if (info->mti_big_lmm_used) {
720 /* big_lmm buffer may be used even without packing the result
721 * into reply, just for internal server needs */
722 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
723 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
726 /* free big lmm if md_size is not needed */
727 if (md_size == 0 || md_packed == 0) {
728 info->mti_big_lmm_used = 0;
730 /* buffer must be allocated separately */
731 LASSERT(info->mti_attr.ma_lmm !=
732 req_capsule_server_get(pill, &RMF_MDT_MD));
733 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
735 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
736 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
739 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
740 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
741 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
742 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
743 acl_size, RCL_SERVER);
745 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
746 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
747 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
749 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
750 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
751 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
754 * Some more field should be shrinked if needed.
755 * This should be done by those who added fields to reply message.
758 /* Grow MD buffer if needed finally */
759 if (info->mti_big_lmm_used) {
762 LASSERT(md_size > md_packed);
763 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
764 md_size - md_packed);
765 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
767 /* we can't answer with proper LOV EA, drop flags,
768 * the rc is also returned so this request is
769 * considered as failed */
770 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
771 /* don't return transno along with error */
772 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
774 /* now we need to pack right LOV/LMV EA */
775 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
776 if (info->mti_attr.ma_valid & MA_LOV) {
777 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
779 info->mti_attr.ma_lmm_size);
780 memcpy(lmm, info->mti_attr.ma_lmm,
781 info->mti_attr.ma_lmm_size);
782 } else if (info->mti_attr.ma_valid & MA_LMV) {
783 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
785 info->mti_attr.ma_lmv_size);
786 memcpy(lmm, info->mti_attr.ma_lmv,
787 info->mti_attr.ma_lmv_size);
790 /* update mdt_max_mdsize so clients will be aware about that */
791 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
792 info->mti_mdt->mdt_max_mdsize =
793 info->mti_attr.ma_lmm_size;
794 info->mti_big_lmm_used = 0;
800 /* if object is dying, pack the lov/llog data,
801 * parameter info->mti_attr should be valid at this point! */
802 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
803 const struct md_attr *ma)
805 struct mdt_body *repbody;
806 const struct lu_attr *la = &ma->ma_attr;
809 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
810 LASSERT(repbody != NULL);
812 if (ma->ma_valid & MA_INODE)
813 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
815 if (ma->ma_valid & MA_LOV) {
816 CERROR("No need in LOV EA upon unlink\n");
819 repbody->mbo_eadatasize = 0;
824 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
830 if (in & MDS_ATTR_MODE)
832 if (in & MDS_ATTR_UID)
834 if (in & MDS_ATTR_GID)
836 if (in & MDS_ATTR_SIZE)
838 if (in & MDS_ATTR_BLOCKS)
840 if (in & MDS_ATTR_ATIME_SET)
842 if (in & MDS_ATTR_CTIME_SET)
844 if (in & MDS_ATTR_MTIME_SET)
846 if (in & MDS_ATTR_ATTR_FLAG)
848 if (in & MDS_ATTR_KILL_SUID)
850 if (in & MDS_ATTR_KILL_SGID)
853 if (in & MDS_ATTR_FROM_OPEN)
854 rr->rr_flags |= MRF_OPEN_TRUNC;
855 if (in & MDS_OPEN_OWNEROVERRIDE)
856 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
857 if (in & MDS_ATTR_FORCE)
858 ma->ma_attr_flags |= MDS_PERM_BYPASS;
860 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID |
861 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
862 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
863 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
864 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
865 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
867 CERROR("Unknown attr bits: "LPX64"\n", in);
873 int mdt_name_unpack(struct req_capsule *pill,
874 const struct req_msg_field *field,
876 enum mdt_name_flags flags)
878 ln->ln_name = req_capsule_client_get(pill, field);
879 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
881 if (!lu_name_is_valid(ln)) {
888 if ((flags & MNF_FIX_ANON) &&
889 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
890 /* Newer (3.x) kernels use a name of "/" for the
891 * "anonymous" disconnected dentries from NFS
892 * filehandle conversion. See d_obtain_alias(). */
900 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
902 struct lu_ucred *uc = mdt_ucred(info);
903 struct md_attr *ma = &info->mti_attr;
904 struct lu_attr *la = &ma->ma_attr;
905 struct req_capsule *pill = info->mti_pill;
906 struct mdt_reint_record *rr = &info->mti_rr;
907 struct mdt_rec_setattr *rec;
908 struct lu_nodemap *nodemap =
909 info->mti_exp->exp_target_data.ted_nodemap;
912 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
913 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
917 /* This prior initialization is needed for old_init_ucred_reint() */
918 uc->uc_fsuid = rec->sa_fsuid;
919 uc->uc_fsgid = rec->sa_fsgid;
920 uc->uc_cap = rec->sa_cap;
921 uc->uc_suppgids[0] = rec->sa_suppgid;
922 uc->uc_suppgids[1] = -1;
924 rr->rr_fid1 = &rec->sa_fid;
925 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
926 la->la_mode = rec->sa_mode;
927 la->la_flags = rec->sa_attr_flags;
928 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
929 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
930 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
931 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
932 la->la_size = rec->sa_size;
933 la->la_blocks = rec->sa_blocks;
934 la->la_ctime = rec->sa_ctime;
935 la->la_atime = rec->sa_atime;
936 la->la_mtime = rec->sa_mtime;
937 ma->ma_valid = MA_INODE;
939 if (rec->sa_bias & MDS_DATA_MODIFIED)
940 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
942 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
944 if (rec->sa_bias & MDS_HSM_RELEASE)
945 ma->ma_attr_flags |= MDS_HSM_RELEASE;
947 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
952 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
954 struct req_capsule *pill = info->mti_pill;
955 struct mdt_ioepoch *ioepoch;
958 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
959 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
966 info->mti_close_handle = ioepoch->mio_handle;
971 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
972 struct req_capsule *pill = info->mti_pill;
974 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
975 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
976 if (info->mti_dlm_req == NULL)
983 static int mdt_setattr_unpack(struct mdt_thread_info *info)
985 struct mdt_reint_record *rr = &info->mti_rr;
986 struct md_attr *ma = &info->mti_attr;
987 struct req_capsule *pill = info->mti_pill;
991 rc = mdt_setattr_unpack_rec(info);
995 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
996 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
997 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
999 if (rr->rr_eadatalen > 0) {
1000 const struct lmv_user_md *lum;
1002 lum = rr->rr_eadata;
1003 /* Sigh ma_valid(from req) does not indicate whether
1004 * it will set LOV/LMV EA, so we have to check magic */
1005 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1006 ma->ma_valid |= MA_LMV;
1007 ma->ma_lmv = (void *)rr->rr_eadata;
1008 ma->ma_lmv_size = rr->rr_eadatalen;
1010 ma->ma_valid |= MA_LOV;
1011 ma->ma_lmm = (void *)rr->rr_eadata;
1012 ma->ma_lmm_size = rr->rr_eadatalen;
1017 rc = mdt_dlmreq_unpack(info);
1021 static int mdt_hsm_release_unpack(struct mdt_thread_info *info)
1023 struct md_attr *ma = &info->mti_attr;
1024 struct req_capsule *pill = info->mti_pill;
1027 if (!(ma->ma_attr_flags & MDS_HSM_RELEASE))
1030 req_capsule_extend(pill, &RQF_MDS_RELEASE_CLOSE);
1032 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1033 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1039 int mdt_close_unpack(struct mdt_thread_info *info)
1044 rc = mdt_close_handle_unpack(info);
1048 rc = mdt_setattr_unpack_rec(info);
1052 rc = mdt_hsm_release_unpack(info);
1056 RETURN(mdt_init_ucred_reint(info));
1059 static int mdt_create_unpack(struct mdt_thread_info *info)
1061 struct lu_ucred *uc = mdt_ucred(info);
1062 struct mdt_rec_create *rec;
1063 struct lu_attr *attr = &info->mti_attr.ma_attr;
1064 struct mdt_reint_record *rr = &info->mti_rr;
1065 struct req_capsule *pill = info->mti_pill;
1066 struct md_op_spec *sp = &info->mti_spec;
1070 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1071 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1075 /* This prior initialization is needed for old_init_ucred_reint() */
1076 uc->uc_fsuid = rec->cr_fsuid;
1077 uc->uc_fsgid = rec->cr_fsgid;
1078 uc->uc_cap = rec->cr_cap;
1079 uc->uc_suppgids[0] = rec->cr_suppgid1;
1080 uc->uc_suppgids[1] = -1;
1081 uc->uc_umask = rec->cr_umask;
1083 rr->rr_fid1 = &rec->cr_fid1;
1084 rr->rr_fid2 = &rec->cr_fid2;
1085 attr->la_mode = rec->cr_mode;
1086 attr->la_rdev = rec->cr_rdev;
1087 attr->la_uid = rec->cr_fsuid;
1088 attr->la_gid = rec->cr_fsgid;
1089 attr->la_ctime = rec->cr_time;
1090 attr->la_mtime = rec->cr_time;
1091 attr->la_atime = rec->cr_time;
1092 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1093 LA_CTIME | LA_MTIME | LA_ATIME;
1094 memset(&sp->u, 0, sizeof(sp->u));
1095 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1097 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1101 if (S_ISLNK(attr->la_mode)) {
1102 const char *tgt = NULL;
1104 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1105 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1106 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1107 sp->u.sp_symname = tgt;
1112 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
1113 if (S_ISDIR(attr->la_mode) &&
1114 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1115 sp->u.sp_ea.eadata =
1116 req_capsule_client_get(pill, &RMF_EADATA);
1117 sp->u.sp_ea.eadatalen =
1118 req_capsule_get_size(pill, &RMF_EADATA,
1120 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1124 rc = mdt_dlmreq_unpack(info);
1128 static int mdt_link_unpack(struct mdt_thread_info *info)
1130 struct lu_ucred *uc = mdt_ucred(info);
1131 struct mdt_rec_link *rec;
1132 struct lu_attr *attr = &info->mti_attr.ma_attr;
1133 struct mdt_reint_record *rr = &info->mti_rr;
1134 struct req_capsule *pill = info->mti_pill;
1138 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1139 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1143 /* This prior initialization is needed for old_init_ucred_reint() */
1144 uc->uc_fsuid = rec->lk_fsuid;
1145 uc->uc_fsgid = rec->lk_fsgid;
1146 uc->uc_cap = rec->lk_cap;
1147 uc->uc_suppgids[0] = rec->lk_suppgid1;
1148 uc->uc_suppgids[1] = rec->lk_suppgid2;
1150 attr->la_uid = rec->lk_fsuid;
1151 attr->la_gid = rec->lk_fsgid;
1152 rr->rr_fid1 = &rec->lk_fid1;
1153 rr->rr_fid2 = &rec->lk_fid2;
1154 attr->la_ctime = rec->lk_time;
1155 attr->la_mtime = rec->lk_time;
1156 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1158 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1162 rc = mdt_dlmreq_unpack(info);
1167 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1169 struct lu_ucred *uc = mdt_ucred(info);
1170 struct mdt_rec_unlink *rec;
1171 struct md_attr *ma = &info->mti_attr;
1172 struct lu_attr *attr = &info->mti_attr.ma_attr;
1173 struct mdt_reint_record *rr = &info->mti_rr;
1174 struct req_capsule *pill = info->mti_pill;
1178 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1179 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1183 /* This prior initialization is needed for old_init_ucred_reint() */
1184 uc->uc_fsuid = rec->ul_fsuid;
1185 uc->uc_fsgid = rec->ul_fsgid;
1186 uc->uc_cap = rec->ul_cap;
1187 uc->uc_suppgids[0] = rec->ul_suppgid1;
1188 uc->uc_suppgids[1] = -1;
1190 attr->la_uid = rec->ul_fsuid;
1191 attr->la_gid = rec->ul_fsgid;
1192 rr->rr_fid1 = &rec->ul_fid1;
1193 rr->rr_fid2 = &rec->ul_fid2;
1194 attr->la_ctime = rec->ul_time;
1195 attr->la_mtime = rec->ul_time;
1196 attr->la_mode = rec->ul_mode;
1197 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1199 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1203 if (rec->ul_bias & MDS_VTX_BYPASS)
1204 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1206 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1208 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1210 rc = mdt_dlmreq_unpack(info);
1214 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1216 info->mti_spec.sp_rm_entry = 1;
1217 return mdt_unlink_unpack(info);
1220 static int mdt_rename_unpack(struct mdt_thread_info *info)
1222 struct lu_ucred *uc = mdt_ucred(info);
1223 struct mdt_rec_rename *rec;
1224 struct md_attr *ma = &info->mti_attr;
1225 struct lu_attr *attr = &info->mti_attr.ma_attr;
1226 struct mdt_reint_record *rr = &info->mti_rr;
1227 struct req_capsule *pill = info->mti_pill;
1231 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1232 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1236 /* This prior initialization is needed for old_init_ucred_reint() */
1237 uc->uc_fsuid = rec->rn_fsuid;
1238 uc->uc_fsgid = rec->rn_fsgid;
1239 uc->uc_cap = rec->rn_cap;
1240 uc->uc_suppgids[0] = rec->rn_suppgid1;
1241 uc->uc_suppgids[1] = rec->rn_suppgid2;
1243 attr->la_uid = rec->rn_fsuid;
1244 attr->la_gid = rec->rn_fsgid;
1245 rr->rr_fid1 = &rec->rn_fid1;
1246 rr->rr_fid2 = &rec->rn_fid2;
1247 attr->la_ctime = rec->rn_time;
1248 attr->la_mtime = rec->rn_time;
1249 /* rename_tgt contains the mode already */
1250 attr->la_mode = rec->rn_mode;
1251 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1253 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1257 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1261 if (rec->rn_bias & MDS_VTX_BYPASS)
1262 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1264 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1266 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1269 rc = mdt_dlmreq_unpack(info);
1275 * please see comment above LOV_MAGIC_V1_DEF
1277 static void mdt_fix_lov_magic(struct mdt_thread_info *info)
1279 struct mdt_reint_record *rr = &info->mti_rr;
1280 struct lov_user_md_v1 *v1;
1282 v1 = (void *)rr->rr_eadata;
1285 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1286 if (v1->lmm_magic == LOV_USER_MAGIC_V1) {
1287 v1->lmm_magic = LOV_MAGIC_V1_DEF;
1288 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
1289 v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF);
1290 } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
1291 v1->lmm_magic = LOV_MAGIC_V3_DEF;
1292 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
1293 v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF);
1298 static int mdt_open_unpack(struct mdt_thread_info *info)
1300 struct lu_ucred *uc = mdt_ucred(info);
1301 struct mdt_rec_create *rec;
1302 struct lu_attr *attr = &info->mti_attr.ma_attr;
1303 struct req_capsule *pill = info->mti_pill;
1304 struct mdt_reint_record *rr = &info->mti_rr;
1305 struct ptlrpc_request *req = mdt_info_req(info);
1306 struct md_op_spec *sp = &info->mti_spec;
1309 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1310 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1314 /* This prior initialization is needed for old_init_ucred_reint() */
1315 uc->uc_fsuid = rec->cr_fsuid;
1316 uc->uc_fsgid = rec->cr_fsgid;
1317 uc->uc_cap = rec->cr_cap;
1318 uc->uc_suppgids[0] = rec->cr_suppgid1;
1319 uc->uc_suppgids[1] = rec->cr_suppgid2;
1320 uc->uc_umask = rec->cr_umask;
1322 rr->rr_fid1 = &rec->cr_fid1;
1323 rr->rr_fid2 = &rec->cr_fid2;
1324 rr->rr_handle = &rec->cr_old_handle;
1325 attr->la_mode = rec->cr_mode;
1326 attr->la_rdev = rec->cr_rdev;
1327 attr->la_uid = rec->cr_fsuid;
1328 attr->la_gid = rec->cr_fsgid;
1329 attr->la_ctime = rec->cr_time;
1330 attr->la_mtime = rec->cr_time;
1331 attr->la_atime = rec->cr_time;
1332 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1333 LA_CTIME | LA_MTIME | LA_ATIME;
1334 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1335 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1336 /* Do not trigger ASSERTION if client miss to set such flags. */
1337 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1340 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1342 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1344 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1345 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1347 if (rr->rr_eadatalen > 0) {
1348 rr->rr_eadata = req_capsule_client_get(pill,
1350 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1351 sp->u.sp_ea.eadata = rr->rr_eadata;
1352 sp->no_create = !!req_is_replay(req);
1353 mdt_fix_lov_magic(info);
1357 * Client default md_size may be 0 right after client start,
1358 * until all osc are connected, set here just some reasonable
1359 * value to prevent misbehavior.
1361 if (rr->rr_eadatalen == 0 &&
1362 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1363 rr->rr_eadatalen = MIN_MD_SIZE;
1369 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1371 struct mdt_reint_record *rr = &info->mti_rr;
1372 struct lu_ucred *uc = mdt_ucred(info);
1373 struct lu_attr *attr = &info->mti_attr.ma_attr;
1374 struct req_capsule *pill = info->mti_pill;
1375 struct mdt_rec_setxattr *rec;
1380 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1381 sizeof(struct mdt_rec_reint));
1383 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1387 /* This prior initialization is needed for old_init_ucred_reint() */
1388 uc->uc_fsuid = rec->sx_fsuid;
1389 uc->uc_fsgid = rec->sx_fsgid;
1390 uc->uc_cap = rec->sx_cap;
1391 uc->uc_suppgids[0] = rec->sx_suppgid1;
1392 uc->uc_suppgids[1] = -1;
1394 rr->rr_opcode = rec->sx_opcode;
1395 rr->rr_fid1 = &rec->sx_fid;
1396 attr->la_valid = rec->sx_valid;
1397 attr->la_ctime = rec->sx_time;
1398 attr->la_size = rec->sx_size;
1399 attr->la_flags = rec->sx_flags;
1401 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1405 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1406 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1408 if (rr->rr_eadatalen > 0) {
1409 rr->rr_eadata = req_capsule_client_get(pill,
1411 if (rr->rr_eadata == NULL)
1414 rr->rr_eadata = NULL;
1416 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1417 CDEBUG(D_INFO, "no xattr data supplied\n");
1421 if (mdt_dlmreq_unpack(info) < 0)
1428 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1430 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1431 [REINT_SETATTR] = mdt_setattr_unpack,
1432 [REINT_CREATE] = mdt_create_unpack,
1433 [REINT_LINK] = mdt_link_unpack,
1434 [REINT_UNLINK] = mdt_unlink_unpack,
1435 [REINT_RENAME] = mdt_rename_unpack,
1436 [REINT_OPEN] = mdt_open_unpack,
1437 [REINT_SETXATTR] = mdt_setxattr_unpack,
1438 [REINT_RMENTRY] = mdt_rmentry_unpack,
1439 [REINT_MIGRATE] = mdt_rename_unpack,
1442 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1447 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1448 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1449 info->mti_rr.rr_opcode = op;
1450 rc = mdt_reint_unpackers[op](info);
1452 CERROR("Unexpected opcode %d\n", op);