4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_lib.c
38 * Lustre Metadata Target (mdt) request unpacking helper.
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Fan Yong <fanyong@clusterfs.com>
49 #define DEBUG_SUBSYSTEM S_MDS
51 #include <linux/user_namespace.h>
52 #ifdef HAVE_UIDGID_HEADER
53 # include <linux/uidgid.h>
55 #include "mdt_internal.h"
56 #include <lnet/nidstr.h>
57 #include <lustre_nodemap.h>
59 typedef enum ucred_init_type {
65 void mdt_exit_ucred(struct mdt_thread_info *info)
67 struct lu_ucred *uc = mdt_ucred(info);
68 struct mdt_device *mdt = info->mti_mdt;
71 if (uc->uc_valid != UCRED_INIT) {
72 uc->uc_suppgids[0] = uc->uc_suppgids[1] = -1;
74 put_group_info(uc->uc_ginfo);
77 if (uc->uc_identity) {
78 mdt_identity_put(mdt->mdt_identity_cache,
80 uc->uc_identity = NULL;
82 uc->uc_valid = UCRED_INIT;
86 static int match_nosquash_list(struct rw_semaphore *sem,
87 struct list_head *nidlist,
93 rc = cfs_match_nid(peernid, nidlist);
98 /* root_squash for inter-MDS operations */
99 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid)
101 struct lu_ucred *ucred = mdt_ucred(info);
102 struct root_squash_info *squash = &info->mti_mdt->mdt_squash;
105 LASSERT(ucred != NULL);
106 if (!squash->rsi_uid || ucred->uc_fsuid)
109 if (match_nosquash_list(&squash->rsi_sem,
110 &squash->rsi_nosquash_nids,
112 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
113 libcfs_nid2str(peernid));
117 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
118 libcfs_nid2str(peernid),
119 ucred->uc_fsuid, ucred->uc_fsgid, ucred->uc_cap,
120 squash->rsi_uid, squash->rsi_gid, 0);
122 ucred->uc_fsuid = squash->rsi_uid;
123 ucred->uc_fsgid = squash->rsi_gid;
125 ucred->uc_suppgids[0] = -1;
126 ucred->uc_suppgids[1] = -1;
131 static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc)
133 struct ptlrpc_request *req = mdt_info_req(info);
134 const char *jobid = mdt_req_get_jobid(req);
136 /* set jobid if specified. */
138 strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid));
140 uc->uc_jobid[0] = '\0';
143 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
144 void *buf, bool drop_fs_cap)
146 struct ptlrpc_request *req = mdt_info_req(info);
147 struct mdt_device *mdt = info->mti_mdt;
148 struct ptlrpc_user_desc *pud = req->rq_user_desc;
149 struct lu_ucred *ucred = mdt_ucred(info);
150 lnet_nid_t peernid = req->rq_peer.nid;
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. */
297 if (ucred->uc_fsuid && drop_fs_cap)
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 int old_init_ucred_common(struct mdt_thread_info *info,
469 struct lu_ucred *uc = mdt_ucred(info);
470 struct mdt_device *mdt = info->mti_mdt;
471 struct md_identity *identity = NULL;
472 struct lu_nodemap *nodemap =
473 info->mti_exp->exp_target_data.ted_nodemap;
475 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
476 identity = mdt_identity_get(mdt->mdt_identity_cache,
478 if (IS_ERR(identity)) {
479 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
482 CDEBUG(D_SEC, "Deny access without identity: "
483 "uid %u\n", uc->uc_fsuid);
488 uc->uc_identity = identity;
490 if (nodemap == NULL) {
491 CERROR("%s: cli %s/%p nodemap not set.\n",
492 mdt2obd_dev(mdt)->obd_name,
493 info->mti_exp->exp_client_uuid.uuid, info->mti_exp);
495 } else if (uc->uc_o_uid == nodemap->nm_squash_uid) {
496 uc->uc_fsuid = nodemap->nm_squash_uid;
497 uc->uc_fsgid = nodemap->nm_squash_gid;
499 uc->uc_suppgids[0] = -1;
500 uc->uc_suppgids[1] = -1;
503 /* process root_squash here. */
504 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
506 /* remove fs privilege for non-root user. */
508 uc->uc_cap &= ~CFS_CAP_FS_MASK;
509 uc->uc_valid = UCRED_OLD;
510 ucred_set_jobid(info, uc);
515 static int old_init_ucred(struct mdt_thread_info *info,
516 struct mdt_body *body, bool drop_fs_cap)
518 struct lu_ucred *uc = mdt_ucred(info);
519 struct lu_nodemap *nodemap =
520 info->mti_exp->exp_target_data.ted_nodemap;
524 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
525 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
526 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
527 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
528 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
529 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
530 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
531 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
534 uc->uc_valid = UCRED_INVALID;
535 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
536 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
537 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
538 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
539 uc->uc_suppgids[0] = body->mbo_suppgid;
540 uc->uc_suppgids[1] = -1;
542 uc->uc_cap = body->mbo_capability;
544 rc = old_init_ucred_common(info, drop_fs_cap);
549 static int old_init_ucred_reint(struct mdt_thread_info *info)
551 struct lu_ucred *uc = mdt_ucred(info);
552 struct lu_nodemap *nodemap =
553 info->mti_exp->exp_target_data.ted_nodemap;
559 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
560 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
561 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
562 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
564 uc->uc_valid = UCRED_INVALID;
565 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
566 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
569 rc = old_init_ucred_common(info, true); /* drop_fs_cap = true */
574 static inline int __mdt_init_ucred(struct mdt_thread_info *info,
575 struct mdt_body *body,
578 struct ptlrpc_request *req = mdt_info_req(info);
579 struct lu_ucred *uc = mdt_ucred(info);
582 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
585 mdt_exit_ucred(info);
587 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
588 return old_init_ucred(info, body, drop_fs_cap);
590 return new_init_ucred(info, BODY_INIT, body, drop_fs_cap);
593 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
595 return __mdt_init_ucred(info, body, true);
598 /* LU-6528 when "no_subtree_check" is set for NFS export, nfsd_set_fh_dentry()
599 * doesn't set correct fsuid explicitely, but raise capability to allow
600 * exportfs_decode_fh() to reconnect disconnected dentry into dcache. So for
601 * lookup (i.e. intent_getattr), we should keep FS capability, otherwise it
602 * will fail permission check. */
603 int mdt_init_ucred_intent_getattr(struct mdt_thread_info *info,
604 struct mdt_body *body)
606 return __mdt_init_ucred(info, body, false);
609 int mdt_init_ucred_reint(struct mdt_thread_info *info)
611 struct ptlrpc_request *req = mdt_info_req(info);
612 struct lu_ucred *uc = mdt_ucred(info);
615 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
618 mdt_exit_ucred(info);
620 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
621 return old_init_ucred_reint(info);
623 return new_init_ucred(info, REC_INIT, NULL, true);
626 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
627 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
629 const struct lov_ost_data_v1 *lod;
633 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
636 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
638 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
639 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
640 le32_to_cpu(lmm->lmm_pattern));
641 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
642 le32_to_cpu(lmm->lmm_stripe_size), count);
644 /* If it's a directory or a released file, then there are
645 * no actual objects to print, so bail out. */
646 if (valid & OBD_MD_FLDIREA ||
647 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
650 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
651 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
654 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
655 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
656 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
660 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
662 const struct lmv_mds_md_v1 *lmm1;
665 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
668 lmm1 = &lmv->lmv_md_v1;
669 CDEBUG(level, "magic 0x%08X, master %#X stripe_count %#x\n",
670 le32_to_cpu(lmm1->lmv_magic),
671 le32_to_cpu(lmm1->lmv_master_mdt_index),
672 le32_to_cpu(lmm1->lmv_stripe_count));
674 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
677 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
680 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
681 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
685 /* Shrink and/or grow reply buffers */
686 int mdt_fix_reply(struct mdt_thread_info *info)
688 struct req_capsule *pill = info->mti_pill;
689 struct mdt_body *body;
690 int md_size, md_packed = 0;
695 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
696 LASSERT(body != NULL);
698 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
700 md_size = body->mbo_eadatasize;
704 acl_size = body->mbo_aclsize;
706 /* this replay - not send info to client */
707 if (info->mti_spec.no_create) {
712 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
717 &RMF_ACL, or &RMF_LOGCOOKIES
718 (optional) &RMF_CAPA1,
719 (optional) &RMF_CAPA2,
720 (optional) something else
723 /* MDT_MD buffer may be bigger than packed value, let's shrink all
724 * buffers before growing it */
725 if (info->mti_big_lmm_used) {
726 /* big_lmm buffer may be used even without packing the result
727 * into reply, just for internal server needs */
728 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
729 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
732 /* free big lmm if md_size is not needed */
733 if (md_size == 0 || md_packed == 0) {
734 info->mti_big_lmm_used = 0;
736 /* buffer must be allocated separately */
737 LASSERT(info->mti_attr.ma_lmm !=
738 req_capsule_server_get(pill, &RMF_MDT_MD));
739 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
741 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
742 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
745 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
746 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
747 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
748 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
749 acl_size, RCL_SERVER);
751 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
752 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
753 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
755 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
756 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
757 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
760 * Some more field should be shrinked if needed.
761 * This should be done by those who added fields to reply message.
764 /* Grow MD buffer if needed finally */
765 if (info->mti_big_lmm_used) {
768 LASSERT(md_size > md_packed);
769 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
770 md_size - md_packed);
771 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
773 /* we can't answer with proper LOV EA, drop flags,
774 * the rc is also returned so this request is
775 * considered as failed */
776 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
777 /* don't return transno along with error */
778 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
780 /* now we need to pack right LOV/LMV EA */
781 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
782 if (info->mti_attr.ma_valid & MA_LOV) {
783 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
785 info->mti_attr.ma_lmm_size);
786 memcpy(lmm, info->mti_attr.ma_lmm,
787 info->mti_attr.ma_lmm_size);
788 } else if (info->mti_attr.ma_valid & MA_LMV) {
789 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
791 info->mti_attr.ma_lmv_size);
792 memcpy(lmm, info->mti_attr.ma_lmv,
793 info->mti_attr.ma_lmv_size);
796 /* update mdt_max_mdsize so clients will be aware about that */
797 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
798 info->mti_mdt->mdt_max_mdsize =
799 info->mti_attr.ma_lmm_size;
800 info->mti_big_lmm_used = 0;
806 /* if object is dying, pack the lov/llog data,
807 * parameter info->mti_attr should be valid at this point! */
808 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
809 const struct md_attr *ma)
811 struct mdt_body *repbody;
812 const struct lu_attr *la = &ma->ma_attr;
815 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
816 LASSERT(repbody != NULL);
818 if (ma->ma_valid & MA_INODE)
819 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
821 if (ma->ma_valid & MA_LOV) {
822 CERROR("No need in LOV EA upon unlink\n");
825 repbody->mbo_eadatasize = 0;
830 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
836 if (in & MDS_ATTR_MODE)
838 if (in & MDS_ATTR_UID)
840 if (in & MDS_ATTR_GID)
842 if (in & MDS_ATTR_SIZE)
844 if (in & MDS_ATTR_BLOCKS)
846 if (in & MDS_ATTR_ATIME_SET)
848 if (in & MDS_ATTR_CTIME_SET)
850 if (in & MDS_ATTR_MTIME_SET)
852 if (in & MDS_ATTR_ATTR_FLAG)
854 if (in & MDS_ATTR_KILL_SUID)
856 if (in & MDS_ATTR_KILL_SGID)
859 if (in & MDS_ATTR_FROM_OPEN)
860 rr->rr_flags |= MRF_OPEN_TRUNC;
861 if (in & MDS_OPEN_OWNEROVERRIDE)
862 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
863 if (in & MDS_ATTR_FORCE)
864 ma->ma_attr_flags |= MDS_PERM_BYPASS;
866 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID |
867 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
868 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
869 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
870 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
871 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
873 CERROR("Unknown attr bits: "LPX64"\n", in);
879 int mdt_name_unpack(struct req_capsule *pill,
880 const struct req_msg_field *field,
882 enum mdt_name_flags flags)
884 ln->ln_name = req_capsule_client_get(pill, field);
885 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
887 if (!lu_name_is_valid(ln)) {
894 if ((flags & MNF_FIX_ANON) &&
895 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
896 /* Newer (3.x) kernels use a name of "/" for the
897 * "anonymous" disconnected dentries from NFS
898 * filehandle conversion. See d_obtain_alias(). */
906 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
908 struct lu_ucred *uc = mdt_ucred(info);
909 struct md_attr *ma = &info->mti_attr;
910 struct lu_attr *la = &ma->ma_attr;
911 struct req_capsule *pill = info->mti_pill;
912 struct mdt_reint_record *rr = &info->mti_rr;
913 struct mdt_rec_setattr *rec;
914 struct lu_nodemap *nodemap =
915 info->mti_exp->exp_target_data.ted_nodemap;
918 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
919 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
923 /* This prior initialization is needed for old_init_ucred_reint() */
924 uc->uc_fsuid = rec->sa_fsuid;
925 uc->uc_fsgid = rec->sa_fsgid;
926 uc->uc_cap = rec->sa_cap;
927 uc->uc_suppgids[0] = rec->sa_suppgid;
928 uc->uc_suppgids[1] = -1;
930 rr->rr_fid1 = &rec->sa_fid;
931 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
932 la->la_mode = rec->sa_mode;
933 la->la_flags = rec->sa_attr_flags;
934 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
935 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
936 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
937 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
938 la->la_size = rec->sa_size;
939 la->la_blocks = rec->sa_blocks;
940 la->la_ctime = rec->sa_ctime;
941 la->la_atime = rec->sa_atime;
942 la->la_mtime = rec->sa_mtime;
943 ma->ma_valid = MA_INODE;
945 if (rec->sa_bias & MDS_DATA_MODIFIED)
946 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
948 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
950 if (rec->sa_bias & MDS_HSM_RELEASE)
951 ma->ma_attr_flags |= MDS_HSM_RELEASE;
953 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
955 if (rec->sa_bias & MDS_CLOSE_LAYOUT_SWAP)
956 ma->ma_attr_flags |= MDS_CLOSE_LAYOUT_SWAP;
958 ma->ma_attr_flags &= ~MDS_CLOSE_LAYOUT_SWAP;
963 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
965 struct req_capsule *pill = info->mti_pill;
966 struct mdt_ioepoch *ioepoch;
969 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
970 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
977 info->mti_close_handle = ioepoch->mio_handle;
982 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
983 struct req_capsule *pill = info->mti_pill;
985 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
986 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
987 if (info->mti_dlm_req == NULL)
994 static int mdt_setattr_unpack(struct mdt_thread_info *info)
996 struct mdt_reint_record *rr = &info->mti_rr;
997 struct md_attr *ma = &info->mti_attr;
998 struct req_capsule *pill = info->mti_pill;
1002 rc = mdt_setattr_unpack_rec(info);
1006 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1007 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1008 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1010 if (rr->rr_eadatalen > 0) {
1011 const struct lmv_user_md *lum;
1013 lum = rr->rr_eadata;
1014 /* Sigh ma_valid(from req) does not indicate whether
1015 * it will set LOV/LMV EA, so we have to check magic */
1016 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1017 ma->ma_valid |= MA_LMV;
1018 ma->ma_lmv = (void *)rr->rr_eadata;
1019 ma->ma_lmv_size = rr->rr_eadatalen;
1021 ma->ma_valid |= MA_LOV;
1022 ma->ma_lmm = (void *)rr->rr_eadata;
1023 ma->ma_lmm_size = rr->rr_eadatalen;
1028 rc = mdt_dlmreq_unpack(info);
1032 static int mdt_intent_close_unpack(struct mdt_thread_info *info)
1034 struct md_attr *ma = &info->mti_attr;
1035 struct req_capsule *pill = info->mti_pill;
1038 if (!(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
1041 req_capsule_extend(pill, &RQF_MDS_INTENT_CLOSE);
1043 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1044 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1050 int mdt_close_unpack(struct mdt_thread_info *info)
1055 rc = mdt_close_handle_unpack(info);
1059 rc = mdt_setattr_unpack_rec(info);
1063 rc = mdt_intent_close_unpack(info);
1067 RETURN(mdt_init_ucred_reint(info));
1070 static int mdt_create_unpack(struct mdt_thread_info *info)
1072 struct lu_ucred *uc = mdt_ucred(info);
1073 struct mdt_rec_create *rec;
1074 struct lu_attr *attr = &info->mti_attr.ma_attr;
1075 struct mdt_reint_record *rr = &info->mti_rr;
1076 struct req_capsule *pill = info->mti_pill;
1077 struct md_op_spec *sp = &info->mti_spec;
1081 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1082 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1086 /* This prior initialization is needed for old_init_ucred_reint() */
1087 uc->uc_fsuid = rec->cr_fsuid;
1088 uc->uc_fsgid = rec->cr_fsgid;
1089 uc->uc_cap = rec->cr_cap;
1090 uc->uc_suppgids[0] = rec->cr_suppgid1;
1091 uc->uc_suppgids[1] = -1;
1092 uc->uc_umask = rec->cr_umask;
1094 rr->rr_fid1 = &rec->cr_fid1;
1095 rr->rr_fid2 = &rec->cr_fid2;
1096 attr->la_mode = rec->cr_mode;
1097 attr->la_rdev = rec->cr_rdev;
1098 attr->la_uid = rec->cr_fsuid;
1099 attr->la_gid = rec->cr_fsgid;
1100 attr->la_ctime = rec->cr_time;
1101 attr->la_mtime = rec->cr_time;
1102 attr->la_atime = rec->cr_time;
1103 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1104 LA_CTIME | LA_MTIME | LA_ATIME;
1105 memset(&sp->u, 0, sizeof(sp->u));
1106 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1108 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1112 if (S_ISLNK(attr->la_mode)) {
1113 const char *tgt = NULL;
1115 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1116 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1117 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1118 sp->u.sp_symname = tgt;
1123 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
1124 if (S_ISDIR(attr->la_mode) &&
1125 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1126 sp->u.sp_ea.eadata =
1127 req_capsule_client_get(pill, &RMF_EADATA);
1128 sp->u.sp_ea.eadatalen =
1129 req_capsule_get_size(pill, &RMF_EADATA,
1131 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1135 rc = mdt_dlmreq_unpack(info);
1139 static int mdt_link_unpack(struct mdt_thread_info *info)
1141 struct lu_ucred *uc = mdt_ucred(info);
1142 struct mdt_rec_link *rec;
1143 struct lu_attr *attr = &info->mti_attr.ma_attr;
1144 struct mdt_reint_record *rr = &info->mti_rr;
1145 struct req_capsule *pill = info->mti_pill;
1149 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1150 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1154 /* This prior initialization is needed for old_init_ucred_reint() */
1155 uc->uc_fsuid = rec->lk_fsuid;
1156 uc->uc_fsgid = rec->lk_fsgid;
1157 uc->uc_cap = rec->lk_cap;
1158 uc->uc_suppgids[0] = rec->lk_suppgid1;
1159 uc->uc_suppgids[1] = rec->lk_suppgid2;
1161 attr->la_uid = rec->lk_fsuid;
1162 attr->la_gid = rec->lk_fsgid;
1163 rr->rr_fid1 = &rec->lk_fid1;
1164 rr->rr_fid2 = &rec->lk_fid2;
1165 attr->la_ctime = rec->lk_time;
1166 attr->la_mtime = rec->lk_time;
1167 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1169 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1173 rc = mdt_dlmreq_unpack(info);
1178 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1180 struct lu_ucred *uc = mdt_ucred(info);
1181 struct mdt_rec_unlink *rec;
1182 struct md_attr *ma = &info->mti_attr;
1183 struct lu_attr *attr = &info->mti_attr.ma_attr;
1184 struct mdt_reint_record *rr = &info->mti_rr;
1185 struct req_capsule *pill = info->mti_pill;
1189 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1190 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1194 /* This prior initialization is needed for old_init_ucred_reint() */
1195 uc->uc_fsuid = rec->ul_fsuid;
1196 uc->uc_fsgid = rec->ul_fsgid;
1197 uc->uc_cap = rec->ul_cap;
1198 uc->uc_suppgids[0] = rec->ul_suppgid1;
1199 uc->uc_suppgids[1] = -1;
1201 attr->la_uid = rec->ul_fsuid;
1202 attr->la_gid = rec->ul_fsgid;
1203 rr->rr_fid1 = &rec->ul_fid1;
1204 rr->rr_fid2 = &rec->ul_fid2;
1205 attr->la_ctime = rec->ul_time;
1206 attr->la_mtime = rec->ul_time;
1207 attr->la_mode = rec->ul_mode;
1208 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1210 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1214 if (rec->ul_bias & MDS_VTX_BYPASS)
1215 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1217 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1219 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1221 rc = mdt_dlmreq_unpack(info);
1225 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1227 info->mti_spec.sp_rm_entry = 1;
1228 return mdt_unlink_unpack(info);
1231 static int mdt_rename_unpack(struct mdt_thread_info *info)
1233 struct lu_ucred *uc = mdt_ucred(info);
1234 struct mdt_rec_rename *rec;
1235 struct md_attr *ma = &info->mti_attr;
1236 struct lu_attr *attr = &info->mti_attr.ma_attr;
1237 struct mdt_reint_record *rr = &info->mti_rr;
1238 struct req_capsule *pill = info->mti_pill;
1242 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1243 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1247 /* This prior initialization is needed for old_init_ucred_reint() */
1248 uc->uc_fsuid = rec->rn_fsuid;
1249 uc->uc_fsgid = rec->rn_fsgid;
1250 uc->uc_cap = rec->rn_cap;
1251 uc->uc_suppgids[0] = rec->rn_suppgid1;
1252 uc->uc_suppgids[1] = rec->rn_suppgid2;
1254 attr->la_uid = rec->rn_fsuid;
1255 attr->la_gid = rec->rn_fsgid;
1256 rr->rr_fid1 = &rec->rn_fid1;
1257 rr->rr_fid2 = &rec->rn_fid2;
1258 attr->la_ctime = rec->rn_time;
1259 attr->la_mtime = rec->rn_time;
1260 /* rename_tgt contains the mode already */
1261 attr->la_mode = rec->rn_mode;
1262 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1264 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1268 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1272 if (rec->rn_bias & MDS_VTX_BYPASS)
1273 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1275 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1277 if (rec->rn_bias & MDS_RENAME_MIGRATE) {
1278 req_capsule_extend(info->mti_pill, &RQF_MDS_REINT_MIGRATE);
1279 rc = mdt_close_handle_unpack(info);
1282 info->mti_spec.sp_migrate_close = 1;
1285 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1288 rc = mdt_dlmreq_unpack(info);
1294 * please see comment above LOV_MAGIC_V1_DEF
1296 static void mdt_fix_lov_magic(struct mdt_thread_info *info)
1298 struct mdt_reint_record *rr = &info->mti_rr;
1299 struct lov_user_md_v1 *v1;
1301 v1 = (void *)rr->rr_eadata;
1304 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1305 if (v1->lmm_magic == LOV_USER_MAGIC_V1) {
1306 v1->lmm_magic = LOV_MAGIC_V1_DEF;
1307 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
1308 v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF);
1309 } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
1310 v1->lmm_magic = LOV_MAGIC_V3_DEF;
1311 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
1312 v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF);
1317 static int mdt_open_unpack(struct mdt_thread_info *info)
1319 struct lu_ucred *uc = mdt_ucred(info);
1320 struct mdt_rec_create *rec;
1321 struct lu_attr *attr = &info->mti_attr.ma_attr;
1322 struct req_capsule *pill = info->mti_pill;
1323 struct mdt_reint_record *rr = &info->mti_rr;
1324 struct ptlrpc_request *req = mdt_info_req(info);
1325 struct md_op_spec *sp = &info->mti_spec;
1328 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1329 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1333 /* This prior initialization is needed for old_init_ucred_reint() */
1334 uc->uc_fsuid = rec->cr_fsuid;
1335 uc->uc_fsgid = rec->cr_fsgid;
1336 uc->uc_cap = rec->cr_cap;
1337 uc->uc_suppgids[0] = rec->cr_suppgid1;
1338 uc->uc_suppgids[1] = rec->cr_suppgid2;
1339 uc->uc_umask = rec->cr_umask;
1341 rr->rr_fid1 = &rec->cr_fid1;
1342 rr->rr_fid2 = &rec->cr_fid2;
1343 rr->rr_handle = &rec->cr_old_handle;
1344 attr->la_mode = rec->cr_mode;
1345 attr->la_rdev = rec->cr_rdev;
1346 attr->la_uid = rec->cr_fsuid;
1347 attr->la_gid = rec->cr_fsgid;
1348 attr->la_ctime = rec->cr_time;
1349 attr->la_mtime = rec->cr_time;
1350 attr->la_atime = rec->cr_time;
1351 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1352 LA_CTIME | LA_MTIME | LA_ATIME;
1353 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1354 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1355 /* Do not trigger ASSERTION if client miss to set such flags. */
1356 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1359 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1361 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1363 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1364 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1366 if (rr->rr_eadatalen > 0) {
1367 rr->rr_eadata = req_capsule_client_get(pill,
1369 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1370 sp->u.sp_ea.eadata = rr->rr_eadata;
1371 sp->no_create = !!req_is_replay(req);
1372 mdt_fix_lov_magic(info);
1376 * Client default md_size may be 0 right after client start,
1377 * until all osc are connected, set here just some reasonable
1378 * value to prevent misbehavior.
1380 if (rr->rr_eadatalen == 0 &&
1381 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1382 rr->rr_eadatalen = MIN_MD_SIZE;
1388 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1390 struct mdt_reint_record *rr = &info->mti_rr;
1391 struct lu_ucred *uc = mdt_ucred(info);
1392 struct lu_attr *attr = &info->mti_attr.ma_attr;
1393 struct req_capsule *pill = info->mti_pill;
1394 struct mdt_rec_setxattr *rec;
1399 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1400 sizeof(struct mdt_rec_reint));
1402 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1406 /* This prior initialization is needed for old_init_ucred_reint() */
1407 uc->uc_fsuid = rec->sx_fsuid;
1408 uc->uc_fsgid = rec->sx_fsgid;
1409 uc->uc_cap = rec->sx_cap;
1410 uc->uc_suppgids[0] = rec->sx_suppgid1;
1411 uc->uc_suppgids[1] = -1;
1413 rr->rr_opcode = rec->sx_opcode;
1414 rr->rr_fid1 = &rec->sx_fid;
1415 attr->la_valid = rec->sx_valid;
1416 attr->la_ctime = rec->sx_time;
1417 attr->la_size = rec->sx_size;
1418 attr->la_flags = rec->sx_flags;
1420 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1424 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1425 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1427 if (rr->rr_eadatalen > 0) {
1428 rr->rr_eadata = req_capsule_client_get(pill,
1430 if (rr->rr_eadata == NULL)
1433 rr->rr_eadata = NULL;
1435 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1436 CDEBUG(D_INFO, "no xattr data supplied\n");
1440 if (mdt_dlmreq_unpack(info) < 0)
1447 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1449 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1450 [REINT_SETATTR] = mdt_setattr_unpack,
1451 [REINT_CREATE] = mdt_create_unpack,
1452 [REINT_LINK] = mdt_link_unpack,
1453 [REINT_UNLINK] = mdt_unlink_unpack,
1454 [REINT_RENAME] = mdt_rename_unpack,
1455 [REINT_OPEN] = mdt_open_unpack,
1456 [REINT_SETXATTR] = mdt_setxattr_unpack,
1457 [REINT_RMENTRY] = mdt_rmentry_unpack,
1458 [REINT_MIGRATE] = mdt_rename_unpack,
1461 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1466 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1467 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1468 info->mti_rr.rr_opcode = op;
1469 rc = mdt_reint_unpackers[op](info);
1471 CERROR("Unexpected opcode %d\n", op);