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 "mdt_internal.h"
52 #include <lnet/nidstr.h>
53 #include <lustre_nodemap.h>
55 typedef enum ucred_init_type {
61 void mdt_exit_ucred(struct mdt_thread_info *info)
63 struct lu_ucred *uc = mdt_ucred(info);
64 struct mdt_device *mdt = info->mti_mdt;
67 if (uc->uc_valid != UCRED_INIT) {
68 uc->uc_suppgids[0] = uc->uc_suppgids[1] = -1;
70 put_group_info(uc->uc_ginfo);
73 if (uc->uc_identity) {
74 mdt_identity_put(mdt->mdt_identity_cache,
76 uc->uc_identity = NULL;
78 uc->uc_valid = UCRED_INIT;
82 static int match_nosquash_list(struct rw_semaphore *sem,
83 struct list_head *nidlist,
89 rc = cfs_match_nid(peernid, nidlist);
94 /* root_squash for inter-MDS operations */
95 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid)
97 struct lu_ucred *ucred = mdt_ucred(info);
98 struct root_squash_info *squash = &info->mti_mdt->mdt_squash;
101 LASSERT(ucred != NULL);
102 if (!squash->rsi_uid || ucred->uc_fsuid)
105 if (match_nosquash_list(&squash->rsi_sem,
106 &squash->rsi_nosquash_nids,
108 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
109 libcfs_nid2str(peernid));
113 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
114 libcfs_nid2str(peernid),
115 ucred->uc_fsuid, ucred->uc_fsgid, ucred->uc_cap,
116 squash->rsi_uid, squash->rsi_gid, 0);
118 ucred->uc_fsuid = squash->rsi_uid;
119 ucred->uc_fsgid = squash->rsi_gid;
121 ucred->uc_suppgids[0] = -1;
122 ucred->uc_suppgids[1] = -1;
127 static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc)
129 struct ptlrpc_request *req = mdt_info_req(info);
130 const char *jobid = mdt_req_get_jobid(req);
132 /* set jobid if specified. */
134 strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid));
136 uc->uc_jobid[0] = '\0';
139 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
142 struct ptlrpc_request *req = mdt_info_req(info);
143 struct mdt_device *mdt = info->mti_mdt;
144 struct ptlrpc_user_desc *pud = req->rq_user_desc;
145 struct lu_ucred *ucred = mdt_ucred(info);
146 lnet_nid_t peernid = req->rq_peer.nid;
148 __u32 remote = exp_connect_rmtclient(info->mti_exp);
155 LASSERT(req->rq_auth_gss);
156 LASSERT(!req->rq_auth_usr_mdt);
157 LASSERT(req->rq_user_desc);
158 LASSERT(ucred != NULL);
160 ucred->uc_valid = UCRED_INVALID;
162 ucred->uc_o_uid = pud->pud_uid;
163 ucred->uc_o_gid = pud->pud_gid;
164 ucred->uc_o_fsuid = pud->pud_fsuid;
165 ucred->uc_o_fsgid = pud->pud_fsgid;
167 if (type == BODY_INIT) {
168 struct mdt_body *body = (struct mdt_body *)buf;
170 ucred->uc_suppgids[0] = body->mbo_suppgid;
171 ucred->uc_suppgids[1] = -1;
174 /* sanity check: we expect the uid which client claimed is true */
176 if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_mapped_uid))) {
177 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
181 if (ptlrpc_user_desc_do_idmap(req, pud))
184 if (req->rq_auth_mapped_uid != pud->pud_uid) {
185 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
186 "while client claims %u:%u/%u:%u\n",
187 libcfs_nid2str(peernid), req->rq_auth_uid,
188 req->rq_auth_mapped_uid,
189 pud->pud_uid, pud->pud_gid,
190 pud->pud_fsuid, pud->pud_fsgid);
194 if (req->rq_auth_uid != pud->pud_uid) {
195 CDEBUG(D_SEC, "local client %s: auth uid %u "
196 "while client claims %u:%u/%u:%u\n",
197 libcfs_nid2str(peernid), req->rq_auth_uid,
198 pud->pud_uid, pud->pud_gid,
199 pud->pud_fsuid, pud->pud_fsgid);
204 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
206 CDEBUG(D_SEC, "remote client must run with identity_get "
210 ucred->uc_identity = NULL;
211 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
215 struct md_identity *identity;
217 identity = mdt_identity_get(mdt->mdt_identity_cache,
219 if (IS_ERR(identity)) {
220 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
222 ucred->uc_identity = NULL;
223 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
226 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
231 ucred->uc_identity = identity;
232 perm = mdt_identity_get_perm(ucred->uc_identity,
237 /* find out the setuid/setgid attempt */
238 setuid = (pud->pud_uid != pud->pud_fsuid);
239 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
240 (ucred->uc_identity &&
241 (pud->pud_gid != ucred->uc_identity->mi_gid)));
243 /* check permission of setuid */
244 if (setuid && !(perm & CFS_SETUID_PERM)) {
245 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
246 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
247 GOTO(out, rc = -EACCES);
250 /* check permission of setgid */
251 if (setgid && !(perm & CFS_SETGID_PERM)) {
252 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
253 "from %s\n", pud->pud_uid, pud->pud_gid,
254 pud->pud_fsuid, pud->pud_fsgid,
255 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
256 GOTO(out, rc = -EACCES);
260 * NB: remote client not allowed to setgroups anyway.
262 if (!remote && perm & CFS_SETGRP_PERM) {
263 if (pud->pud_ngroups) {
264 /* setgroups for local client */
265 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
266 if (!ucred->uc_ginfo) {
267 CERROR("failed to alloc %d groups\n",
269 GOTO(out, rc = -ENOMEM);
272 lustre_groups_from_list(ucred->uc_ginfo,
274 lustre_groups_sort(ucred->uc_ginfo);
276 ucred->uc_ginfo = NULL;
279 ucred->uc_suppgids[0] = -1;
280 ucred->uc_suppgids[1] = -1;
281 ucred->uc_ginfo = NULL;
284 ucred->uc_uid = pud->pud_uid;
285 ucred->uc_gid = pud->pud_gid;
286 ucred->uc_fsuid = pud->pud_fsuid;
287 ucred->uc_fsgid = pud->pud_fsgid;
289 /* process root_squash here. */
290 mdt_root_squash(info, peernid);
292 /* remove fs privilege for non-root user. */
294 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
296 ucred->uc_cap = pud->pud_cap;
297 if (remote && !(perm & CFS_RMTOWN_PERM))
298 ucred->uc_cap &= ~(CFS_CAP_SYS_RESOURCE_MASK |
300 ucred->uc_valid = UCRED_NEW;
301 ucred_set_jobid(info, ucred);
307 if (ucred->uc_ginfo) {
308 put_group_info(ucred->uc_ginfo);
309 ucred->uc_ginfo = NULL;
311 if (ucred->uc_identity) {
312 mdt_identity_put(mdt->mdt_identity_cache,
314 ucred->uc_identity = NULL;
322 * Check whether allow the client to set supplementary group IDs or not.
324 * \param[in] info pointer to the thread context
325 * \param[in] uc pointer to the RPC user descriptor
327 * \retval true if allow to set supplementary group IDs
328 * \retval false for other cases
330 bool allow_client_chgrp(struct mdt_thread_info *info, struct lu_ucred *uc)
332 __u32 remote = exp_connect_rmtclient(info->mti_exp);
335 /* 1. If identity_upcall is disabled, then forbid remote client to set
336 * supplementary group IDs, but permit local client to do that. */
337 if (is_identity_get_disabled(info->mti_mdt->mdt_identity_cache)) {
344 /* 2. If fail to get related identities, then forbid any client to
345 * set supplementary group IDs. */
346 if (uc->uc_identity == NULL)
349 /* 3. Check the permission in the identities. */
350 perm = mdt_identity_get_perm(uc->uc_identity, remote,
351 mdt_info_req(info)->rq_peer.nid);
352 if (perm & CFS_SETGRP_PERM)
358 int mdt_check_ucred(struct mdt_thread_info *info)
360 struct ptlrpc_request *req = mdt_info_req(info);
361 struct mdt_device *mdt = info->mti_mdt;
362 struct ptlrpc_user_desc *pud = req->rq_user_desc;
363 struct lu_ucred *ucred = mdt_ucred(info);
364 struct md_identity *identity = NULL;
365 lnet_nid_t peernid = req->rq_peer.nid;
367 __u32 remote = exp_connect_rmtclient(info->mti_exp);
374 LASSERT(ucred != NULL);
375 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
378 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
381 /* sanity check: if we use strong authentication, we expect the
382 * uid which client claimed is true */
384 if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_mapped_uid))) {
385 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
389 if (ptlrpc_user_desc_do_idmap(req, pud))
392 if (req->rq_auth_mapped_uid != pud->pud_uid) {
393 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
394 "while client claims %u:%u/%u:%u\n",
395 libcfs_nid2str(peernid), req->rq_auth_uid,
396 req->rq_auth_mapped_uid,
397 pud->pud_uid, pud->pud_gid,
398 pud->pud_fsuid, pud->pud_fsgid);
402 if (req->rq_auth_uid != pud->pud_uid) {
403 CDEBUG(D_SEC, "local client %s: auth uid %u "
404 "while client claims %u:%u/%u:%u\n",
405 libcfs_nid2str(peernid), req->rq_auth_uid,
406 pud->pud_uid, pud->pud_gid,
407 pud->pud_fsuid, pud->pud_fsgid);
412 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
414 CDEBUG(D_SEC, "remote client must run with identity_get "
421 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
422 if (IS_ERR(identity)) {
423 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
427 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
433 perm = mdt_identity_get_perm(identity, remote, peernid);
434 /* find out the setuid/setgid attempt */
435 setuid = (pud->pud_uid != pud->pud_fsuid);
436 setgid = (pud->pud_gid != pud->pud_fsgid ||
437 pud->pud_gid != identity->mi_gid);
439 /* check permission of setuid */
440 if (setuid && !(perm & CFS_SETUID_PERM)) {
441 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
442 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
443 GOTO(out, rc = -EACCES);
446 /* check permission of setgid */
447 if (setgid && !(perm & CFS_SETGID_PERM)) {
448 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
449 "from %s\n", pud->pud_uid, pud->pud_gid,
450 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
451 libcfs_nid2str(peernid));
452 GOTO(out, rc = -EACCES);
458 mdt_identity_put(mdt->mdt_identity_cache, identity);
462 static void mdt_squash_nodemap_id(struct lu_ucred *ucred,
463 struct lu_nodemap *nodemap)
465 if (ucred->uc_o_uid == nodemap->nm_squash_uid) {
466 ucred->uc_fsuid = nodemap->nm_squash_uid;
467 ucred->uc_fsgid = nodemap->nm_squash_gid;
469 ucred->uc_suppgids[0] = -1;
470 ucred->uc_suppgids[1] = -1;
475 static int old_init_ucred(struct mdt_thread_info *info,
476 struct mdt_body *body)
478 struct lu_ucred *uc = mdt_ucred(info);
479 struct mdt_device *mdt = info->mti_mdt;
480 struct md_identity *identity = NULL;
481 struct lu_nodemap *nodemap =
482 info->mti_exp->exp_target_data.ted_nodemap;
485 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
486 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
487 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
488 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
489 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
490 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
491 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
492 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
495 uc->uc_valid = UCRED_INVALID;
496 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
497 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
498 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
499 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
500 uc->uc_suppgids[0] = body->mbo_suppgid;
501 uc->uc_suppgids[1] = -1;
503 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
504 identity = mdt_identity_get(mdt->mdt_identity_cache,
506 if (IS_ERR(identity)) {
507 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
510 CDEBUG(D_SEC, "Deny access without identity: "
511 "uid %u\n", uc->uc_fsuid);
516 uc->uc_identity = identity;
518 mdt_squash_nodemap_id(uc, nodemap);
520 /* process root_squash here. */
521 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
523 /* remove fs privilege for non-root user. */
525 uc->uc_cap = body->mbo_capability & ~CFS_CAP_FS_MASK;
527 uc->uc_cap = body->mbo_capability;
528 uc->uc_valid = UCRED_OLD;
529 ucred_set_jobid(info, uc);
534 static int old_init_ucred_reint(struct mdt_thread_info *info)
536 struct lu_ucred *uc = mdt_ucred(info);
537 struct mdt_device *mdt = info->mti_mdt;
538 struct md_identity *identity = NULL;
539 struct lu_nodemap *nodemap =
540 info->mti_exp->exp_target_data.ted_nodemap;
545 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
546 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
547 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
548 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
550 uc->uc_valid = UCRED_INVALID;
551 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
552 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
555 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
556 identity = mdt_identity_get(mdt->mdt_identity_cache,
558 if (IS_ERR(identity)) {
559 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
562 CDEBUG(D_SEC, "Deny access without identity: "
563 "uid %u\n", uc->uc_fsuid);
568 uc->uc_identity = identity;
570 /* process root_squash here. */
571 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
573 /* remove fs privilege for non-root user. */
575 uc->uc_cap &= ~CFS_CAP_FS_MASK;
576 uc->uc_valid = UCRED_OLD;
577 ucred_set_jobid(info, uc);
582 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
584 struct ptlrpc_request *req = mdt_info_req(info);
585 struct lu_ucred *uc = mdt_ucred(info);
588 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
591 mdt_exit_ucred(info);
593 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
594 return old_init_ucred(info, body);
596 return new_init_ucred(info, BODY_INIT, body);
599 int mdt_init_ucred_reint(struct mdt_thread_info *info)
601 struct ptlrpc_request *req = mdt_info_req(info);
602 struct lu_ucred *uc = mdt_ucred(info);
605 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
608 mdt_exit_ucred(info);
610 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
611 return old_init_ucred_reint(info);
613 return new_init_ucred(info, REC_INIT, NULL);
616 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
617 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
619 const struct lov_ost_data_v1 *lod;
623 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
626 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
628 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
629 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
630 le32_to_cpu(lmm->lmm_pattern));
631 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
632 le32_to_cpu(lmm->lmm_stripe_size), count);
634 /* If it's a directory or a released file, then there are
635 * no actual objects to print, so bail out. */
636 if (valid & OBD_MD_FLDIREA ||
637 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
640 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
641 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
644 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
645 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
646 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
650 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
652 const struct lmv_mds_md_v1 *lmm1;
655 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
658 lmm1 = &lmv->lmv_md_v1;
659 CDEBUG(level, "magic 0x%08X, master %#X stripe_count %#x\n",
660 le32_to_cpu(lmm1->lmv_magic),
661 le32_to_cpu(lmm1->lmv_master_mdt_index),
662 le32_to_cpu(lmm1->lmv_stripe_count));
664 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
667 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
670 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
671 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
675 /* Shrink and/or grow reply buffers */
676 int mdt_fix_reply(struct mdt_thread_info *info)
678 struct req_capsule *pill = info->mti_pill;
679 struct mdt_body *body;
680 int md_size, md_packed = 0;
685 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
686 LASSERT(body != NULL);
688 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
690 md_size = body->mbo_eadatasize;
694 acl_size = body->mbo_aclsize;
696 /* this replay - not send info to client */
697 if (info->mti_spec.no_create) {
702 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d"
703 " MDSCAPA = %llx, OSSCAPA = %llx\n",
705 (unsigned long long)(body->mbo_valid & OBD_MD_FLMDSCAPA),
706 (unsigned long long)(body->mbo_valid & OBD_MD_FLOSSCAPA));
710 &RMF_ACL, or &RMF_LOGCOOKIES
711 (optional) &RMF_CAPA1,
712 (optional) &RMF_CAPA2,
713 (optional) something else
716 /* MDT_MD buffer may be bigger than packed value, let's shrink all
717 * buffers before growing it */
718 if (info->mti_big_lmm_used) {
719 /* big_lmm buffer may be used even without packing the result
720 * into reply, just for internal server needs */
721 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
722 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
725 /* free big lmm if md_size is not needed */
726 if (md_size == 0 || md_packed == 0) {
727 info->mti_big_lmm_used = 0;
729 /* buffer must be allocated separately */
730 LASSERT(info->mti_attr.ma_lmm !=
731 req_capsule_server_get(pill, &RMF_MDT_MD));
732 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
734 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
735 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
738 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
739 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
740 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
741 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
742 acl_size, RCL_SERVER);
744 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
745 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
746 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
748 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
749 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
750 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
753 * Some more field should be shrinked if needed.
754 * This should be done by those who added fields to reply message.
757 /* Grow MD buffer if needed finally */
758 if (info->mti_big_lmm_used) {
761 LASSERT(md_size > md_packed);
762 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
763 md_size - md_packed);
764 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
766 /* we can't answer with proper LOV EA, drop flags,
767 * the rc is also returned so this request is
768 * considered as failed */
769 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
770 /* don't return transno along with error */
771 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
773 /* now we need to pack right LOV/LMV EA */
774 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
775 if (info->mti_attr.ma_valid & MA_LOV) {
776 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
778 info->mti_attr.ma_lmm_size);
779 memcpy(lmm, info->mti_attr.ma_lmm,
780 info->mti_attr.ma_lmm_size);
781 } else if (info->mti_attr.ma_valid & MA_LMV) {
782 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
784 info->mti_attr.ma_lmv_size);
785 memcpy(lmm, info->mti_attr.ma_lmv,
786 info->mti_attr.ma_lmv_size);
789 /* update mdt_max_mdsize so clients will be aware about that */
790 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
791 info->mti_mdt->mdt_max_mdsize =
792 info->mti_attr.ma_lmm_size;
793 info->mti_big_lmm_used = 0;
799 /* if object is dying, pack the lov/llog data,
800 * parameter info->mti_attr should be valid at this point! */
801 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
802 const struct md_attr *ma)
804 struct mdt_body *repbody;
805 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;
821 if (info->mti_mdt->mdt_lut.lut_oss_capa &&
822 exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA &&
823 repbody->mbo_valid & OBD_MD_FLEASIZE) {
824 struct lustre_capa *capa;
826 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
828 capa->lc_opc = CAPA_OPC_OSS_DESTROY;
829 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0);
833 repbody->mbo_valid |= OBD_MD_FLOSSCAPA;
839 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
845 if (in & MDS_ATTR_MODE)
847 if (in & MDS_ATTR_UID)
849 if (in & MDS_ATTR_GID)
851 if (in & MDS_ATTR_SIZE)
853 if (in & MDS_ATTR_BLOCKS)
855 if (in & MDS_ATTR_ATIME_SET)
857 if (in & MDS_ATTR_CTIME_SET)
859 if (in & MDS_ATTR_MTIME_SET)
861 if (in & MDS_ATTR_ATTR_FLAG)
863 if (in & MDS_ATTR_KILL_SUID)
865 if (in & MDS_ATTR_KILL_SGID)
868 if (in & MDS_ATTR_FROM_OPEN)
869 rr->rr_flags |= MRF_OPEN_TRUNC;
870 if (in & MDS_OPEN_OWNEROVERRIDE)
871 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
872 if (in & MDS_ATTR_FORCE)
873 ma->ma_attr_flags |= MDS_PERM_BYPASS;
875 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID |
876 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
877 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
878 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
879 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
880 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
882 CERROR("Unknown attr bits: "LPX64"\n", in);
886 void mdt_set_capainfo(struct mdt_thread_info *info, int offset,
887 const struct lu_fid *fid, struct lustre_capa *capa)
889 struct lu_capainfo *lci;
891 LASSERT(offset >= 0 && offset < LU_CAPAINFO_MAX);
892 if (!info->mti_mdt->mdt_lut.lut_mds_capa ||
893 !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA))
896 lci = lu_capainfo_get(info->mti_env);
898 lci->lci_fid[offset] = *fid;
899 lci->lci_capa[offset] = capa;
903 void mdt_dump_capainfo(struct mdt_thread_info *info)
905 struct lu_capainfo *lci = lu_capainfo_get(info->mti_env);
911 for (i = 0; i < LU_CAPAINFO_MAX; i++) {
912 if (lci->lci_capa[i] == NULL) {
913 CERROR("no capa for index %d "DFID"\n",
914 i, PFID(&lci->lci_fid[i]));
917 if (lci->lci_capa[i] == BYPASS_CAPA) {
918 CERROR("bypass for index %d "DFID"\n",
919 i, PFID(&lci->lci_fid[i]));
922 DEBUG_CAPA(D_ERROR, lci->lci_capa[i], "index %d", i);
925 #endif /* DEBUG_CAPA */
929 int mdt_name_unpack(struct req_capsule *pill,
930 const struct req_msg_field *field,
932 enum mdt_name_flags flags)
934 ln->ln_name = req_capsule_client_get(pill, field);
935 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
937 if (!lu_name_is_valid(ln)) {
944 if ((flags & MNF_FIX_ANON) &&
945 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
946 /* Newer (3.x) kernels use a name of "/" for the
947 * "anonymous" disconnected dentries from NFS
948 * filehandle conversion. See d_obtain_alias(). */
956 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
958 struct lu_ucred *uc = mdt_ucred(info);
959 struct md_attr *ma = &info->mti_attr;
960 struct lu_attr *la = &ma->ma_attr;
961 struct req_capsule *pill = info->mti_pill;
962 struct mdt_reint_record *rr = &info->mti_rr;
963 struct mdt_rec_setattr *rec;
964 struct lu_nodemap *nodemap =
965 info->mti_exp->exp_target_data.ted_nodemap;
968 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
969 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
973 /* This prior initialization is needed for old_init_ucred_reint() */
974 uc->uc_fsuid = rec->sa_fsuid;
975 uc->uc_fsgid = rec->sa_fsgid;
976 uc->uc_cap = rec->sa_cap;
977 uc->uc_suppgids[0] = rec->sa_suppgid;
978 uc->uc_suppgids[1] = -1;
980 rr->rr_fid1 = &rec->sa_fid;
981 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
982 /* If MDS_ATTR_xTIME is set without MDS_ATTR_xTIME_SET and
983 * the client does not have OBD_CONNECT_FULL20, convert it
984 * to LA_xTIME. LU-3036 */
985 if (!(exp_connect_flags(info->mti_exp) & OBD_CONNECT_FULL20)) {
986 if (!(rec->sa_valid & MDS_ATTR_ATIME_SET) &&
987 (rec->sa_valid & MDS_ATTR_ATIME))
988 la->la_valid |= LA_ATIME;
989 if (!(rec->sa_valid & MDS_ATTR_MTIME_SET) &&
990 (rec->sa_valid & MDS_ATTR_MTIME))
991 la->la_valid |= LA_MTIME;
992 if (!(rec->sa_valid & MDS_ATTR_CTIME_SET) &&
993 (rec->sa_valid & MDS_ATTR_CTIME))
994 la->la_valid |= LA_CTIME;
996 la->la_mode = rec->sa_mode;
997 la->la_flags = rec->sa_attr_flags;
998 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
999 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
1000 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
1001 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
1002 la->la_size = rec->sa_size;
1003 la->la_blocks = rec->sa_blocks;
1004 la->la_ctime = rec->sa_ctime;
1005 la->la_atime = rec->sa_atime;
1006 la->la_mtime = rec->sa_mtime;
1007 ma->ma_valid = MA_INODE;
1009 if (rec->sa_bias & MDS_DATA_MODIFIED)
1010 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
1012 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
1014 if (rec->sa_bias & MDS_HSM_RELEASE)
1015 ma->ma_attr_flags |= MDS_HSM_RELEASE;
1017 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
1019 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1020 mdt_set_capainfo(info, 0, rr->rr_fid1,
1021 req_capsule_client_get(pill, &RMF_CAPA1));
1026 static int mdt_ioepoch_unpack(struct mdt_thread_info *info)
1028 struct req_capsule *pill = info->mti_pill;
1031 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
1033 req_capsule_client_get(pill, &RMF_MDT_EPOCH);
1035 info->mti_ioepoch = NULL;
1036 RETURN(info->mti_ioepoch == NULL ? -EFAULT : 0);
1039 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
1040 struct req_capsule *pill = info->mti_pill;
1042 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
1043 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
1044 if (info->mti_dlm_req == NULL)
1051 static int mdt_setattr_unpack(struct mdt_thread_info *info)
1053 struct mdt_reint_record *rr = &info->mti_rr;
1054 struct md_attr *ma = &info->mti_attr;
1055 struct req_capsule *pill = info->mti_pill;
1059 rc = mdt_setattr_unpack_rec(info);
1063 /* Epoch may be absent */
1064 mdt_ioepoch_unpack(info);
1066 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1067 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1068 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1070 if (rr->rr_eadatalen > 0) {
1071 const struct lmv_user_md *lum;
1073 lum = rr->rr_eadata;
1074 /* Sigh ma_valid(from req) does not indicate whether
1075 * it will set LOV/LMV EA, so we have to check magic */
1076 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1077 ma->ma_valid |= MA_LMV;
1078 ma->ma_lmv = (void *)rr->rr_eadata;
1079 ma->ma_lmv_size = rr->rr_eadatalen;
1081 ma->ma_valid |= MA_LOV;
1082 ma->ma_lmm = (void *)rr->rr_eadata;
1083 ma->ma_lmm_size = rr->rr_eadatalen;
1088 rc = mdt_dlmreq_unpack(info);
1092 static int mdt_hsm_release_unpack(struct mdt_thread_info *info)
1094 struct md_attr *ma = &info->mti_attr;
1095 struct req_capsule *pill = info->mti_pill;
1098 if (!(ma->ma_attr_flags & MDS_HSM_RELEASE))
1101 req_capsule_extend(pill, &RQF_MDS_RELEASE_CLOSE);
1103 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1104 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1110 int mdt_close_unpack(struct mdt_thread_info *info)
1115 rc = mdt_ioepoch_unpack(info);
1119 rc = mdt_setattr_unpack_rec(info);
1123 rc = mdt_hsm_release_unpack(info);
1127 RETURN(mdt_init_ucred_reint(info));
1130 static int mdt_create_unpack(struct mdt_thread_info *info)
1132 struct lu_ucred *uc = mdt_ucred(info);
1133 struct mdt_rec_create *rec;
1134 struct lu_attr *attr = &info->mti_attr.ma_attr;
1135 struct mdt_reint_record *rr = &info->mti_rr;
1136 struct req_capsule *pill = info->mti_pill;
1137 struct md_op_spec *sp = &info->mti_spec;
1141 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1142 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1146 /* This prior initialization is needed for old_init_ucred_reint() */
1147 uc->uc_fsuid = rec->cr_fsuid;
1148 uc->uc_fsgid = rec->cr_fsgid;
1149 uc->uc_cap = rec->cr_cap;
1150 uc->uc_suppgids[0] = rec->cr_suppgid1;
1151 uc->uc_suppgids[1] = -1;
1152 uc->uc_umask = rec->cr_umask;
1154 rr->rr_fid1 = &rec->cr_fid1;
1155 rr->rr_fid2 = &rec->cr_fid2;
1156 attr->la_mode = rec->cr_mode;
1157 attr->la_rdev = rec->cr_rdev;
1158 attr->la_uid = rec->cr_fsuid;
1159 attr->la_gid = rec->cr_fsgid;
1160 attr->la_ctime = rec->cr_time;
1161 attr->la_mtime = rec->cr_time;
1162 attr->la_atime = rec->cr_time;
1163 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1164 LA_CTIME | LA_MTIME | LA_ATIME;
1165 memset(&sp->u, 0, sizeof(sp->u));
1166 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1168 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1169 mdt_set_capainfo(info, 0, rr->rr_fid1,
1170 req_capsule_client_get(pill, &RMF_CAPA1));
1171 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1173 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1177 if (S_ISLNK(attr->la_mode)) {
1178 const char *tgt = NULL;
1180 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1181 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1182 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1183 sp->u.sp_symname = tgt;
1188 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
1189 if (S_ISDIR(attr->la_mode) &&
1190 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1191 sp->u.sp_ea.eadata =
1192 req_capsule_client_get(pill, &RMF_EADATA);
1193 sp->u.sp_ea.eadatalen =
1194 req_capsule_get_size(pill, &RMF_EADATA,
1196 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1200 rc = mdt_dlmreq_unpack(info);
1204 static int mdt_link_unpack(struct mdt_thread_info *info)
1206 struct lu_ucred *uc = mdt_ucred(info);
1207 struct mdt_rec_link *rec;
1208 struct lu_attr *attr = &info->mti_attr.ma_attr;
1209 struct mdt_reint_record *rr = &info->mti_rr;
1210 struct req_capsule *pill = info->mti_pill;
1214 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1215 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1219 /* This prior initialization is needed for old_init_ucred_reint() */
1220 uc->uc_fsuid = rec->lk_fsuid;
1221 uc->uc_fsgid = rec->lk_fsgid;
1222 uc->uc_cap = rec->lk_cap;
1223 uc->uc_suppgids[0] = rec->lk_suppgid1;
1224 uc->uc_suppgids[1] = rec->lk_suppgid2;
1226 attr->la_uid = rec->lk_fsuid;
1227 attr->la_gid = rec->lk_fsgid;
1228 rr->rr_fid1 = &rec->lk_fid1;
1229 rr->rr_fid2 = &rec->lk_fid2;
1230 attr->la_ctime = rec->lk_time;
1231 attr->la_mtime = rec->lk_time;
1232 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1234 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1235 mdt_set_capainfo(info, 0, rr->rr_fid1,
1236 req_capsule_client_get(pill, &RMF_CAPA1));
1237 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1238 mdt_set_capainfo(info, 1, rr->rr_fid2,
1239 req_capsule_client_get(pill, &RMF_CAPA2));
1241 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1245 rc = mdt_dlmreq_unpack(info);
1250 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1252 struct lu_ucred *uc = mdt_ucred(info);
1253 struct mdt_rec_unlink *rec;
1254 struct md_attr *ma = &info->mti_attr;
1255 struct lu_attr *attr = &info->mti_attr.ma_attr;
1256 struct mdt_reint_record *rr = &info->mti_rr;
1257 struct req_capsule *pill = info->mti_pill;
1261 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1262 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1266 /* This prior initialization is needed for old_init_ucred_reint() */
1267 uc->uc_fsuid = rec->ul_fsuid;
1268 uc->uc_fsgid = rec->ul_fsgid;
1269 uc->uc_cap = rec->ul_cap;
1270 uc->uc_suppgids[0] = rec->ul_suppgid1;
1271 uc->uc_suppgids[1] = -1;
1273 attr->la_uid = rec->ul_fsuid;
1274 attr->la_gid = rec->ul_fsgid;
1275 rr->rr_fid1 = &rec->ul_fid1;
1276 rr->rr_fid2 = &rec->ul_fid2;
1277 attr->la_ctime = rec->ul_time;
1278 attr->la_mtime = rec->ul_time;
1279 attr->la_mode = rec->ul_mode;
1280 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1282 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1283 mdt_set_capainfo(info, 0, rr->rr_fid1,
1284 req_capsule_client_get(pill, &RMF_CAPA1));
1286 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1290 if (rec->ul_bias & MDS_VTX_BYPASS)
1291 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1293 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1295 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1297 rc = mdt_dlmreq_unpack(info);
1301 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1303 info->mti_spec.sp_rm_entry = 1;
1304 return mdt_unlink_unpack(info);
1307 static int mdt_rename_unpack(struct mdt_thread_info *info)
1309 struct lu_ucred *uc = mdt_ucred(info);
1310 struct mdt_rec_rename *rec;
1311 struct md_attr *ma = &info->mti_attr;
1312 struct lu_attr *attr = &info->mti_attr.ma_attr;
1313 struct mdt_reint_record *rr = &info->mti_rr;
1314 struct req_capsule *pill = info->mti_pill;
1318 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1319 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1323 /* This prior initialization is needed for old_init_ucred_reint() */
1324 uc->uc_fsuid = rec->rn_fsuid;
1325 uc->uc_fsgid = rec->rn_fsgid;
1326 uc->uc_cap = rec->rn_cap;
1327 uc->uc_suppgids[0] = rec->rn_suppgid1;
1328 uc->uc_suppgids[1] = rec->rn_suppgid2;
1330 attr->la_uid = rec->rn_fsuid;
1331 attr->la_gid = rec->rn_fsgid;
1332 rr->rr_fid1 = &rec->rn_fid1;
1333 rr->rr_fid2 = &rec->rn_fid2;
1334 attr->la_ctime = rec->rn_time;
1335 attr->la_mtime = rec->rn_time;
1336 /* rename_tgt contains the mode already */
1337 attr->la_mode = rec->rn_mode;
1338 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1340 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1341 mdt_set_capainfo(info, 0, rr->rr_fid1,
1342 req_capsule_client_get(pill, &RMF_CAPA1));
1343 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1344 mdt_set_capainfo(info, 1, rr->rr_fid2,
1345 req_capsule_client_get(pill, &RMF_CAPA2));
1347 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1351 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1355 if (rec->rn_bias & MDS_VTX_BYPASS)
1356 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1358 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1360 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1363 rc = mdt_dlmreq_unpack(info);
1369 * please see comment above LOV_MAGIC_V1_DEF
1371 static void mdt_fix_lov_magic(struct mdt_thread_info *info)
1373 struct mdt_reint_record *rr = &info->mti_rr;
1374 struct lov_user_md_v1 *v1;
1376 v1 = (void *)rr->rr_eadata;
1379 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1380 if (v1->lmm_magic == LOV_USER_MAGIC_V1) {
1381 v1->lmm_magic = LOV_MAGIC_V1_DEF;
1382 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
1383 v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF);
1384 } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
1385 v1->lmm_magic = LOV_MAGIC_V3_DEF;
1386 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
1387 v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF);
1392 static int mdt_open_unpack(struct mdt_thread_info *info)
1394 struct lu_ucred *uc = mdt_ucred(info);
1395 struct mdt_rec_create *rec;
1396 struct lu_attr *attr = &info->mti_attr.ma_attr;
1397 struct req_capsule *pill = info->mti_pill;
1398 struct mdt_reint_record *rr = &info->mti_rr;
1399 struct ptlrpc_request *req = mdt_info_req(info);
1400 struct md_op_spec *sp = &info->mti_spec;
1403 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1404 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1408 /* This prior initialization is needed for old_init_ucred_reint() */
1409 uc->uc_fsuid = rec->cr_fsuid;
1410 uc->uc_fsgid = rec->cr_fsgid;
1411 uc->uc_cap = rec->cr_cap;
1412 uc->uc_suppgids[0] = rec->cr_suppgid1;
1413 uc->uc_suppgids[1] = rec->cr_suppgid2;
1414 uc->uc_umask = rec->cr_umask;
1416 rr->rr_fid1 = &rec->cr_fid1;
1417 rr->rr_fid2 = &rec->cr_fid2;
1418 rr->rr_handle = &rec->cr_old_handle;
1419 attr->la_mode = rec->cr_mode;
1420 attr->la_rdev = rec->cr_rdev;
1421 attr->la_uid = rec->cr_fsuid;
1422 attr->la_gid = rec->cr_fsgid;
1423 attr->la_ctime = rec->cr_time;
1424 attr->la_mtime = rec->cr_time;
1425 attr->la_atime = rec->cr_time;
1426 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1427 LA_CTIME | LA_MTIME | LA_ATIME;
1428 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1429 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1430 /* Do not trigger ASSERTION if client miss to set such flags. */
1431 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1433 info->mti_replayepoch = rec->cr_ioepoch;
1435 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1437 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1438 mdt_set_capainfo(info, 0, rr->rr_fid1,
1439 req_capsule_client_get(pill, &RMF_CAPA1));
1440 if (req_is_replay(req) &&
1441 req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) {
1443 mdt_set_capainfo(info, 1, rr->rr_fid2,
1444 req_capsule_client_get(pill, &RMF_CAPA2));
1447 * FIXME: capa in replay open request might have expired,
1448 * bypass capa check. Security hole?
1450 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1451 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1455 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1457 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1458 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1460 if (rr->rr_eadatalen > 0) {
1461 rr->rr_eadata = req_capsule_client_get(pill,
1463 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1464 sp->u.sp_ea.eadata = rr->rr_eadata;
1465 sp->no_create = !!req_is_replay(req);
1466 mdt_fix_lov_magic(info);
1470 * Client default md_size may be 0 right after client start,
1471 * until all osc are connected, set here just some reasonable
1472 * value to prevent misbehavior.
1474 if (rr->rr_eadatalen == 0 &&
1475 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1476 rr->rr_eadatalen = MIN_MD_SIZE;
1482 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1484 struct mdt_reint_record *rr = &info->mti_rr;
1485 struct lu_ucred *uc = mdt_ucred(info);
1486 struct lu_attr *attr = &info->mti_attr.ma_attr;
1487 struct req_capsule *pill = info->mti_pill;
1488 struct mdt_rec_setxattr *rec;
1493 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1494 sizeof(struct mdt_rec_reint));
1496 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1500 /* This prior initialization is needed for old_init_ucred_reint() */
1501 uc->uc_fsuid = rec->sx_fsuid;
1502 uc->uc_fsgid = rec->sx_fsgid;
1503 uc->uc_cap = rec->sx_cap;
1504 uc->uc_suppgids[0] = rec->sx_suppgid1;
1505 uc->uc_suppgids[1] = -1;
1507 rr->rr_opcode = rec->sx_opcode;
1508 rr->rr_fid1 = &rec->sx_fid;
1509 attr->la_valid = rec->sx_valid;
1510 attr->la_ctime = rec->sx_time;
1511 attr->la_size = rec->sx_size;
1512 attr->la_flags = rec->sx_flags;
1514 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1515 mdt_set_capainfo(info, 0, rr->rr_fid1,
1516 req_capsule_client_get(pill, &RMF_CAPA1));
1518 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1520 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1524 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1525 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1527 if (rr->rr_eadatalen > 0) {
1528 rr->rr_eadata = req_capsule_client_get(pill,
1530 if (rr->rr_eadata == NULL)
1533 rr->rr_eadata = NULL;
1535 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1536 CDEBUG(D_INFO, "no xattr data supplied\n");
1540 if (mdt_dlmreq_unpack(info) < 0)
1547 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1549 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1550 [REINT_SETATTR] = mdt_setattr_unpack,
1551 [REINT_CREATE] = mdt_create_unpack,
1552 [REINT_LINK] = mdt_link_unpack,
1553 [REINT_UNLINK] = mdt_unlink_unpack,
1554 [REINT_RENAME] = mdt_rename_unpack,
1555 [REINT_OPEN] = mdt_open_unpack,
1556 [REINT_SETXATTR] = mdt_setxattr_unpack,
1557 [REINT_RMENTRY] = mdt_rmentry_unpack,
1558 [REINT_MIGRATE] = mdt_rename_unpack,
1561 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1566 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1567 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1568 info->mti_rr.rr_opcode = op;
1569 rc = mdt_reint_unpackers[op](info);
1571 CERROR("Unexpected opcode %d\n", op);