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, 2013, 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/lib-lnet.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,
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 int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
130 struct ptlrpc_request *req = mdt_info_req(info);
131 struct mdt_device *mdt = info->mti_mdt;
132 struct ptlrpc_user_desc *pud = req->rq_user_desc;
133 struct lu_ucred *ucred = mdt_ucred(info);
134 lnet_nid_t peernid = req->rq_peer.nid;
136 __u32 remote = exp_connect_rmtclient(info->mti_exp);
143 LASSERT(req->rq_auth_gss);
144 LASSERT(!req->rq_auth_usr_mdt);
145 LASSERT(req->rq_user_desc);
146 LASSERT(ucred != NULL);
148 ucred->uc_valid = UCRED_INVALID;
150 ucred->uc_o_uid = pud->pud_uid;
151 ucred->uc_o_gid = pud->pud_gid;
152 ucred->uc_o_fsuid = pud->pud_fsuid;
153 ucred->uc_o_fsgid = pud->pud_fsgid;
155 if (type == BODY_INIT) {
156 struct mdt_body *body = (struct mdt_body *)buf;
158 ucred->uc_suppgids[0] = body->mbo_suppgid;
159 ucred->uc_suppgids[1] = -1;
162 /* sanity check: we expect the uid which client claimed is true */
164 if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_mapped_uid))) {
165 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
166 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
170 if (ptlrpc_user_desc_do_idmap(req, pud))
173 if (req->rq_auth_mapped_uid != pud->pud_uid) {
174 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
175 "while client claims %u:%u/%u:%u\n",
176 libcfs_nid2str(peernid), req->rq_auth_uid,
177 req->rq_auth_mapped_uid,
178 pud->pud_uid, pud->pud_gid,
179 pud->pud_fsuid, pud->pud_fsgid);
183 if (req->rq_auth_uid != pud->pud_uid) {
184 CDEBUG(D_SEC, "local client %s: auth uid %u "
185 "while client claims %u:%u/%u:%u\n",
186 libcfs_nid2str(peernid), req->rq_auth_uid,
187 pud->pud_uid, pud->pud_gid,
188 pud->pud_fsuid, pud->pud_fsgid);
193 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
195 CDEBUG(D_SEC, "remote client must run with identity_get "
199 ucred->uc_identity = NULL;
200 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
204 struct md_identity *identity;
206 identity = mdt_identity_get(mdt->mdt_identity_cache,
208 if (IS_ERR(identity)) {
209 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
211 ucred->uc_identity = NULL;
212 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
215 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
220 ucred->uc_identity = identity;
221 perm = mdt_identity_get_perm(ucred->uc_identity,
226 /* find out the setuid/setgid attempt */
227 setuid = (pud->pud_uid != pud->pud_fsuid);
228 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
229 (ucred->uc_identity &&
230 (pud->pud_gid != ucred->uc_identity->mi_gid)));
232 /* check permission of setuid */
233 if (setuid && !(perm & CFS_SETUID_PERM)) {
234 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
235 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
236 GOTO(out, rc = -EACCES);
239 /* check permission of setgid */
240 if (setgid && !(perm & CFS_SETGID_PERM)) {
241 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
242 "from %s\n", pud->pud_uid, pud->pud_gid,
243 pud->pud_fsuid, pud->pud_fsgid,
244 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
245 GOTO(out, rc = -EACCES);
249 * NB: remote client not allowed to setgroups anyway.
251 if (!remote && perm & CFS_SETGRP_PERM) {
252 if (pud->pud_ngroups) {
253 /* setgroups for local client */
254 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
255 if (!ucred->uc_ginfo) {
256 CERROR("failed to alloc %d groups\n",
258 GOTO(out, rc = -ENOMEM);
261 lustre_groups_from_list(ucred->uc_ginfo,
263 lustre_groups_sort(ucred->uc_ginfo);
265 ucred->uc_ginfo = NULL;
268 ucred->uc_suppgids[0] = -1;
269 ucred->uc_suppgids[1] = -1;
270 ucred->uc_ginfo = NULL;
273 ucred->uc_uid = pud->pud_uid;
274 ucred->uc_gid = pud->pud_gid;
275 ucred->uc_fsuid = pud->pud_fsuid;
276 ucred->uc_fsgid = pud->pud_fsgid;
278 /* process root_squash here. */
279 mdt_root_squash(info, peernid);
281 /* remove fs privilege for non-root user. */
283 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
285 ucred->uc_cap = pud->pud_cap;
286 if (remote && !(perm & CFS_RMTOWN_PERM))
287 ucred->uc_cap &= ~(CFS_CAP_SYS_RESOURCE_MASK |
289 ucred->uc_valid = UCRED_NEW;
295 if (ucred->uc_ginfo) {
296 put_group_info(ucred->uc_ginfo);
297 ucred->uc_ginfo = NULL;
299 if (ucred->uc_identity) {
300 mdt_identity_put(mdt->mdt_identity_cache,
302 ucred->uc_identity = NULL;
309 int mdt_check_ucred(struct mdt_thread_info *info)
311 struct ptlrpc_request *req = mdt_info_req(info);
312 struct mdt_device *mdt = info->mti_mdt;
313 struct ptlrpc_user_desc *pud = req->rq_user_desc;
314 struct lu_ucred *ucred = mdt_ucred(info);
315 struct md_identity *identity = NULL;
316 lnet_nid_t peernid = req->rq_peer.nid;
318 __u32 remote = exp_connect_rmtclient(info->mti_exp);
325 LASSERT(ucred != NULL);
326 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
329 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
332 /* sanity check: if we use strong authentication, we expect the
333 * uid which client claimed is true */
335 if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_mapped_uid))) {
336 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
340 if (ptlrpc_user_desc_do_idmap(req, pud))
343 if (req->rq_auth_mapped_uid != pud->pud_uid) {
344 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
345 "while client claims %u:%u/%u:%u\n",
346 libcfs_nid2str(peernid), req->rq_auth_uid,
347 req->rq_auth_mapped_uid,
348 pud->pud_uid, pud->pud_gid,
349 pud->pud_fsuid, pud->pud_fsgid);
353 if (req->rq_auth_uid != pud->pud_uid) {
354 CDEBUG(D_SEC, "local client %s: auth uid %u "
355 "while client claims %u:%u/%u:%u\n",
356 libcfs_nid2str(peernid), req->rq_auth_uid,
357 pud->pud_uid, pud->pud_gid,
358 pud->pud_fsuid, pud->pud_fsgid);
363 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
365 CDEBUG(D_SEC, "remote client must run with identity_get "
372 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
373 if (IS_ERR(identity)) {
374 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
378 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
384 perm = mdt_identity_get_perm(identity, remote, peernid);
385 /* find out the setuid/setgid attempt */
386 setuid = (pud->pud_uid != pud->pud_fsuid);
387 setgid = (pud->pud_gid != pud->pud_fsgid ||
388 pud->pud_gid != identity->mi_gid);
390 /* check permission of setuid */
391 if (setuid && !(perm & CFS_SETUID_PERM)) {
392 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
393 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
394 GOTO(out, rc = -EACCES);
397 /* check permission of setgid */
398 if (setgid && !(perm & CFS_SETGID_PERM)) {
399 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
400 "from %s\n", pud->pud_uid, pud->pud_gid,
401 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
402 libcfs_nid2str(peernid));
403 GOTO(out, rc = -EACCES);
409 mdt_identity_put(mdt->mdt_identity_cache, identity);
413 static int old_init_ucred(struct mdt_thread_info *info,
414 struct mdt_body *body)
416 struct lu_ucred *uc = mdt_ucred(info);
417 struct mdt_device *mdt = info->mti_mdt;
418 struct md_identity *identity = NULL;
423 uc->uc_valid = UCRED_INVALID;
424 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
425 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
426 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
427 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
428 uc->uc_suppgids[0] = body->mbo_suppgid;
429 uc->uc_suppgids[1] = -1;
431 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
432 identity = mdt_identity_get(mdt->mdt_identity_cache,
434 if (IS_ERR(identity)) {
435 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
438 CDEBUG(D_SEC, "Deny access without identity: "
439 "uid %u\n", uc->uc_fsuid);
444 uc->uc_identity = identity;
446 /* process root_squash here. */
447 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
449 /* remove fs privilege for non-root user. */
451 uc->uc_cap = body->mbo_capability & ~CFS_CAP_FS_MASK;
453 uc->uc_cap = body->mbo_capability;
454 uc->uc_valid = UCRED_OLD;
459 static int old_init_ucred_reint(struct mdt_thread_info *info)
461 struct lu_ucred *uc = mdt_ucred(info);
462 struct mdt_device *mdt = info->mti_mdt;
463 struct md_identity *identity = NULL;
468 uc->uc_valid = UCRED_INVALID;
469 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
470 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
472 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
473 identity = mdt_identity_get(mdt->mdt_identity_cache,
475 if (IS_ERR(identity)) {
476 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
479 CDEBUG(D_SEC, "Deny access without identity: "
480 "uid %u\n", uc->uc_fsuid);
485 uc->uc_identity = identity;
487 /* process root_squash here. */
488 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
490 /* remove fs privilege for non-root user. */
492 uc->uc_cap &= ~CFS_CAP_FS_MASK;
493 uc->uc_valid = UCRED_OLD;
498 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
500 struct ptlrpc_request *req = mdt_info_req(info);
501 struct lu_ucred *uc = mdt_ucred(info);
504 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
507 mdt_exit_ucred(info);
509 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
510 return old_init_ucred(info, body);
512 return new_init_ucred(info, BODY_INIT, body);
515 int mdt_init_ucred_reint(struct mdt_thread_info *info)
517 struct ptlrpc_request *req = mdt_info_req(info);
518 struct lu_ucred *uc = mdt_ucred(info);
521 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
524 mdt_exit_ucred(info);
526 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
527 return old_init_ucred_reint(info);
529 return new_init_ucred(info, REC_INIT, NULL);
532 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
533 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
535 const struct lov_ost_data_v1 *lod;
539 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
542 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
544 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
545 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
546 le32_to_cpu(lmm->lmm_pattern));
547 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
548 le32_to_cpu(lmm->lmm_stripe_size), count);
550 /* If it's a directory or a released file, then there are
551 * no actual objects to print, so bail out. */
552 if (valid & OBD_MD_FLDIREA ||
553 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
556 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
557 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
560 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
561 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
562 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
566 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
568 const struct lmv_mds_md_v1 *lmm1;
571 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
574 lmm1 = &lmv->lmv_md_v1;
575 CDEBUG(level, "magic 0x%08X, master %#X stripe_count %#x\n",
576 le32_to_cpu(lmm1->lmv_magic),
577 le32_to_cpu(lmm1->lmv_master_mdt_index),
578 le32_to_cpu(lmm1->lmv_stripe_count));
580 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
583 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
586 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
587 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
591 /* Shrink and/or grow reply buffers */
592 int mdt_fix_reply(struct mdt_thread_info *info)
594 struct req_capsule *pill = info->mti_pill;
595 struct mdt_body *body;
596 int md_size, md_packed = 0;
601 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
602 LASSERT(body != NULL);
604 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
606 md_size = body->mbo_eadatasize;
610 acl_size = body->mbo_aclsize;
612 /* this replay - not send info to client */
613 if (info->mti_spec.no_create) {
618 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d"
619 " MDSCAPA = %llx, OSSCAPA = %llx\n",
621 (unsigned long long)(body->mbo_valid & OBD_MD_FLMDSCAPA),
622 (unsigned long long)(body->mbo_valid & OBD_MD_FLOSSCAPA));
626 &RMF_ACL, or &RMF_LOGCOOKIES
627 (optional) &RMF_CAPA1,
628 (optional) &RMF_CAPA2,
629 (optional) something else
632 /* MDT_MD buffer may be bigger than packed value, let's shrink all
633 * buffers before growing it */
634 if (info->mti_big_lmm_used) {
635 /* big_lmm buffer may be used even without packing the result
636 * into reply, just for internal server needs */
637 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
638 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
641 /* free big lmm if md_size is not needed */
642 if (md_size == 0 || md_packed == 0) {
643 info->mti_big_lmm_used = 0;
645 /* buffer must be allocated separately */
646 LASSERT(info->mti_attr.ma_lmm !=
647 req_capsule_server_get(pill, &RMF_MDT_MD));
648 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
650 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
651 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
654 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
655 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
656 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
657 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
658 acl_size, RCL_SERVER);
660 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
661 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
662 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
664 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
665 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
666 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
669 * Some more field should be shrinked if needed.
670 * This should be done by those who added fields to reply message.
673 /* Grow MD buffer if needed finally */
674 if (info->mti_big_lmm_used) {
677 LASSERT(md_size > md_packed);
678 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
679 md_size - md_packed);
680 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
682 /* we can't answer with proper LOV EA, drop flags,
683 * the rc is also returned so this request is
684 * considered as failed */
685 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
686 /* don't return transno along with error */
687 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
689 /* now we need to pack right LOV/LMV EA */
690 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
691 if (info->mti_attr.ma_valid & MA_LOV) {
692 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
694 info->mti_attr.ma_lmm_size);
695 memcpy(lmm, info->mti_attr.ma_lmm,
696 info->mti_attr.ma_lmm_size);
697 } else if (info->mti_attr.ma_valid & MA_LMV) {
698 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
700 info->mti_attr.ma_lmv_size);
701 memcpy(lmm, info->mti_attr.ma_lmv,
702 info->mti_attr.ma_lmv_size);
705 /* update mdt_max_mdsize so clients will be aware about that */
706 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
707 info->mti_mdt->mdt_max_mdsize =
708 info->mti_attr.ma_lmm_size;
709 info->mti_big_lmm_used = 0;
715 /* if object is dying, pack the lov/llog data,
716 * parameter info->mti_attr should be valid at this point! */
717 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
718 const struct md_attr *ma)
720 struct mdt_body *repbody;
721 const struct lu_attr *la = &ma->ma_attr;
725 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
726 LASSERT(repbody != NULL);
728 if (ma->ma_valid & MA_INODE)
729 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
731 if (ma->ma_valid & MA_LOV) {
732 CERROR("No need in LOV EA upon unlink\n");
735 repbody->mbo_eadatasize = 0;
737 if (info->mti_mdt->mdt_lut.lut_oss_capa &&
738 exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA &&
739 repbody->mbo_valid & OBD_MD_FLEASIZE) {
740 struct lustre_capa *capa;
742 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
744 capa->lc_opc = CAPA_OPC_OSS_DESTROY;
745 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0);
749 repbody->mbo_valid |= OBD_MD_FLOSSCAPA;
755 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
761 if (in & MDS_ATTR_MODE)
763 if (in & MDS_ATTR_UID)
765 if (in & MDS_ATTR_GID)
767 if (in & MDS_ATTR_SIZE)
769 if (in & MDS_ATTR_BLOCKS)
771 if (in & MDS_ATTR_ATIME_SET)
773 if (in & MDS_ATTR_CTIME_SET)
775 if (in & MDS_ATTR_MTIME_SET)
777 if (in & MDS_ATTR_ATTR_FLAG)
779 if (in & MDS_ATTR_KILL_SUID)
781 if (in & MDS_ATTR_KILL_SGID)
784 if (in & MDS_ATTR_FROM_OPEN)
785 rr->rr_flags |= MRF_OPEN_TRUNC;
786 if (in & MDS_OPEN_OWNEROVERRIDE)
787 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
788 if (in & MDS_ATTR_FORCE)
789 ma->ma_attr_flags |= MDS_PERM_BYPASS;
791 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID |
792 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
793 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
794 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
795 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
796 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
798 CERROR("Unknown attr bits: "LPX64"\n", in);
802 void mdt_set_capainfo(struct mdt_thread_info *info, int offset,
803 const struct lu_fid *fid, struct lustre_capa *capa)
805 struct lu_capainfo *lci;
807 LASSERT(offset >= 0 && offset < LU_CAPAINFO_MAX);
808 if (!info->mti_mdt->mdt_lut.lut_mds_capa ||
809 !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA))
812 lci = lu_capainfo_get(info->mti_env);
814 lci->lci_fid[offset] = *fid;
815 lci->lci_capa[offset] = capa;
819 void mdt_dump_capainfo(struct mdt_thread_info *info)
821 struct lu_capainfo *lci = lu_capainfo_get(info->mti_env);
827 for (i = 0; i < LU_CAPAINFO_MAX; i++) {
828 if (lci->lci_capa[i] == NULL) {
829 CERROR("no capa for index %d "DFID"\n",
830 i, PFID(&lci->lci_fid[i]));
833 if (lci->lci_capa[i] == BYPASS_CAPA) {
834 CERROR("bypass for index %d "DFID"\n",
835 i, PFID(&lci->lci_fid[i]));
838 DEBUG_CAPA(D_ERROR, lci->lci_capa[i], "index %d", i);
841 #endif /* DEBUG_CAPA */
845 int mdt_name_unpack(struct req_capsule *pill,
846 const struct req_msg_field *field,
848 enum mdt_name_flags flags)
850 ln->ln_name = req_capsule_client_get(pill, field);
851 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
853 if (!lu_name_is_valid(ln)) {
860 if ((flags & MNF_FIX_ANON) &&
861 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
862 /* Newer (3.x) kernels use a name of "/" for the
863 * "anonymous" disconnected dentries from NFS
864 * filehandle conversion. See d_obtain_alias(). */
872 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
874 struct lu_ucred *uc = mdt_ucred(info);
875 struct md_attr *ma = &info->mti_attr;
876 struct lu_attr *la = &ma->ma_attr;
877 struct req_capsule *pill = info->mti_pill;
878 struct mdt_reint_record *rr = &info->mti_rr;
879 struct mdt_rec_setattr *rec;
882 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
883 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
887 /* This prior initialization is needed for old_init_ucred_reint() */
888 uc->uc_fsuid = rec->sa_fsuid;
889 uc->uc_fsgid = rec->sa_fsgid;
890 uc->uc_cap = rec->sa_cap;
891 uc->uc_suppgids[0] = rec->sa_suppgid;
892 uc->uc_suppgids[1] = -1;
894 rr->rr_fid1 = &rec->sa_fid;
895 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
896 /* If MDS_ATTR_xTIME is set without MDS_ATTR_xTIME_SET and
897 * the client does not have OBD_CONNECT_FULL20, convert it
898 * to LA_xTIME. LU-3036 */
899 if (!(exp_connect_flags(info->mti_exp) & OBD_CONNECT_FULL20)) {
900 if (!(rec->sa_valid & MDS_ATTR_ATIME_SET) &&
901 (rec->sa_valid & MDS_ATTR_ATIME))
902 la->la_valid |= LA_ATIME;
903 if (!(rec->sa_valid & MDS_ATTR_MTIME_SET) &&
904 (rec->sa_valid & MDS_ATTR_MTIME))
905 la->la_valid |= LA_MTIME;
906 if (!(rec->sa_valid & MDS_ATTR_CTIME_SET) &&
907 (rec->sa_valid & MDS_ATTR_CTIME))
908 la->la_valid |= LA_CTIME;
910 la->la_mode = rec->sa_mode;
911 la->la_flags = rec->sa_attr_flags;
912 la->la_uid = rec->sa_uid;
913 la->la_gid = rec->sa_gid;
914 la->la_size = rec->sa_size;
915 la->la_blocks = rec->sa_blocks;
916 la->la_ctime = rec->sa_ctime;
917 la->la_atime = rec->sa_atime;
918 la->la_mtime = rec->sa_mtime;
919 ma->ma_valid = MA_INODE;
921 if (rec->sa_bias & MDS_DATA_MODIFIED)
922 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
924 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
926 if (rec->sa_bias & MDS_HSM_RELEASE)
927 ma->ma_attr_flags |= MDS_HSM_RELEASE;
929 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
931 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
932 mdt_set_capainfo(info, 0, rr->rr_fid1,
933 req_capsule_client_get(pill, &RMF_CAPA1));
938 static int mdt_ioepoch_unpack(struct mdt_thread_info *info)
940 struct req_capsule *pill = info->mti_pill;
943 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
945 req_capsule_client_get(pill, &RMF_MDT_EPOCH);
947 info->mti_ioepoch = NULL;
948 RETURN(info->mti_ioepoch == NULL ? -EFAULT : 0);
951 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
952 struct req_capsule *pill = info->mti_pill;
954 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
955 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
956 if (info->mti_dlm_req == NULL)
963 static int mdt_setattr_unpack(struct mdt_thread_info *info)
965 struct mdt_reint_record *rr = &info->mti_rr;
966 struct md_attr *ma = &info->mti_attr;
967 struct req_capsule *pill = info->mti_pill;
971 rc = mdt_setattr_unpack_rec(info);
975 /* Epoch may be absent */
976 mdt_ioepoch_unpack(info);
978 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
979 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
980 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
982 if (rr->rr_eadatalen > 0) {
983 const struct lmv_user_md *lum;
986 /* Sigh ma_valid(from req) does not indicate whether
987 * it will set LOV/LMV EA, so we have to check magic */
988 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
989 ma->ma_valid |= MA_LMV;
990 ma->ma_lmv = (void *)rr->rr_eadata;
991 ma->ma_lmv_size = rr->rr_eadatalen;
993 ma->ma_valid |= MA_LOV;
994 ma->ma_lmm = (void *)rr->rr_eadata;
995 ma->ma_lmm_size = rr->rr_eadatalen;
1000 rc = mdt_dlmreq_unpack(info);
1004 static int mdt_hsm_release_unpack(struct mdt_thread_info *info)
1006 struct md_attr *ma = &info->mti_attr;
1007 struct req_capsule *pill = info->mti_pill;
1010 if (!(ma->ma_attr_flags & MDS_HSM_RELEASE))
1013 req_capsule_extend(pill, &RQF_MDS_RELEASE_CLOSE);
1015 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1016 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1022 int mdt_close_unpack(struct mdt_thread_info *info)
1027 rc = mdt_ioepoch_unpack(info);
1031 rc = mdt_setattr_unpack_rec(info);
1035 rc = mdt_hsm_release_unpack(info);
1039 RETURN(mdt_init_ucred_reint(info));
1042 static int mdt_create_unpack(struct mdt_thread_info *info)
1044 struct lu_ucred *uc = mdt_ucred(info);
1045 struct mdt_rec_create *rec;
1046 struct lu_attr *attr = &info->mti_attr.ma_attr;
1047 struct mdt_reint_record *rr = &info->mti_rr;
1048 struct req_capsule *pill = info->mti_pill;
1049 struct md_op_spec *sp = &info->mti_spec;
1053 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1054 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1058 /* This prior initialization is needed for old_init_ucred_reint() */
1059 uc->uc_fsuid = rec->cr_fsuid;
1060 uc->uc_fsgid = rec->cr_fsgid;
1061 uc->uc_cap = rec->cr_cap;
1062 uc->uc_suppgids[0] = rec->cr_suppgid1;
1063 uc->uc_suppgids[1] = -1;
1064 uc->uc_umask = rec->cr_umask;
1066 rr->rr_fid1 = &rec->cr_fid1;
1067 rr->rr_fid2 = &rec->cr_fid2;
1068 attr->la_mode = rec->cr_mode;
1069 attr->la_rdev = rec->cr_rdev;
1070 attr->la_uid = rec->cr_fsuid;
1071 attr->la_gid = rec->cr_fsgid;
1072 attr->la_ctime = rec->cr_time;
1073 attr->la_mtime = rec->cr_time;
1074 attr->la_atime = rec->cr_time;
1075 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1076 LA_CTIME | LA_MTIME | LA_ATIME;
1077 memset(&sp->u, 0, sizeof(sp->u));
1078 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1080 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1081 mdt_set_capainfo(info, 0, rr->rr_fid1,
1082 req_capsule_client_get(pill, &RMF_CAPA1));
1083 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1085 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1089 if (S_ISLNK(attr->la_mode)) {
1090 const char *tgt = NULL;
1092 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1093 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1094 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1095 sp->u.sp_symname = tgt;
1100 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
1101 if (S_ISDIR(attr->la_mode) &&
1102 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1103 sp->u.sp_ea.eadata =
1104 req_capsule_client_get(pill, &RMF_EADATA);
1105 sp->u.sp_ea.eadatalen =
1106 req_capsule_get_size(pill, &RMF_EADATA,
1108 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1112 rc = mdt_dlmreq_unpack(info);
1116 static int mdt_link_unpack(struct mdt_thread_info *info)
1118 struct lu_ucred *uc = mdt_ucred(info);
1119 struct mdt_rec_link *rec;
1120 struct lu_attr *attr = &info->mti_attr.ma_attr;
1121 struct mdt_reint_record *rr = &info->mti_rr;
1122 struct req_capsule *pill = info->mti_pill;
1126 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1127 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1131 /* This prior initialization is needed for old_init_ucred_reint() */
1132 uc->uc_fsuid = rec->lk_fsuid;
1133 uc->uc_fsgid = rec->lk_fsgid;
1134 uc->uc_cap = rec->lk_cap;
1135 uc->uc_suppgids[0] = rec->lk_suppgid1;
1136 uc->uc_suppgids[1] = rec->lk_suppgid2;
1138 attr->la_uid = rec->lk_fsuid;
1139 attr->la_gid = rec->lk_fsgid;
1140 rr->rr_fid1 = &rec->lk_fid1;
1141 rr->rr_fid2 = &rec->lk_fid2;
1142 attr->la_ctime = rec->lk_time;
1143 attr->la_mtime = rec->lk_time;
1144 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1146 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1147 mdt_set_capainfo(info, 0, rr->rr_fid1,
1148 req_capsule_client_get(pill, &RMF_CAPA1));
1149 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1150 mdt_set_capainfo(info, 1, rr->rr_fid2,
1151 req_capsule_client_get(pill, &RMF_CAPA2));
1153 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1157 rc = mdt_dlmreq_unpack(info);
1162 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1164 struct lu_ucred *uc = mdt_ucred(info);
1165 struct mdt_rec_unlink *rec;
1166 struct md_attr *ma = &info->mti_attr;
1167 struct lu_attr *attr = &info->mti_attr.ma_attr;
1168 struct mdt_reint_record *rr = &info->mti_rr;
1169 struct req_capsule *pill = info->mti_pill;
1173 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1174 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1178 /* This prior initialization is needed for old_init_ucred_reint() */
1179 uc->uc_fsuid = rec->ul_fsuid;
1180 uc->uc_fsgid = rec->ul_fsgid;
1181 uc->uc_cap = rec->ul_cap;
1182 uc->uc_suppgids[0] = rec->ul_suppgid1;
1183 uc->uc_suppgids[1] = -1;
1185 attr->la_uid = rec->ul_fsuid;
1186 attr->la_gid = rec->ul_fsgid;
1187 rr->rr_fid1 = &rec->ul_fid1;
1188 rr->rr_fid2 = &rec->ul_fid2;
1189 attr->la_ctime = rec->ul_time;
1190 attr->la_mtime = rec->ul_time;
1191 attr->la_mode = rec->ul_mode;
1192 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1194 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1195 mdt_set_capainfo(info, 0, rr->rr_fid1,
1196 req_capsule_client_get(pill, &RMF_CAPA1));
1198 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1202 if (rec->ul_bias & MDS_VTX_BYPASS)
1203 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1205 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1207 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1209 rc = mdt_dlmreq_unpack(info);
1213 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1215 info->mti_spec.sp_rm_entry = 1;
1216 return mdt_unlink_unpack(info);
1219 static int mdt_rename_unpack(struct mdt_thread_info *info)
1221 struct lu_ucred *uc = mdt_ucred(info);
1222 struct mdt_rec_rename *rec;
1223 struct md_attr *ma = &info->mti_attr;
1224 struct lu_attr *attr = &info->mti_attr.ma_attr;
1225 struct mdt_reint_record *rr = &info->mti_rr;
1226 struct req_capsule *pill = info->mti_pill;
1230 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1231 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1235 /* This prior initialization is needed for old_init_ucred_reint() */
1236 uc->uc_fsuid = rec->rn_fsuid;
1237 uc->uc_fsgid = rec->rn_fsgid;
1238 uc->uc_cap = rec->rn_cap;
1239 uc->uc_suppgids[0] = rec->rn_suppgid1;
1240 uc->uc_suppgids[1] = rec->rn_suppgid2;
1242 attr->la_uid = rec->rn_fsuid;
1243 attr->la_gid = rec->rn_fsgid;
1244 rr->rr_fid1 = &rec->rn_fid1;
1245 rr->rr_fid2 = &rec->rn_fid2;
1246 attr->la_ctime = rec->rn_time;
1247 attr->la_mtime = rec->rn_time;
1248 /* rename_tgt contains the mode already */
1249 attr->la_mode = rec->rn_mode;
1250 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1252 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1253 mdt_set_capainfo(info, 0, rr->rr_fid1,
1254 req_capsule_client_get(pill, &RMF_CAPA1));
1255 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1256 mdt_set_capainfo(info, 1, rr->rr_fid2,
1257 req_capsule_client_get(pill, &RMF_CAPA2));
1259 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1263 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1267 if (rec->rn_bias & MDS_VTX_BYPASS)
1268 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1270 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1272 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1275 rc = mdt_dlmreq_unpack(info);
1281 * please see comment above LOV_MAGIC_V1_DEF
1283 static void mdt_fix_lov_magic(struct mdt_thread_info *info)
1285 struct mdt_reint_record *rr = &info->mti_rr;
1286 struct lov_user_md_v1 *v1;
1288 v1 = (void *)rr->rr_eadata;
1291 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1292 if (v1->lmm_magic == LOV_USER_MAGIC_V1) {
1293 v1->lmm_magic = LOV_MAGIC_V1_DEF;
1294 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
1295 v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF);
1296 } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
1297 v1->lmm_magic = LOV_MAGIC_V3_DEF;
1298 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
1299 v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF);
1304 static int mdt_open_unpack(struct mdt_thread_info *info)
1306 struct lu_ucred *uc = mdt_ucred(info);
1307 struct mdt_rec_create *rec;
1308 struct lu_attr *attr = &info->mti_attr.ma_attr;
1309 struct req_capsule *pill = info->mti_pill;
1310 struct mdt_reint_record *rr = &info->mti_rr;
1311 struct ptlrpc_request *req = mdt_info_req(info);
1312 struct md_op_spec *sp = &info->mti_spec;
1315 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1316 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1320 /* This prior initialization is needed for old_init_ucred_reint() */
1321 uc->uc_fsuid = rec->cr_fsuid;
1322 uc->uc_fsgid = rec->cr_fsgid;
1323 uc->uc_cap = rec->cr_cap;
1324 uc->uc_suppgids[0] = rec->cr_suppgid1;
1325 uc->uc_suppgids[1] = rec->cr_suppgid2;
1326 uc->uc_umask = rec->cr_umask;
1328 rr->rr_fid1 = &rec->cr_fid1;
1329 rr->rr_fid2 = &rec->cr_fid2;
1330 rr->rr_handle = &rec->cr_old_handle;
1331 attr->la_mode = rec->cr_mode;
1332 attr->la_rdev = rec->cr_rdev;
1333 attr->la_uid = rec->cr_fsuid;
1334 attr->la_gid = rec->cr_fsgid;
1335 attr->la_ctime = rec->cr_time;
1336 attr->la_mtime = rec->cr_time;
1337 attr->la_atime = rec->cr_time;
1338 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1339 LA_CTIME | LA_MTIME | LA_ATIME;
1340 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1341 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1342 /* Do not trigger ASSERTION if client miss to set such flags. */
1343 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1345 info->mti_replayepoch = rec->cr_ioepoch;
1347 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1349 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1350 mdt_set_capainfo(info, 0, rr->rr_fid1,
1351 req_capsule_client_get(pill, &RMF_CAPA1));
1352 if (req_is_replay(req) &&
1353 req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) {
1355 mdt_set_capainfo(info, 1, rr->rr_fid2,
1356 req_capsule_client_get(pill, &RMF_CAPA2));
1359 * FIXME: capa in replay open request might have expired,
1360 * bypass capa check. Security hole?
1362 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1363 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1367 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1369 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1370 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1372 if (rr->rr_eadatalen > 0) {
1373 rr->rr_eadata = req_capsule_client_get(pill,
1375 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1376 sp->u.sp_ea.eadata = rr->rr_eadata;
1377 sp->no_create = !!req_is_replay(req);
1378 mdt_fix_lov_magic(info);
1382 * Client default md_size may be 0 right after client start,
1383 * until all osc are connected, set here just some reasonable
1384 * value to prevent misbehavior.
1386 if (rr->rr_eadatalen == 0 &&
1387 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1388 rr->rr_eadatalen = MIN_MD_SIZE;
1394 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1396 struct mdt_reint_record *rr = &info->mti_rr;
1397 struct lu_ucred *uc = mdt_ucred(info);
1398 struct lu_attr *attr = &info->mti_attr.ma_attr;
1399 struct req_capsule *pill = info->mti_pill;
1400 struct mdt_rec_setxattr *rec;
1405 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1406 sizeof(struct mdt_rec_reint));
1408 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1412 /* This prior initialization is needed for old_init_ucred_reint() */
1413 uc->uc_fsuid = rec->sx_fsuid;
1414 uc->uc_fsgid = rec->sx_fsgid;
1415 uc->uc_cap = rec->sx_cap;
1416 uc->uc_suppgids[0] = rec->sx_suppgid1;
1417 uc->uc_suppgids[1] = -1;
1419 rr->rr_opcode = rec->sx_opcode;
1420 rr->rr_fid1 = &rec->sx_fid;
1421 attr->la_valid = rec->sx_valid;
1422 attr->la_ctime = rec->sx_time;
1423 attr->la_size = rec->sx_size;
1424 attr->la_flags = rec->sx_flags;
1426 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1427 mdt_set_capainfo(info, 0, rr->rr_fid1,
1428 req_capsule_client_get(pill, &RMF_CAPA1));
1430 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1432 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1436 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1437 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1439 if (rr->rr_eadatalen > 0) {
1440 rr->rr_eadata = req_capsule_client_get(pill,
1442 if (rr->rr_eadata == NULL)
1445 rr->rr_eadata = NULL;
1447 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1448 CDEBUG(D_INFO, "no xattr data supplied\n");
1452 if (mdt_dlmreq_unpack(info) < 0)
1459 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1461 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1462 [REINT_SETATTR] = mdt_setattr_unpack,
1463 [REINT_CREATE] = mdt_create_unpack,
1464 [REINT_LINK] = mdt_link_unpack,
1465 [REINT_UNLINK] = mdt_unlink_unpack,
1466 [REINT_RENAME] = mdt_rename_unpack,
1467 [REINT_OPEN] = mdt_open_unpack,
1468 [REINT_SETXATTR] = mdt_setxattr_unpack,
1469 [REINT_RMENTRY] = mdt_rmentry_unpack,
1470 [REINT_MIGRATE] = mdt_rename_unpack,
1473 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1478 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1479 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1480 info->mti_rr.rr_opcode = op;
1481 rc = mdt_reint_unpackers[op](info);
1483 CERROR("Unexpected opcode %d\n", op);