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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mdt/mdt_lib.c
34 * Lustre Metadata Target (mdt) request unpacking helper.
36 * Author: Peter Braam <braam@clusterfs.com>
37 * Author: Andreas Dilger <adilger@clusterfs.com>
38 * Author: Phil Schwan <phil@clusterfs.com>
39 * Author: Mike Shaver <shaver@clusterfs.com>
40 * Author: Nikita Danilov <nikita@clusterfs.com>
41 * Author: Huang Hua <huanghua@clusterfs.com>
42 * Author: Fan Yong <fanyong@clusterfs.com>
45 #define DEBUG_SUBSYSTEM S_MDS
47 #include <linux/user_namespace.h>
48 #ifdef HAVE_UIDGID_HEADER
49 # include <linux/uidgid.h>
51 #include "mdt_internal.h"
52 #include <lnet/nidstr.h>
53 #include <lustre_nodemap.h>
55 typedef enum ucred_init_type {
61 static __u64 get_mrc_cr_flags(struct mdt_rec_create *mrc)
63 return (__u64)(mrc->cr_flags_l) | ((__u64)mrc->cr_flags_h << 32);
66 void mdt_exit_ucred(struct mdt_thread_info *info)
68 struct lu_ucred *uc = mdt_ucred(info);
69 struct mdt_device *mdt = info->mti_mdt;
72 if (uc->uc_valid != UCRED_INIT) {
73 uc->uc_suppgids[0] = uc->uc_suppgids[1] = -1;
75 put_group_info(uc->uc_ginfo);
78 if (uc->uc_identity) {
79 mdt_identity_put(mdt->mdt_identity_cache,
81 uc->uc_identity = NULL;
83 uc->uc_valid = UCRED_INIT;
87 static int match_nosquash_list(struct rw_semaphore *sem,
88 struct list_head *nidlist,
94 rc = cfs_match_nid(peernid, nidlist);
99 /* root_squash for inter-MDS operations */
100 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid)
102 struct lu_ucred *ucred = mdt_ucred(info);
103 struct root_squash_info *squash = &info->mti_mdt->mdt_squash;
106 LASSERT(ucred != NULL);
107 if (!squash->rsi_uid || ucred->uc_fsuid)
110 if (match_nosquash_list(&squash->rsi_sem,
111 &squash->rsi_nosquash_nids,
113 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
114 libcfs_nid2str(peernid));
118 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
119 libcfs_nid2str(peernid),
120 ucred->uc_fsuid, ucred->uc_fsgid, ucred->uc_cap,
121 squash->rsi_uid, squash->rsi_gid, 0);
123 ucred->uc_fsuid = squash->rsi_uid;
124 ucred->uc_fsgid = squash->rsi_gid;
126 ucred->uc_suppgids[0] = -1;
127 ucred->uc_suppgids[1] = -1;
132 static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc)
134 struct ptlrpc_request *req = mdt_info_req(info);
135 const char *jobid = mdt_req_get_jobid(req);
137 /* set jobid if specified. */
139 strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid));
141 uc->uc_jobid[0] = '\0';
144 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
145 void *buf, bool drop_fs_cap)
147 struct ptlrpc_request *req = mdt_info_req(info);
148 struct mdt_device *mdt = info->mti_mdt;
149 struct ptlrpc_user_desc *pud = req->rq_user_desc;
150 struct lu_ucred *ucred = mdt_ucred(info);
151 struct lu_nodemap *nodemap;
152 lnet_nid_t peernid = req->rq_peer.nid;
160 LASSERT(req->rq_auth_gss);
161 LASSERT(!req->rq_auth_usr_mdt);
162 LASSERT(req->rq_user_desc);
163 LASSERT(ucred != NULL);
165 ucred->uc_valid = UCRED_INVALID;
167 nodemap = nodemap_get_from_exp(info->mti_exp);
169 RETURN(PTR_ERR(nodemap));
171 pud->pud_uid = nodemap_map_id(nodemap, NODEMAP_UID,
172 NODEMAP_CLIENT_TO_FS, pud->pud_uid);
173 pud->pud_gid = nodemap_map_id(nodemap, NODEMAP_GID,
174 NODEMAP_CLIENT_TO_FS, pud->pud_gid);
175 pud->pud_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
176 NODEMAP_CLIENT_TO_FS, pud->pud_fsuid);
177 pud->pud_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
178 NODEMAP_CLIENT_TO_FS, pud->pud_fsgid);
180 ucred->uc_o_uid = pud->pud_uid;
181 ucred->uc_o_gid = pud->pud_gid;
182 ucred->uc_o_fsuid = pud->pud_fsuid;
183 ucred->uc_o_fsgid = pud->pud_fsgid;
185 if (nodemap && ucred->uc_o_uid == nodemap->nm_squash_uid) {
186 /* deny access before we get identity ref */
187 if (nodemap->nmf_deny_unknown) {
188 nodemap_putref(nodemap);
192 ucred->uc_fsuid = nodemap->nm_squash_uid;
193 ucred->uc_fsgid = nodemap->nm_squash_gid;
195 ucred->uc_suppgids[0] = -1;
196 ucred->uc_suppgids[1] = -1;
198 nodemap_putref(nodemap);
200 if (type == BODY_INIT) {
201 struct mdt_body *body = (struct mdt_body *)buf;
203 ucred->uc_suppgids[0] = body->mbo_suppgid;
204 ucred->uc_suppgids[1] = -1;
207 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
208 req->rq_auth_uid != pud->pud_uid) {
209 CDEBUG(D_SEC, "local client %s: auth uid %u "
210 "while client claims %u:%u/%u:%u\n",
211 libcfs_nid2str(peernid), req->rq_auth_uid,
212 pud->pud_uid, pud->pud_gid,
213 pud->pud_fsuid, pud->pud_fsgid);
217 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
218 ucred->uc_identity = NULL;
219 perm = CFS_SETUID_PERM | CFS_SETGID_PERM | CFS_SETGRP_PERM;
221 struct md_identity *identity;
223 identity = mdt_identity_get(mdt->mdt_identity_cache,
225 if (IS_ERR(identity)) {
226 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
227 ucred->uc_identity = NULL;
228 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
232 "Deny access without identity: uid %u\n",
237 ucred->uc_identity = identity;
238 perm = mdt_identity_get_perm(ucred->uc_identity,
243 /* find out the setuid/setgid attempt */
244 setuid = (pud->pud_uid != pud->pud_fsuid);
245 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
246 (ucred->uc_identity &&
247 (pud->pud_gid != ucred->uc_identity->mi_gid)));
249 /* check permission of setuid */
250 if (setuid && !(perm & CFS_SETUID_PERM)) {
251 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
252 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
253 GOTO(out, rc = -EACCES);
256 /* check permission of setgid */
257 if (setgid && !(perm & CFS_SETGID_PERM)) {
258 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
259 "from %s\n", pud->pud_uid, pud->pud_gid,
260 pud->pud_fsuid, pud->pud_fsgid,
261 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
262 GOTO(out, rc = -EACCES);
265 if (perm & CFS_SETGRP_PERM) {
266 if (pud->pud_ngroups) {
267 /* setgroups for local client */
268 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
269 if (!ucred->uc_ginfo) {
270 CERROR("failed to alloc %d groups\n",
272 GOTO(out, rc = -ENOMEM);
275 lustre_groups_from_list(ucred->uc_ginfo,
277 lustre_groups_sort(ucred->uc_ginfo);
279 ucred->uc_ginfo = NULL;
282 ucred->uc_suppgids[0] = -1;
283 ucred->uc_suppgids[1] = -1;
284 ucred->uc_ginfo = NULL;
287 ucred->uc_uid = pud->pud_uid;
288 ucred->uc_gid = pud->pud_gid;
289 ucred->uc_fsuid = pud->pud_fsuid;
290 ucred->uc_fsgid = pud->pud_fsgid;
292 /* process root_squash here. */
293 mdt_root_squash(info, peernid);
295 /* remove fs privilege for non-root user. */
296 if (ucred->uc_fsuid && drop_fs_cap)
297 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
299 ucred->uc_cap = pud->pud_cap;
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)
334 /* 1. If identity_upcall is disabled,
335 * permit local client to do anything. */
336 if (is_identity_get_disabled(info->mti_mdt->mdt_identity_cache))
339 /* 2. If fail to get related identities, then forbid any client to
340 * set supplementary group IDs. */
341 if (uc->uc_identity == NULL)
344 /* 3. Check the permission in the identities. */
345 perm = mdt_identity_get_perm(uc->uc_identity,
346 mdt_info_req(info)->rq_peer.nid);
347 if (perm & CFS_SETGRP_PERM)
353 int mdt_check_ucred(struct mdt_thread_info *info)
355 struct ptlrpc_request *req = mdt_info_req(info);
356 struct mdt_device *mdt = info->mti_mdt;
357 struct ptlrpc_user_desc *pud = req->rq_user_desc;
358 struct lu_ucred *ucred = mdt_ucred(info);
359 struct md_identity *identity = NULL;
360 lnet_nid_t peernid = req->rq_peer.nid;
368 LASSERT(ucred != NULL);
369 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
372 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
375 /* sanity check: if we use strong authentication, we expect the
376 * uid which client claimed is true */
377 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
378 req->rq_auth_uid != pud->pud_uid) {
379 CDEBUG(D_SEC, "local client %s: auth uid %u "
380 "while client claims %u:%u/%u:%u\n",
381 libcfs_nid2str(peernid), req->rq_auth_uid,
382 pud->pud_uid, pud->pud_gid,
383 pud->pud_fsuid, pud->pud_fsgid);
387 if (is_identity_get_disabled(mdt->mdt_identity_cache))
390 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
391 if (IS_ERR(identity)) {
392 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
395 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
401 perm = mdt_identity_get_perm(identity, peernid);
402 /* find out the setuid/setgid attempt */
403 setuid = (pud->pud_uid != pud->pud_fsuid);
404 setgid = (pud->pud_gid != pud->pud_fsgid ||
405 pud->pud_gid != identity->mi_gid);
407 /* check permission of setuid */
408 if (setuid && !(perm & CFS_SETUID_PERM)) {
409 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
410 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
411 GOTO(out, rc = -EACCES);
414 /* check permission of setgid */
415 if (setgid && !(perm & CFS_SETGID_PERM)) {
416 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
417 "from %s\n", pud->pud_uid, pud->pud_gid,
418 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
419 libcfs_nid2str(peernid));
420 GOTO(out, rc = -EACCES);
426 mdt_identity_put(mdt->mdt_identity_cache, identity);
430 static int old_init_ucred_common(struct mdt_thread_info *info,
431 struct lu_nodemap *nodemap,
434 struct lu_ucred *uc = mdt_ucred(info);
435 struct mdt_device *mdt = info->mti_mdt;
436 struct md_identity *identity = NULL;
438 if (nodemap && uc->uc_o_uid == nodemap->nm_squash_uid) {
439 /* deny access before we get identity ref */
440 if (nodemap->nmf_deny_unknown)
443 uc->uc_fsuid = nodemap->nm_squash_uid;
444 uc->uc_fsgid = nodemap->nm_squash_gid;
446 uc->uc_suppgids[0] = -1;
447 uc->uc_suppgids[1] = -1;
450 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
451 identity = mdt_identity_get(mdt->mdt_identity_cache,
453 if (IS_ERR(identity)) {
454 if (unlikely(PTR_ERR(identity) == -EREMCHG ||
455 uc->uc_cap & CFS_CAP_FS_MASK)) {
458 CDEBUG(D_SEC, "Deny access without identity: "
459 "uid %u\n", uc->uc_fsuid);
464 uc->uc_identity = identity;
466 /* process root_squash here. */
467 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
469 /* remove fs privilege for non-root user. */
470 if (uc->uc_fsuid && drop_fs_cap)
471 uc->uc_cap &= ~CFS_CAP_FS_MASK;
472 uc->uc_valid = UCRED_OLD;
473 ucred_set_jobid(info, uc);
480 static int old_init_ucred(struct mdt_thread_info *info,
481 struct mdt_body *body, bool drop_fs_cap)
483 struct lu_ucred *uc = mdt_ucred(info);
484 struct lu_nodemap *nodemap;
488 nodemap = nodemap_get_from_exp(info->mti_exp);
490 RETURN(PTR_ERR(nodemap));
492 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
493 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
494 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
495 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
496 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
497 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
498 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
499 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
502 uc->uc_valid = UCRED_INVALID;
503 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
504 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
505 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
506 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
507 uc->uc_suppgids[0] = body->mbo_suppgid;
508 uc->uc_suppgids[1] = -1;
510 uc->uc_cap = body->mbo_capability;
512 rc = old_init_ucred_common(info, nodemap, drop_fs_cap);
513 nodemap_putref(nodemap);
518 static int old_init_ucred_reint(struct mdt_thread_info *info)
520 struct lu_ucred *uc = mdt_ucred(info);
521 struct lu_nodemap *nodemap;
525 nodemap = nodemap_get_from_exp(info->mti_exp);
527 RETURN(PTR_ERR(nodemap));
531 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
532 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
533 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
534 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
536 uc->uc_valid = UCRED_INVALID;
537 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
538 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
541 rc = old_init_ucred_common(info, nodemap, true); /* drop_fs_cap=true */
542 nodemap_putref(nodemap);
547 static inline int __mdt_init_ucred(struct mdt_thread_info *info,
548 struct mdt_body *body,
551 struct ptlrpc_request *req = mdt_info_req(info);
552 struct lu_ucred *uc = mdt_ucred(info);
555 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
558 mdt_exit_ucred(info);
560 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
561 return old_init_ucred(info, body, drop_fs_cap);
563 return new_init_ucred(info, BODY_INIT, body, drop_fs_cap);
566 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
568 return __mdt_init_ucred(info, body, true);
571 /* LU-6528 when "no_subtree_check" is set for NFS export, nfsd_set_fh_dentry()
572 * doesn't set correct fsuid explicitely, but raise capability to allow
573 * exportfs_decode_fh() to reconnect disconnected dentry into dcache. So for
574 * lookup (i.e. intent_getattr), we should keep FS capability, otherwise it
575 * will fail permission check. */
576 int mdt_init_ucred_intent_getattr(struct mdt_thread_info *info,
577 struct mdt_body *body)
579 return __mdt_init_ucred(info, body, false);
582 int mdt_init_ucred_reint(struct mdt_thread_info *info)
584 struct ptlrpc_request *req = mdt_info_req(info);
585 struct lu_ucred *uc = mdt_ucred(info);
586 struct md_attr *ma = &info->mti_attr;
589 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
592 /* LU-5564: for normal close request, skip permission check */
593 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE &&
594 !(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
595 uc->uc_cap |= CFS_CAP_FS_MASK;
597 mdt_exit_ucred(info);
599 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
600 return old_init_ucred_reint(info);
602 return new_init_ucred(info, REC_INIT, NULL, true);
605 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
606 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
608 const struct lov_ost_data_v1 *lod;
612 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
615 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
617 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
618 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
619 le32_to_cpu(lmm->lmm_pattern));
620 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
621 le32_to_cpu(lmm->lmm_stripe_size), count);
623 /* If it's a directory or a released file, then there are
624 * no actual objects to print, so bail out. */
625 if (valid & OBD_MD_FLDIREA ||
626 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
629 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
630 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
633 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
634 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
635 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
639 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
641 const struct lmv_mds_md_v1 *lmm1;
644 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
647 lmm1 = &lmv->lmv_md_v1;
649 "magic 0x%08X, master %#X stripe_count %#x hash_type %#x\n",
650 le32_to_cpu(lmm1->lmv_magic),
651 le32_to_cpu(lmm1->lmv_master_mdt_index),
652 le32_to_cpu(lmm1->lmv_stripe_count),
653 le32_to_cpu(lmm1->lmv_hash_type));
655 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
658 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
661 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
662 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
666 /* Shrink and/or grow reply buffers */
667 int mdt_fix_reply(struct mdt_thread_info *info)
669 struct req_capsule *pill = info->mti_pill;
670 struct mdt_body *body;
671 int md_size, md_packed = 0;
676 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
677 LASSERT(body != NULL);
679 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
681 md_size = body->mbo_eadatasize;
685 acl_size = body->mbo_aclsize;
687 /* this replay - not send info to client */
688 if (info->mti_spec.no_create) {
693 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
698 &RMF_ACL, or &RMF_LOGCOOKIES
699 (optional) &RMF_CAPA1,
700 (optional) &RMF_CAPA2,
701 (optional) something else
704 /* MDT_MD buffer may be bigger than packed value, let's shrink all
705 * buffers before growing it */
706 if (info->mti_big_lmm_used) {
707 /* big_lmm buffer may be used even without packing the result
708 * into reply, just for internal server needs */
709 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
710 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
713 /* free big lmm if md_size is not needed */
714 if (md_size == 0 || md_packed == 0) {
715 info->mti_big_lmm_used = 0;
717 /* buffer must be allocated separately */
718 LASSERT(info->mti_attr.ma_lmm !=
719 req_capsule_server_get(pill, &RMF_MDT_MD));
720 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
722 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
723 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
726 if (info->mti_big_acl_used) {
728 info->mti_big_acl_used = 0;
730 req_capsule_shrink(pill, &RMF_ACL, 0, RCL_SERVER);
731 } else if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER)) {
732 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
733 } else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
734 req_capsule_shrink(pill, &RMF_LOGCOOKIES, acl_size, RCL_SERVER);
737 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
738 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
739 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
741 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
742 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
743 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
746 * Some more field should be shrinked if needed.
747 * This should be done by those who added fields to reply message.
750 /* Grow MD buffer if needed finally */
751 if (info->mti_big_lmm_used) {
754 LASSERT(md_size > md_packed);
755 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
756 md_size - md_packed);
757 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
759 /* we can't answer with proper LOV EA, drop flags,
760 * the rc is also returned so this request is
761 * considered as failed */
762 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
763 /* don't return transno along with error */
764 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
766 /* now we need to pack right LOV/LMV EA */
767 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
768 if (info->mti_attr.ma_valid & MA_LOV) {
769 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
771 info->mti_attr.ma_lmm_size);
772 memcpy(lmm, info->mti_attr.ma_lmm,
773 info->mti_attr.ma_lmm_size);
774 } else if (info->mti_attr.ma_valid & MA_LMV) {
775 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
777 info->mti_attr.ma_lmv_size);
778 memcpy(lmm, info->mti_attr.ma_lmv,
779 info->mti_attr.ma_lmv_size);
783 /* update mdt_max_mdsize so clients will be aware about that */
784 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
785 info->mti_mdt->mdt_max_mdsize =
786 info->mti_attr.ma_lmm_size;
787 info->mti_big_lmm_used = 0;
790 if (info->mti_big_acl_used) {
791 CDEBUG(D_INFO, "Enlarge reply ACL buffer to %d bytes\n",
794 rc = req_capsule_server_grow(pill, &RMF_ACL, acl_size);
796 body->mbo_valid &= ~OBD_MD_FLACL;
798 void *acl = req_capsule_server_get(pill, &RMF_ACL);
800 memcpy(acl, info->mti_big_acl, acl_size);
803 info->mti_big_acl_used = 0;
810 /* if object is dying, pack the lov/llog data,
811 * parameter info->mti_attr should be valid at this point!
812 * Also implements RAoLU policy */
813 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
816 struct mdt_body *repbody = NULL;
817 const struct lu_attr *la = &ma->ma_attr;
818 struct coordinator *cdt = &info->mti_mdt->mdt_coordinator;
821 struct hsm_action_item hai = {
822 .hai_len = sizeof(hai),
823 .hai_action = HSMA_REMOVE,
824 .hai_extent.length = -1,
833 if (mdt_info_req(info) != NULL) {
834 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
835 LASSERT(repbody != NULL);
837 CDEBUG(D_INFO, "not running in a request/reply context\n");
840 if ((ma->ma_valid & MA_INODE) && repbody != NULL)
841 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
843 if (ma->ma_valid & MA_LOV) {
844 CERROR("No need in LOV EA upon unlink\n");
848 repbody->mbo_eadatasize = 0;
850 /* Only check unlinked and archived if RAoLU and upon last close */
851 if (!cdt->cdt_remove_archive_on_last_unlink ||
852 atomic_read(&mo->mot_open_count) != 0)
855 /* mdt_attr_get_complex will clear ma_valid, so check here first */
856 if ((ma->ma_valid & MA_INODE) && (ma->ma_attr.la_nlink != 0))
859 if ((ma->ma_valid & MA_HSM) && (!(ma->ma_hsm.mh_flags & HS_EXISTS)))
862 need |= (MA_INODE | MA_HSM) & ~ma->ma_valid;
864 /* ma->ma_valid is missing either MA_INODE, MA_HSM, or both,
865 * try setting them */
867 rc = mdt_attr_get_complex(info, mo, ma);
869 CERROR("%s: unable to fetch missing attributes of"
870 DFID": rc=%d\n", mdt_obd_name(info->mti_mdt),
871 PFID(mdt_object_fid(mo)), rc);
875 if (need & MA_INODE) {
876 if (ma->ma_valid & MA_INODE) {
877 if (ma->ma_attr.la_nlink != 0)
885 if (ma->ma_valid & MA_HSM) {
886 if (!(ma->ma_hsm.mh_flags & HS_EXISTS))
894 /* RAoLU policy is active, last close on file has occured,
895 * file is unlinked, file is archived, so create remove request
897 * If CDT is not running, requests will be logged for later. */
898 compound_id = atomic_inc_return(&cdt->cdt_compound_id);
899 if (ma->ma_hsm.mh_arch_id != 0)
900 archive_id = ma->ma_hsm.mh_arch_id;
902 archive_id = cdt->cdt_default_archive_id;
904 hai.hai_fid = *mdt_object_fid(mo);
906 rc = mdt_agent_record_add(info->mti_env, info->mti_mdt,
907 compound_id, archive_id, 0, &hai);
909 CERROR("%s: unable to add HSM remove request for "DFID
910 ": rc=%d\n", mdt_obd_name(info->mti_mdt),
911 PFID(mdt_object_fid(mo)), rc);
916 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
922 if (in & MDS_ATTR_MODE)
924 if (in & MDS_ATTR_UID)
926 if (in & MDS_ATTR_GID)
928 if (in & MDS_ATTR_SIZE)
930 if (in & MDS_ATTR_BLOCKS)
932 if (in & MDS_ATTR_ATIME_SET)
934 if (in & MDS_ATTR_CTIME_SET)
936 if (in & MDS_ATTR_MTIME_SET)
938 if (in & MDS_ATTR_ATTR_FLAG)
940 if (in & MDS_ATTR_KILL_SUID)
942 if (in & MDS_ATTR_KILL_SGID)
944 if (in & MDS_ATTR_PROJID)
947 if (in & MDS_ATTR_FROM_OPEN)
948 rr->rr_flags |= MRF_OPEN_TRUNC;
949 if (in & MDS_OPEN_OWNEROVERRIDE)
950 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
951 if (in & MDS_ATTR_FORCE)
952 ma->ma_attr_flags |= MDS_PERM_BYPASS;
954 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID | MDS_ATTR_PROJID |
955 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
956 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
957 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
958 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
959 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
961 CERROR("Unknown attr bits: %#llx\n", in);
967 int mdt_name_unpack(struct req_capsule *pill,
968 const struct req_msg_field *field,
970 enum mdt_name_flags flags)
972 ln->ln_name = req_capsule_client_get(pill, field);
973 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
975 if (!lu_name_is_valid(ln)) {
982 if ((flags & MNF_FIX_ANON) &&
983 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
984 /* Newer (3.x) kernels use a name of "/" for the
985 * "anonymous" disconnected dentries from NFS
986 * filehandle conversion. See d_obtain_alias(). */
994 static int mdt_file_secctx_unpack(struct req_capsule *pill,
995 const char **secctx_name,
996 void **secctx, size_t *secctx_size)
1001 *secctx_name = NULL;
1005 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT) ||
1006 !req_capsule_field_present(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT))
1009 name_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX_NAME,
1014 name = req_capsule_client_get(pill, &RMF_FILE_SECCTX_NAME);
1015 if (strnlen(name, name_size) != name_size - 1)
1018 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX, RCL_CLIENT) ||
1019 !req_capsule_field_present(pill, &RMF_FILE_SECCTX, RCL_CLIENT))
1022 *secctx_name = name;
1023 *secctx = req_capsule_client_get(pill, &RMF_FILE_SECCTX);
1024 *secctx_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX, RCL_CLIENT);
1029 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
1031 struct lu_ucred *uc = mdt_ucred(info);
1032 struct md_attr *ma = &info->mti_attr;
1033 struct lu_attr *la = &ma->ma_attr;
1034 struct req_capsule *pill = info->mti_pill;
1035 struct mdt_reint_record *rr = &info->mti_rr;
1036 struct mdt_rec_setattr *rec;
1037 struct lu_nodemap *nodemap;
1040 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
1041 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1045 /* This prior initialization is needed for old_init_ucred_reint() */
1046 uc->uc_fsuid = rec->sa_fsuid;
1047 uc->uc_fsgid = rec->sa_fsgid;
1048 uc->uc_cap = rec->sa_cap;
1049 uc->uc_suppgids[0] = rec->sa_suppgid;
1050 uc->uc_suppgids[1] = -1;
1052 rr->rr_fid1 = &rec->sa_fid;
1053 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
1054 la->la_mode = rec->sa_mode;
1055 la->la_flags = rec->sa_attr_flags;
1057 nodemap = nodemap_get_from_exp(info->mti_exp);
1058 if (IS_ERR(nodemap))
1059 RETURN(PTR_ERR(nodemap));
1061 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
1062 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
1063 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
1064 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
1065 la->la_projid = rec->sa_projid;
1066 nodemap_putref(nodemap);
1068 la->la_size = rec->sa_size;
1069 la->la_blocks = rec->sa_blocks;
1070 la->la_ctime = rec->sa_ctime;
1071 la->la_atime = rec->sa_atime;
1072 la->la_mtime = rec->sa_mtime;
1073 ma->ma_valid = MA_INODE;
1075 if (rec->sa_bias & MDS_DATA_MODIFIED)
1076 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
1078 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
1080 if (rec->sa_bias & MDS_HSM_RELEASE)
1081 ma->ma_attr_flags |= MDS_HSM_RELEASE;
1083 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
1085 if (rec->sa_bias & MDS_CLOSE_LAYOUT_SWAP)
1086 ma->ma_attr_flags |= MDS_CLOSE_LAYOUT_SWAP;
1088 ma->ma_attr_flags &= ~MDS_CLOSE_LAYOUT_SWAP;
1093 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
1095 struct req_capsule *pill = info->mti_pill;
1096 struct mdt_ioepoch *ioepoch;
1099 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
1100 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
1104 if (ioepoch == NULL)
1107 info->mti_close_handle = ioepoch->mio_handle;
1112 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
1113 struct req_capsule *pill = info->mti_pill;
1115 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
1116 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
1117 if (info->mti_dlm_req == NULL)
1124 static int mdt_setattr_unpack(struct mdt_thread_info *info)
1126 struct mdt_reint_record *rr = &info->mti_rr;
1127 struct md_attr *ma = &info->mti_attr;
1128 struct req_capsule *pill = info->mti_pill;
1132 rc = mdt_setattr_unpack_rec(info);
1136 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1137 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1138 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1140 if (rr->rr_eadatalen > 0) {
1141 const struct lmv_user_md *lum;
1143 lum = rr->rr_eadata;
1144 /* Sigh ma_valid(from req) does not indicate whether
1145 * it will set LOV/LMV EA, so we have to check magic */
1146 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1147 ma->ma_valid |= MA_LMV;
1148 ma->ma_lmv = (void *)rr->rr_eadata;
1149 ma->ma_lmv_size = rr->rr_eadatalen;
1151 ma->ma_valid |= MA_LOV;
1152 ma->ma_lmm = (void *)rr->rr_eadata;
1153 ma->ma_lmm_size = rr->rr_eadatalen;
1158 rc = mdt_dlmreq_unpack(info);
1162 static int mdt_intent_close_unpack(struct mdt_thread_info *info)
1164 struct md_attr *ma = &info->mti_attr;
1165 struct req_capsule *pill = info->mti_pill;
1168 if (!(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
1171 req_capsule_extend(pill, &RQF_MDS_INTENT_CLOSE);
1173 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1174 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1180 int mdt_close_unpack(struct mdt_thread_info *info)
1185 rc = mdt_close_handle_unpack(info);
1189 rc = mdt_setattr_unpack_rec(info);
1193 rc = mdt_intent_close_unpack(info);
1197 RETURN(mdt_init_ucred_reint(info));
1200 static int mdt_create_unpack(struct mdt_thread_info *info)
1202 struct lu_ucred *uc = mdt_ucred(info);
1203 struct mdt_rec_create *rec;
1204 struct lu_attr *attr = &info->mti_attr.ma_attr;
1205 struct mdt_reint_record *rr = &info->mti_rr;
1206 struct req_capsule *pill = info->mti_pill;
1207 struct md_op_spec *sp = &info->mti_spec;
1211 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1212 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1216 /* This prior initialization is needed for old_init_ucred_reint() */
1217 uc->uc_fsuid = rec->cr_fsuid;
1218 uc->uc_fsgid = rec->cr_fsgid;
1219 uc->uc_cap = rec->cr_cap;
1220 uc->uc_suppgids[0] = rec->cr_suppgid1;
1221 uc->uc_suppgids[1] = -1;
1222 uc->uc_umask = rec->cr_umask;
1224 rr->rr_fid1 = &rec->cr_fid1;
1225 rr->rr_fid2 = &rec->cr_fid2;
1226 attr->la_mode = rec->cr_mode;
1227 attr->la_rdev = rec->cr_rdev;
1228 attr->la_uid = rec->cr_fsuid;
1229 attr->la_gid = rec->cr_fsgid;
1230 attr->la_ctime = rec->cr_time;
1231 attr->la_mtime = rec->cr_time;
1232 attr->la_atime = rec->cr_time;
1233 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1234 LA_CTIME | LA_MTIME | LA_ATIME;
1235 memset(&sp->u, 0, sizeof(sp->u));
1236 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1238 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1242 if (S_ISLNK(attr->la_mode)) {
1243 const char *tgt = NULL;
1245 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1246 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1247 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1248 sp->u.sp_symname = tgt;
1253 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_ACL);
1254 if (S_ISDIR(attr->la_mode) &&
1255 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1256 sp->u.sp_ea.eadata =
1257 req_capsule_client_get(pill, &RMF_EADATA);
1258 sp->u.sp_ea.eadatalen =
1259 req_capsule_get_size(pill, &RMF_EADATA,
1261 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1265 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1266 &sp->sp_cr_file_secctx,
1267 &sp->sp_cr_file_secctx_size);
1271 rc = mdt_dlmreq_unpack(info);
1275 static int mdt_link_unpack(struct mdt_thread_info *info)
1277 struct lu_ucred *uc = mdt_ucred(info);
1278 struct mdt_rec_link *rec;
1279 struct lu_attr *attr = &info->mti_attr.ma_attr;
1280 struct mdt_reint_record *rr = &info->mti_rr;
1281 struct req_capsule *pill = info->mti_pill;
1285 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1286 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1290 /* This prior initialization is needed for old_init_ucred_reint() */
1291 uc->uc_fsuid = rec->lk_fsuid;
1292 uc->uc_fsgid = rec->lk_fsgid;
1293 uc->uc_cap = rec->lk_cap;
1294 uc->uc_suppgids[0] = rec->lk_suppgid1;
1295 uc->uc_suppgids[1] = rec->lk_suppgid2;
1297 attr->la_uid = rec->lk_fsuid;
1298 attr->la_gid = rec->lk_fsgid;
1299 rr->rr_fid1 = &rec->lk_fid1;
1300 rr->rr_fid2 = &rec->lk_fid2;
1301 attr->la_ctime = rec->lk_time;
1302 attr->la_mtime = rec->lk_time;
1303 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1305 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1309 rc = mdt_dlmreq_unpack(info);
1314 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1316 struct lu_ucred *uc = mdt_ucred(info);
1317 struct mdt_rec_unlink *rec;
1318 struct md_attr *ma = &info->mti_attr;
1319 struct lu_attr *attr = &info->mti_attr.ma_attr;
1320 struct mdt_reint_record *rr = &info->mti_rr;
1321 struct req_capsule *pill = info->mti_pill;
1325 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1326 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1330 /* This prior initialization is needed for old_init_ucred_reint() */
1331 uc->uc_fsuid = rec->ul_fsuid;
1332 uc->uc_fsgid = rec->ul_fsgid;
1333 uc->uc_cap = rec->ul_cap;
1334 uc->uc_suppgids[0] = rec->ul_suppgid1;
1335 uc->uc_suppgids[1] = -1;
1337 attr->la_uid = rec->ul_fsuid;
1338 attr->la_gid = rec->ul_fsgid;
1339 rr->rr_fid1 = &rec->ul_fid1;
1340 rr->rr_fid2 = &rec->ul_fid2;
1341 attr->la_ctime = rec->ul_time;
1342 attr->la_mtime = rec->ul_time;
1343 attr->la_mode = rec->ul_mode;
1344 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1346 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1350 if (rec->ul_bias & MDS_VTX_BYPASS)
1351 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1353 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1355 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1357 rc = mdt_dlmreq_unpack(info);
1361 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1363 info->mti_spec.sp_rm_entry = 1;
1364 return mdt_unlink_unpack(info);
1367 static int mdt_rename_unpack(struct mdt_thread_info *info)
1369 struct lu_ucred *uc = mdt_ucred(info);
1370 struct mdt_rec_rename *rec;
1371 struct md_attr *ma = &info->mti_attr;
1372 struct lu_attr *attr = &info->mti_attr.ma_attr;
1373 struct mdt_reint_record *rr = &info->mti_rr;
1374 struct req_capsule *pill = info->mti_pill;
1378 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1379 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1383 /* This prior initialization is needed for old_init_ucred_reint() */
1384 uc->uc_fsuid = rec->rn_fsuid;
1385 uc->uc_fsgid = rec->rn_fsgid;
1386 uc->uc_cap = rec->rn_cap;
1387 uc->uc_suppgids[0] = rec->rn_suppgid1;
1388 uc->uc_suppgids[1] = rec->rn_suppgid2;
1390 attr->la_uid = rec->rn_fsuid;
1391 attr->la_gid = rec->rn_fsgid;
1392 rr->rr_fid1 = &rec->rn_fid1;
1393 rr->rr_fid2 = &rec->rn_fid2;
1394 attr->la_ctime = rec->rn_time;
1395 attr->la_mtime = rec->rn_time;
1396 /* rename_tgt contains the mode already */
1397 attr->la_mode = rec->rn_mode;
1398 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1400 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1404 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1408 if (rec->rn_bias & MDS_VTX_BYPASS)
1409 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1411 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1413 if (rec->rn_bias & MDS_RENAME_MIGRATE) {
1414 req_capsule_extend(info->mti_pill, &RQF_MDS_REINT_MIGRATE);
1415 rc = mdt_close_handle_unpack(info);
1418 info->mti_spec.sp_migrate_close = 1;
1421 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1424 rc = mdt_dlmreq_unpack(info);
1430 * please see comment above LOV_MAGIC_V1_DEF
1432 void mdt_fix_lov_magic(struct mdt_thread_info *info, void *eadata)
1434 struct lov_user_md_v1 *v1 = eadata;
1438 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1439 if ((v1->lmm_magic & LOV_MAGIC_MASK) == LOV_MAGIC_MAGIC)
1440 v1->lmm_magic |= LOV_MAGIC_DEF;
1441 else if ((v1->lmm_magic & __swab32(LOV_MAGIC_MAGIC)) ==
1442 __swab32(LOV_MAGIC_MAGIC))
1443 v1->lmm_magic |= __swab32(LOV_MAGIC_DEF);
1447 static int mdt_open_unpack(struct mdt_thread_info *info)
1449 struct lu_ucred *uc = mdt_ucred(info);
1450 struct mdt_rec_create *rec;
1451 struct lu_attr *attr = &info->mti_attr.ma_attr;
1452 struct req_capsule *pill = info->mti_pill;
1453 struct mdt_reint_record *rr = &info->mti_rr;
1454 struct ptlrpc_request *req = mdt_info_req(info);
1455 struct md_op_spec *sp = &info->mti_spec;
1459 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1460 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1464 /* This prior initialization is needed for old_init_ucred_reint() */
1465 uc->uc_fsuid = rec->cr_fsuid;
1466 uc->uc_fsgid = rec->cr_fsgid;
1467 uc->uc_cap = rec->cr_cap;
1468 uc->uc_suppgids[0] = rec->cr_suppgid1;
1469 uc->uc_suppgids[1] = rec->cr_suppgid2;
1470 uc->uc_umask = rec->cr_umask;
1472 rr->rr_fid1 = &rec->cr_fid1;
1473 rr->rr_fid2 = &rec->cr_fid2;
1474 rr->rr_handle = &rec->cr_old_handle;
1475 attr->la_mode = rec->cr_mode;
1476 attr->la_rdev = rec->cr_rdev;
1477 attr->la_uid = rec->cr_fsuid;
1478 attr->la_gid = rec->cr_fsgid;
1479 attr->la_ctime = rec->cr_time;
1480 attr->la_mtime = rec->cr_time;
1481 attr->la_atime = rec->cr_time;
1482 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1483 LA_CTIME | LA_MTIME | LA_ATIME;
1484 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1485 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1486 /* Do not trigger ASSERTION if client miss to set such flags. */
1487 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1490 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1492 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1494 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1495 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1497 if (rr->rr_eadatalen > 0) {
1498 rr->rr_eadata = req_capsule_client_get(pill,
1500 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1501 sp->u.sp_ea.eadata = rr->rr_eadata;
1502 sp->no_create = !!req_is_replay(req);
1503 mdt_fix_lov_magic(info, rr->rr_eadata);
1507 * Client default md_size may be 0 right after client start,
1508 * until all osc are connected, set here just some reasonable
1509 * value to prevent misbehavior.
1511 if (rr->rr_eadatalen == 0 &&
1512 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1513 rr->rr_eadatalen = MIN_MD_SIZE;
1516 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1517 &sp->sp_cr_file_secctx,
1518 &sp->sp_cr_file_secctx_size);
1523 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1525 struct mdt_reint_record *rr = &info->mti_rr;
1526 struct lu_ucred *uc = mdt_ucred(info);
1527 struct lu_attr *attr = &info->mti_attr.ma_attr;
1528 struct req_capsule *pill = info->mti_pill;
1529 struct mdt_rec_setxattr *rec;
1534 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1535 sizeof(struct mdt_rec_reint));
1537 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1541 /* This prior initialization is needed for old_init_ucred_reint() */
1542 uc->uc_fsuid = rec->sx_fsuid;
1543 uc->uc_fsgid = rec->sx_fsgid;
1544 uc->uc_cap = rec->sx_cap;
1545 uc->uc_suppgids[0] = rec->sx_suppgid1;
1546 uc->uc_suppgids[1] = -1;
1548 rr->rr_opcode = rec->sx_opcode;
1549 rr->rr_fid1 = &rec->sx_fid;
1550 attr->la_valid = rec->sx_valid;
1551 attr->la_ctime = rec->sx_time;
1552 attr->la_size = rec->sx_size;
1553 attr->la_flags = rec->sx_flags;
1555 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1559 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1560 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1562 if (rr->rr_eadatalen > 0) {
1563 rr->rr_eadata = req_capsule_client_get(pill,
1565 if (rr->rr_eadata == NULL)
1568 rr->rr_eadata = NULL;
1570 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1571 CDEBUG(D_INFO, "no xattr data supplied\n");
1575 if (mdt_dlmreq_unpack(info) < 0)
1582 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1584 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1585 [REINT_SETATTR] = mdt_setattr_unpack,
1586 [REINT_CREATE] = mdt_create_unpack,
1587 [REINT_LINK] = mdt_link_unpack,
1588 [REINT_UNLINK] = mdt_unlink_unpack,
1589 [REINT_RENAME] = mdt_rename_unpack,
1590 [REINT_OPEN] = mdt_open_unpack,
1591 [REINT_SETXATTR] = mdt_setxattr_unpack,
1592 [REINT_RMENTRY] = mdt_rmentry_unpack,
1593 [REINT_MIGRATE] = mdt_rename_unpack,
1596 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1601 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1602 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1603 info->mti_rr.rr_opcode = op;
1604 rc = mdt_reint_unpackers[op](info);
1606 CERROR("Unexpected opcode %d\n", op);