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, 2017, 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 <uapi/linux/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 void ucred_set_nid(struct mdt_thread_info *info, struct lu_ucred *uc)
146 if (info && info->mti_exp && info->mti_exp->exp_connection)
147 uc->uc_nid = info->mti_exp->exp_connection->c_peer.nid;
149 uc->uc_nid = LNET_NID_ANY;
152 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
153 void *buf, bool drop_fs_cap)
155 struct ptlrpc_request *req = mdt_info_req(info);
156 struct mdt_device *mdt = info->mti_mdt;
157 struct ptlrpc_user_desc *pud = req->rq_user_desc;
158 struct lu_ucred *ucred = mdt_ucred(info);
159 struct lu_nodemap *nodemap;
160 lnet_nid_t peernid = req->rq_peer.nid;
168 LASSERT(req->rq_auth_gss);
169 LASSERT(!req->rq_auth_usr_mdt);
170 LASSERT(req->rq_user_desc);
171 LASSERT(ucred != NULL);
173 ucred->uc_valid = UCRED_INVALID;
175 nodemap = nodemap_get_from_exp(info->mti_exp);
177 RETURN(PTR_ERR(nodemap));
179 pud->pud_uid = nodemap_map_id(nodemap, NODEMAP_UID,
180 NODEMAP_CLIENT_TO_FS, pud->pud_uid);
181 pud->pud_gid = nodemap_map_id(nodemap, NODEMAP_GID,
182 NODEMAP_CLIENT_TO_FS, pud->pud_gid);
183 pud->pud_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
184 NODEMAP_CLIENT_TO_FS, pud->pud_fsuid);
185 pud->pud_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
186 NODEMAP_CLIENT_TO_FS, pud->pud_fsgid);
188 ucred->uc_o_uid = pud->pud_uid;
189 ucred->uc_o_gid = pud->pud_gid;
190 ucred->uc_o_fsuid = pud->pud_fsuid;
191 ucred->uc_o_fsgid = pud->pud_fsgid;
193 if (nodemap && ucred->uc_o_uid == nodemap->nm_squash_uid) {
194 /* deny access before we get identity ref */
195 if (nodemap->nmf_deny_unknown) {
196 nodemap_putref(nodemap);
200 ucred->uc_fsuid = nodemap->nm_squash_uid;
201 ucred->uc_fsgid = nodemap->nm_squash_gid;
203 ucred->uc_suppgids[0] = -1;
204 ucred->uc_suppgids[1] = -1;
206 nodemap_putref(nodemap);
208 if (type == BODY_INIT) {
209 struct mdt_body *body = (struct mdt_body *)buf;
211 ucred->uc_suppgids[0] = body->mbo_suppgid;
212 ucred->uc_suppgids[1] = -1;
215 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
216 req->rq_auth_uid != pud->pud_uid) {
217 CDEBUG(D_SEC, "local client %s: auth uid %u "
218 "while client claims %u:%u/%u:%u\n",
219 libcfs_nid2str(peernid), req->rq_auth_uid,
220 pud->pud_uid, pud->pud_gid,
221 pud->pud_fsuid, pud->pud_fsgid);
225 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
226 ucred->uc_identity = NULL;
227 perm = CFS_SETUID_PERM | CFS_SETGID_PERM | CFS_SETGRP_PERM;
229 struct md_identity *identity;
231 identity = mdt_identity_get(mdt->mdt_identity_cache,
233 if (IS_ERR(identity)) {
234 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
235 ucred->uc_identity = NULL;
236 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
240 "Deny access without identity: uid %u\n",
245 ucred->uc_identity = identity;
246 perm = mdt_identity_get_perm(ucred->uc_identity,
251 /* find out the setuid/setgid attempt */
252 setuid = (pud->pud_uid != pud->pud_fsuid);
253 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
254 (ucred->uc_identity &&
255 (pud->pud_gid != ucred->uc_identity->mi_gid)));
257 /* check permission of setuid */
258 if (setuid && !(perm & CFS_SETUID_PERM)) {
259 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
260 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
261 GOTO(out, rc = -EACCES);
264 /* check permission of setgid */
265 if (setgid && !(perm & CFS_SETGID_PERM)) {
266 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
267 "from %s\n", pud->pud_uid, pud->pud_gid,
268 pud->pud_fsuid, pud->pud_fsgid,
269 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
270 GOTO(out, rc = -EACCES);
273 if (perm & CFS_SETGRP_PERM) {
274 if (pud->pud_ngroups) {
275 /* setgroups for local client */
276 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
277 if (!ucred->uc_ginfo) {
278 CERROR("failed to alloc %d groups\n",
280 GOTO(out, rc = -ENOMEM);
283 lustre_groups_from_list(ucred->uc_ginfo,
285 lustre_groups_sort(ucred->uc_ginfo);
287 ucred->uc_ginfo = NULL;
290 ucred->uc_suppgids[0] = -1;
291 ucred->uc_suppgids[1] = -1;
292 ucred->uc_ginfo = NULL;
295 ucred->uc_uid = pud->pud_uid;
296 ucred->uc_gid = pud->pud_gid;
297 ucred->uc_fsuid = pud->pud_fsuid;
298 ucred->uc_fsgid = pud->pud_fsgid;
300 /* process root_squash here. */
301 mdt_root_squash(info, peernid);
303 /* remove fs privilege for non-root user. */
304 if (ucred->uc_fsuid && drop_fs_cap)
305 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
307 ucred->uc_cap = pud->pud_cap;
308 ucred->uc_valid = UCRED_NEW;
309 ucred_set_jobid(info, ucred);
310 ucred_set_nid(info, ucred);
316 if (ucred->uc_ginfo) {
317 put_group_info(ucred->uc_ginfo);
318 ucred->uc_ginfo = NULL;
320 if (ucred->uc_identity) {
321 mdt_identity_put(mdt->mdt_identity_cache,
323 ucred->uc_identity = NULL;
331 * Check whether allow the client to set supplementary group IDs or not.
333 * \param[in] info pointer to the thread context
334 * \param[in] uc pointer to the RPC user descriptor
336 * \retval true if allow to set supplementary group IDs
337 * \retval false for other cases
339 bool allow_client_chgrp(struct mdt_thread_info *info, struct lu_ucred *uc)
343 /* 1. If identity_upcall is disabled,
344 * permit local client to do anything. */
345 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,
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;
377 LASSERT(ucred != NULL);
378 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
381 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
384 /* sanity check: if we use strong authentication, we expect the
385 * uid which client claimed is true */
386 if (!flvr_is_rootonly(req->rq_flvr.sf_rpc) &&
387 req->rq_auth_uid != pud->pud_uid) {
388 CDEBUG(D_SEC, "local client %s: auth uid %u "
389 "while client claims %u:%u/%u:%u\n",
390 libcfs_nid2str(peernid), req->rq_auth_uid,
391 pud->pud_uid, pud->pud_gid,
392 pud->pud_fsuid, pud->pud_fsgid);
396 if (is_identity_get_disabled(mdt->mdt_identity_cache))
399 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
400 if (IS_ERR(identity)) {
401 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
404 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
410 perm = mdt_identity_get_perm(identity, peernid);
411 /* find out the setuid/setgid attempt */
412 setuid = (pud->pud_uid != pud->pud_fsuid);
413 setgid = (pud->pud_gid != pud->pud_fsgid ||
414 pud->pud_gid != identity->mi_gid);
416 /* check permission of setuid */
417 if (setuid && !(perm & CFS_SETUID_PERM)) {
418 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
419 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
420 GOTO(out, rc = -EACCES);
423 /* check permission of setgid */
424 if (setgid && !(perm & CFS_SETGID_PERM)) {
425 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
426 "from %s\n", pud->pud_uid, pud->pud_gid,
427 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
428 libcfs_nid2str(peernid));
429 GOTO(out, rc = -EACCES);
435 mdt_identity_put(mdt->mdt_identity_cache, identity);
439 static int old_init_ucred_common(struct mdt_thread_info *info,
440 struct lu_nodemap *nodemap,
443 struct lu_ucred *uc = mdt_ucred(info);
444 struct mdt_device *mdt = info->mti_mdt;
445 struct md_identity *identity = NULL;
447 if (nodemap && uc->uc_o_uid == nodemap->nm_squash_uid) {
448 /* deny access before we get identity ref */
449 if (nodemap->nmf_deny_unknown)
452 uc->uc_fsuid = nodemap->nm_squash_uid;
453 uc->uc_fsgid = nodemap->nm_squash_gid;
455 uc->uc_suppgids[0] = -1;
456 uc->uc_suppgids[1] = -1;
459 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
460 identity = mdt_identity_get(mdt->mdt_identity_cache,
462 if (IS_ERR(identity)) {
463 if (unlikely(PTR_ERR(identity) == -EREMCHG ||
464 uc->uc_cap & CFS_CAP_FS_MASK)) {
467 CDEBUG(D_SEC, "Deny access without identity: "
468 "uid %u\n", uc->uc_fsuid);
473 uc->uc_identity = identity;
475 /* process root_squash here. */
476 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
478 /* remove fs privilege for non-root user. */
479 if (uc->uc_fsuid && drop_fs_cap)
480 uc->uc_cap &= ~CFS_CAP_FS_MASK;
481 uc->uc_valid = UCRED_OLD;
482 ucred_set_jobid(info, uc);
483 ucred_set_nid(info, uc);
490 static int old_init_ucred(struct mdt_thread_info *info,
491 struct mdt_body *body, bool drop_fs_cap)
493 struct lu_ucred *uc = mdt_ucred(info);
494 struct lu_nodemap *nodemap;
498 nodemap = nodemap_get_from_exp(info->mti_exp);
500 RETURN(PTR_ERR(nodemap));
502 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
503 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
504 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
505 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
506 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
507 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
508 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
509 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
512 uc->uc_valid = UCRED_INVALID;
513 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
514 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
515 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
516 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
517 uc->uc_suppgids[0] = body->mbo_suppgid;
518 uc->uc_suppgids[1] = -1;
520 uc->uc_cap = body->mbo_capability;
522 rc = old_init_ucred_common(info, nodemap, drop_fs_cap);
523 nodemap_putref(nodemap);
528 static int old_init_ucred_reint(struct mdt_thread_info *info)
530 struct lu_ucred *uc = mdt_ucred(info);
531 struct lu_nodemap *nodemap;
535 nodemap = nodemap_get_from_exp(info->mti_exp);
537 RETURN(PTR_ERR(nodemap));
541 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
542 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
543 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
544 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
546 uc->uc_valid = UCRED_INVALID;
547 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
548 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
551 rc = old_init_ucred_common(info, nodemap, true); /* drop_fs_cap=true */
552 nodemap_putref(nodemap);
557 static inline int __mdt_init_ucred(struct mdt_thread_info *info,
558 struct mdt_body *body,
561 struct ptlrpc_request *req = mdt_info_req(info);
562 struct lu_ucred *uc = mdt_ucred(info);
565 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
568 mdt_exit_ucred(info);
570 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
571 return old_init_ucred(info, body, drop_fs_cap);
573 return new_init_ucred(info, BODY_INIT, body, drop_fs_cap);
576 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
578 return __mdt_init_ucred(info, body, true);
581 /* LU-6528 when "no_subtree_check" is set for NFS export, nfsd_set_fh_dentry()
582 * doesn't set correct fsuid explicitely, but raise capability to allow
583 * exportfs_decode_fh() to reconnect disconnected dentry into dcache. So for
584 * lookup (i.e. intent_getattr), we should keep FS capability, otherwise it
585 * will fail permission check. */
586 int mdt_init_ucred_intent_getattr(struct mdt_thread_info *info,
587 struct mdt_body *body)
589 return __mdt_init_ucred(info, body, false);
592 int mdt_init_ucred_reint(struct mdt_thread_info *info)
594 struct ptlrpc_request *req = mdt_info_req(info);
595 struct lu_ucred *uc = mdt_ucred(info);
596 struct md_attr *ma = &info->mti_attr;
599 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
602 /* LU-5564: for normal close request, skip permission check */
603 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE &&
604 !(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
605 uc->uc_cap |= CFS_CAP_FS_MASK;
607 mdt_exit_ucred(info);
609 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
610 return old_init_ucred_reint(info);
612 return new_init_ucred(info, REC_INIT, NULL, true);
615 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
616 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
618 const struct lov_ost_data_v1 *lod;
619 __u32 lmm_magic = le32_to_cpu(lmm->lmm_magic);
623 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
626 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
627 POSTID(&lmm->lmm_oi), lmm_magic,
628 le32_to_cpu(lmm->lmm_pattern));
630 /* No support for compount layouts yet */
631 if (lmm_magic != LOV_MAGIC_V1 && lmm_magic != LOV_MAGIC_V3)
634 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
635 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
636 le32_to_cpu(lmm->lmm_stripe_size), count);
638 /* If it's a directory or a released file, then there are
639 * no actual objects to print, so bail out. */
640 if (valid & OBD_MD_FLDIREA ||
641 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
644 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
645 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
648 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
649 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
650 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
654 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
656 const struct lmv_mds_md_v1 *lmm1;
659 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
662 lmm1 = &lmv->lmv_md_v1;
664 "magic 0x%08X, master %#X stripe_count %#x hash_type %#x\n",
665 le32_to_cpu(lmm1->lmv_magic),
666 le32_to_cpu(lmm1->lmv_master_mdt_index),
667 le32_to_cpu(lmm1->lmv_stripe_count),
668 le32_to_cpu(lmm1->lmv_hash_type));
670 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
673 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
676 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
677 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
681 /* Shrink and/or grow reply buffers */
682 int mdt_fix_reply(struct mdt_thread_info *info)
684 struct req_capsule *pill = info->mti_pill;
685 struct mdt_body *body;
686 int md_size, md_packed = 0;
691 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
692 LASSERT(body != NULL);
694 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
696 md_size = body->mbo_eadatasize;
700 acl_size = body->mbo_aclsize;
702 /* this replay - not send info to client */
703 if (info->mti_spec.no_create) {
708 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
713 &RMF_ACL, or &RMF_LOGCOOKIES
714 (optional) &RMF_CAPA1,
715 (optional) &RMF_CAPA2,
716 (optional) something else
719 /* MDT_MD buffer may be bigger than packed value, let's shrink all
720 * buffers before growing it */
721 if (info->mti_big_lmm_used) {
722 /* big_lmm buffer may be used even without packing the result
723 * into reply, just for internal server needs */
724 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
725 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
728 /* free big lmm if md_size is not needed */
729 if (md_size == 0 || md_packed == 0) {
730 info->mti_big_lmm_used = 0;
732 /* buffer must be allocated separately */
733 LASSERT(info->mti_attr.ma_lmm !=
734 req_capsule_server_get(pill, &RMF_MDT_MD));
735 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
737 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
738 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
741 if (info->mti_big_acl_used) {
743 info->mti_big_acl_used = 0;
745 req_capsule_shrink(pill, &RMF_ACL, 0, RCL_SERVER);
746 } else if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER)) {
747 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
748 } else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
749 req_capsule_shrink(pill, &RMF_LOGCOOKIES, acl_size, RCL_SERVER);
752 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
753 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
754 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
756 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
757 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
758 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
761 * Some more field should be shrinked if needed.
762 * This should be done by those who added fields to reply message.
765 /* Grow MD buffer if needed finally */
766 if (info->mti_big_lmm_used) {
769 LASSERT(md_size > md_packed);
770 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
771 md_size - md_packed);
772 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
774 /* we can't answer with proper LOV EA, drop flags,
775 * the rc is also returned so this request is
776 * considered as failed */
777 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
778 /* don't return transno along with error */
779 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
781 /* now we need to pack right LOV/LMV EA */
782 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
783 if (info->mti_attr.ma_valid & MA_LOV) {
784 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
786 info->mti_attr.ma_lmm_size);
787 memcpy(lmm, info->mti_attr.ma_lmm,
788 info->mti_attr.ma_lmm_size);
789 } else if (info->mti_attr.ma_valid & MA_LMV) {
790 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
792 info->mti_attr.ma_lmv_size);
793 memcpy(lmm, info->mti_attr.ma_lmv,
794 info->mti_attr.ma_lmv_size);
798 /* update mdt_max_mdsize so clients will be aware about that */
799 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
800 info->mti_mdt->mdt_max_mdsize =
801 info->mti_attr.ma_lmm_size;
802 info->mti_big_lmm_used = 0;
805 if (info->mti_big_acl_used) {
806 CDEBUG(D_INFO, "Enlarge reply ACL buffer to %d bytes\n",
809 rc = req_capsule_server_grow(pill, &RMF_ACL, acl_size);
811 body->mbo_valid &= ~OBD_MD_FLACL;
813 void *acl = req_capsule_server_get(pill, &RMF_ACL);
815 memcpy(acl, info->mti_big_acl, acl_size);
818 info->mti_big_acl_used = 0;
825 /* if object is dying, pack the lov/llog data,
826 * parameter info->mti_attr should be valid at this point!
827 * Also implements RAoLU policy */
828 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
831 struct mdt_body *repbody = NULL;
832 const struct lu_attr *la = &ma->ma_attr;
833 struct coordinator *cdt = &info->mti_mdt->mdt_coordinator;
836 struct hsm_action_item hai = {
837 .hai_len = sizeof(hai),
838 .hai_action = HSMA_REMOVE,
839 .hai_extent.length = -1,
848 if (mdt_info_req(info) != NULL) {
849 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
850 LASSERT(repbody != NULL);
852 CDEBUG(D_INFO, "not running in a request/reply context\n");
855 if ((ma->ma_valid & MA_INODE) && repbody != NULL)
856 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
858 if (ma->ma_valid & MA_LOV) {
859 CERROR("No need in LOV EA upon unlink\n");
863 repbody->mbo_eadatasize = 0;
865 /* Only check unlinked and archived if RAoLU and upon last close */
866 if (!cdt->cdt_remove_archive_on_last_unlink ||
867 atomic_read(&mo->mot_open_count) != 0)
870 /* mdt_attr_get_complex will clear ma_valid, so check here first */
871 if ((ma->ma_valid & MA_INODE) && (ma->ma_attr.la_nlink != 0))
874 if ((ma->ma_valid & MA_HSM) && (!(ma->ma_hsm.mh_flags & HS_EXISTS)))
877 need |= (MA_INODE | MA_HSM) & ~ma->ma_valid;
879 /* ma->ma_valid is missing either MA_INODE, MA_HSM, or both,
880 * try setting them */
882 rc = mdt_attr_get_complex(info, mo, ma);
884 CERROR("%s: unable to fetch missing attributes of"
885 DFID": rc=%d\n", mdt_obd_name(info->mti_mdt),
886 PFID(mdt_object_fid(mo)), rc);
890 if (need & MA_INODE) {
891 if (ma->ma_valid & MA_INODE) {
892 if (ma->ma_attr.la_nlink != 0)
900 if (ma->ma_valid & MA_HSM) {
901 if (!(ma->ma_hsm.mh_flags & HS_EXISTS))
909 /* RAoLU policy is active, last close on file has occured,
910 * file is unlinked, file is archived, so create remove request
912 * If CDT is not running, requests will be logged for later. */
913 compound_id = atomic_inc_return(&cdt->cdt_compound_id);
914 if (ma->ma_hsm.mh_arch_id != 0)
915 archive_id = ma->ma_hsm.mh_arch_id;
917 archive_id = cdt->cdt_default_archive_id;
919 hai.hai_fid = *mdt_object_fid(mo);
921 rc = mdt_agent_record_add(info->mti_env, info->mti_mdt,
922 compound_id, archive_id, 0, &hai);
924 CERROR("%s: unable to add HSM remove request for "DFID
925 ": rc=%d\n", mdt_obd_name(info->mti_mdt),
926 PFID(mdt_object_fid(mo)), rc);
931 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
937 if (in & MDS_ATTR_MODE)
939 if (in & MDS_ATTR_UID)
941 if (in & MDS_ATTR_GID)
943 if (in & MDS_ATTR_SIZE)
945 if (in & MDS_ATTR_BLOCKS)
947 if (in & MDS_ATTR_ATIME_SET)
949 if (in & MDS_ATTR_CTIME_SET)
951 if (in & MDS_ATTR_MTIME_SET)
953 if (in & MDS_ATTR_ATTR_FLAG)
955 if (in & MDS_ATTR_KILL_SUID)
957 if (in & MDS_ATTR_KILL_SGID)
959 if (in & MDS_ATTR_PROJID)
962 if (in & MDS_ATTR_FROM_OPEN)
963 rr->rr_flags |= MRF_OPEN_TRUNC;
964 if (in & MDS_OPEN_OWNEROVERRIDE)
965 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
966 if (in & MDS_ATTR_FORCE)
967 ma->ma_attr_flags |= MDS_PERM_BYPASS;
969 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID | MDS_ATTR_PROJID |
970 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
971 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
972 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
973 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
974 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
976 CERROR("Unknown attr bits: %#llx\n", in);
982 int mdt_name_unpack(struct req_capsule *pill,
983 const struct req_msg_field *field,
985 enum mdt_name_flags flags)
987 ln->ln_name = req_capsule_client_get(pill, field);
988 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
990 if (!lu_name_is_valid(ln)) {
997 if ((flags & MNF_FIX_ANON) &&
998 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
999 /* Newer (3.x) kernels use a name of "/" for the
1000 * "anonymous" disconnected dentries from NFS
1001 * filehandle conversion. See d_obtain_alias(). */
1009 static int mdt_file_secctx_unpack(struct req_capsule *pill,
1010 const char **secctx_name,
1011 void **secctx, size_t *secctx_size)
1016 *secctx_name = NULL;
1020 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT) ||
1021 !req_capsule_field_present(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT))
1024 name_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX_NAME,
1029 name = req_capsule_client_get(pill, &RMF_FILE_SECCTX_NAME);
1030 if (strnlen(name, name_size) != name_size - 1)
1033 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX, RCL_CLIENT) ||
1034 !req_capsule_field_present(pill, &RMF_FILE_SECCTX, RCL_CLIENT))
1037 *secctx_name = name;
1038 *secctx = req_capsule_client_get(pill, &RMF_FILE_SECCTX);
1039 *secctx_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX, RCL_CLIENT);
1044 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
1046 struct lu_ucred *uc = mdt_ucred(info);
1047 struct md_attr *ma = &info->mti_attr;
1048 struct lu_attr *la = &ma->ma_attr;
1049 struct req_capsule *pill = info->mti_pill;
1050 struct mdt_reint_record *rr = &info->mti_rr;
1051 struct mdt_rec_setattr *rec;
1052 struct lu_nodemap *nodemap;
1056 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1057 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1061 /* This prior initialization is needed for old_init_ucred_reint() */
1062 uc->uc_fsuid = rec->sa_fsuid;
1063 uc->uc_fsgid = rec->sa_fsgid;
1064 uc->uc_cap = rec->sa_cap;
1065 uc->uc_suppgids[0] = rec->sa_suppgid;
1066 uc->uc_suppgids[1] = -1;
1068 rr->rr_fid1 = &rec->sa_fid;
1069 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
1070 la->la_mode = rec->sa_mode;
1071 la->la_flags = rec->sa_attr_flags;
1073 nodemap = nodemap_get_from_exp(info->mti_exp);
1074 if (IS_ERR(nodemap))
1075 RETURN(PTR_ERR(nodemap));
1077 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
1078 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
1079 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
1080 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
1081 la->la_projid = rec->sa_projid;
1082 nodemap_putref(nodemap);
1084 la->la_size = rec->sa_size;
1085 la->la_blocks = rec->sa_blocks;
1086 la->la_ctime = rec->sa_ctime;
1087 la->la_atime = rec->sa_atime;
1088 la->la_mtime = rec->sa_mtime;
1089 ma->ma_valid = MA_INODE;
1091 if (rec->sa_bias & MDS_DATA_MODIFIED)
1092 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
1094 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
1096 ma->ma_attr_flags &= ~MDS_CLOSE_INTENT;
1097 ma->ma_attr_flags |= rec->sa_bias & MDS_CLOSE_INTENT;
1101 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
1103 struct req_capsule *pill = info->mti_pill;
1104 struct mdt_ioepoch *ioepoch;
1107 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
1108 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
1112 if (ioepoch == NULL)
1115 info->mti_close_handle = ioepoch->mio_handle;
1120 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
1121 struct req_capsule *pill = info->mti_pill;
1123 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
1124 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
1125 if (info->mti_dlm_req == NULL)
1132 static int mdt_setattr_unpack(struct mdt_thread_info *info)
1134 struct mdt_reint_record *rr = &info->mti_rr;
1135 struct md_attr *ma = &info->mti_attr;
1136 struct req_capsule *pill = info->mti_pill;
1140 rc = mdt_setattr_unpack_rec(info);
1144 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1145 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1146 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1148 if (rr->rr_eadatalen > 0) {
1149 const struct lmv_user_md *lum;
1151 lum = rr->rr_eadata;
1152 /* Sigh ma_valid(from req) does not indicate whether
1153 * it will set LOV/LMV EA, so we have to check magic */
1154 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1155 ma->ma_valid |= MA_LMV;
1156 ma->ma_lmv = (void *)rr->rr_eadata;
1157 ma->ma_lmv_size = rr->rr_eadatalen;
1159 ma->ma_valid |= MA_LOV;
1160 ma->ma_lmm = (void *)rr->rr_eadata;
1161 ma->ma_lmm_size = rr->rr_eadatalen;
1166 rc = mdt_dlmreq_unpack(info);
1170 static int mdt_close_intent_unpack(struct mdt_thread_info *info)
1172 struct md_attr *ma = &info->mti_attr;
1173 struct req_capsule *pill = info->mti_pill;
1176 if (!(ma->ma_attr_flags & MDS_CLOSE_INTENT))
1179 req_capsule_extend(pill, &RQF_MDS_CLOSE_INTENT);
1181 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1182 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1188 int mdt_close_unpack(struct mdt_thread_info *info)
1193 rc = mdt_close_handle_unpack(info);
1197 rc = mdt_setattr_unpack_rec(info);
1201 rc = mdt_close_intent_unpack(info);
1205 RETURN(mdt_init_ucred_reint(info));
1208 static int mdt_create_unpack(struct mdt_thread_info *info)
1210 struct lu_ucred *uc = mdt_ucred(info);
1211 struct mdt_rec_create *rec;
1212 struct lu_attr *attr = &info->mti_attr.ma_attr;
1213 struct mdt_reint_record *rr = &info->mti_rr;
1214 struct req_capsule *pill = info->mti_pill;
1215 struct md_op_spec *sp = &info->mti_spec;
1220 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1221 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1225 /* This prior initialization is needed for old_init_ucred_reint() */
1226 uc->uc_fsuid = rec->cr_fsuid;
1227 uc->uc_fsgid = rec->cr_fsgid;
1228 uc->uc_cap = rec->cr_cap;
1229 uc->uc_suppgids[0] = rec->cr_suppgid1;
1230 uc->uc_suppgids[1] = -1;
1231 uc->uc_umask = rec->cr_umask;
1233 rr->rr_fid1 = &rec->cr_fid1;
1234 rr->rr_fid2 = &rec->cr_fid2;
1235 attr->la_mode = rec->cr_mode;
1236 attr->la_rdev = rec->cr_rdev;
1237 attr->la_uid = rec->cr_fsuid;
1238 attr->la_gid = rec->cr_fsgid;
1239 attr->la_ctime = rec->cr_time;
1240 attr->la_mtime = rec->cr_time;
1241 attr->la_atime = rec->cr_time;
1242 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1243 LA_CTIME | LA_MTIME | LA_ATIME;
1244 memset(&sp->u, 0, sizeof(sp->u));
1245 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1247 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1251 if (S_ISLNK(attr->la_mode)) {
1252 const char *tgt = NULL;
1254 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1255 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1256 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1257 sp->u.sp_symname = tgt;
1262 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_ACL);
1263 if (S_ISDIR(attr->la_mode) &&
1264 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1265 sp->u.sp_ea.eadata =
1266 req_capsule_client_get(pill, &RMF_EADATA);
1267 sp->u.sp_ea.eadatalen =
1268 req_capsule_get_size(pill, &RMF_EADATA,
1270 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1274 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1275 &sp->sp_cr_file_secctx,
1276 &sp->sp_cr_file_secctx_size);
1280 rc = mdt_dlmreq_unpack(info);
1284 static int mdt_link_unpack(struct mdt_thread_info *info)
1286 struct lu_ucred *uc = mdt_ucred(info);
1287 struct mdt_rec_link *rec;
1288 struct lu_attr *attr = &info->mti_attr.ma_attr;
1289 struct mdt_reint_record *rr = &info->mti_rr;
1290 struct req_capsule *pill = info->mti_pill;
1295 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1296 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1300 /* This prior initialization is needed for old_init_ucred_reint() */
1301 uc->uc_fsuid = rec->lk_fsuid;
1302 uc->uc_fsgid = rec->lk_fsgid;
1303 uc->uc_cap = rec->lk_cap;
1304 uc->uc_suppgids[0] = rec->lk_suppgid1;
1305 uc->uc_suppgids[1] = rec->lk_suppgid2;
1307 attr->la_uid = rec->lk_fsuid;
1308 attr->la_gid = rec->lk_fsgid;
1309 rr->rr_fid1 = &rec->lk_fid1;
1310 rr->rr_fid2 = &rec->lk_fid2;
1311 attr->la_ctime = rec->lk_time;
1312 attr->la_mtime = rec->lk_time;
1313 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1315 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1319 rc = mdt_dlmreq_unpack(info);
1324 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1326 struct lu_ucred *uc = mdt_ucred(info);
1327 struct mdt_rec_unlink *rec;
1328 struct md_attr *ma = &info->mti_attr;
1329 struct lu_attr *attr = &info->mti_attr.ma_attr;
1330 struct mdt_reint_record *rr = &info->mti_rr;
1331 struct req_capsule *pill = info->mti_pill;
1336 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1337 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1341 /* This prior initialization is needed for old_init_ucred_reint() */
1342 uc->uc_fsuid = rec->ul_fsuid;
1343 uc->uc_fsgid = rec->ul_fsgid;
1344 uc->uc_cap = rec->ul_cap;
1345 uc->uc_suppgids[0] = rec->ul_suppgid1;
1346 uc->uc_suppgids[1] = -1;
1348 attr->la_uid = rec->ul_fsuid;
1349 attr->la_gid = rec->ul_fsgid;
1350 rr->rr_fid1 = &rec->ul_fid1;
1351 rr->rr_fid2 = &rec->ul_fid2;
1352 attr->la_ctime = rec->ul_time;
1353 attr->la_mtime = rec->ul_time;
1354 attr->la_mode = rec->ul_mode;
1355 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1357 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1361 if (rec->ul_bias & MDS_VTX_BYPASS)
1362 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1364 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1366 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1368 rc = mdt_dlmreq_unpack(info);
1372 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1374 info->mti_spec.sp_rm_entry = 1;
1375 return mdt_unlink_unpack(info);
1378 static int mdt_rename_unpack(struct mdt_thread_info *info)
1380 struct lu_ucred *uc = mdt_ucred(info);
1381 struct mdt_rec_rename *rec;
1382 struct md_attr *ma = &info->mti_attr;
1383 struct lu_attr *attr = &info->mti_attr.ma_attr;
1384 struct mdt_reint_record *rr = &info->mti_rr;
1385 struct req_capsule *pill = info->mti_pill;
1390 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1391 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1395 /* This prior initialization is needed for old_init_ucred_reint() */
1396 uc->uc_fsuid = rec->rn_fsuid;
1397 uc->uc_fsgid = rec->rn_fsgid;
1398 uc->uc_cap = rec->rn_cap;
1399 uc->uc_suppgids[0] = rec->rn_suppgid1;
1400 uc->uc_suppgids[1] = rec->rn_suppgid2;
1402 attr->la_uid = rec->rn_fsuid;
1403 attr->la_gid = rec->rn_fsgid;
1404 rr->rr_fid1 = &rec->rn_fid1;
1405 rr->rr_fid2 = &rec->rn_fid2;
1406 attr->la_ctime = rec->rn_time;
1407 attr->la_mtime = rec->rn_time;
1408 /* rename_tgt contains the mode already */
1409 attr->la_mode = rec->rn_mode;
1410 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1412 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1416 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1420 if (rec->rn_bias & MDS_VTX_BYPASS)
1421 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1423 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1425 if (rec->rn_bias & MDS_RENAME_MIGRATE) {
1426 req_capsule_extend(info->mti_pill, &RQF_MDS_REINT_MIGRATE);
1427 rc = mdt_close_handle_unpack(info);
1430 info->mti_spec.sp_migrate_close = 1;
1433 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1436 rc = mdt_dlmreq_unpack(info);
1442 * please see comment above LOV_MAGIC_V1_DEFINED
1444 void mdt_fix_lov_magic(struct mdt_thread_info *info, void *eadata)
1446 struct lov_user_md_v1 *v1 = eadata;
1450 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1451 if ((v1->lmm_magic & LOV_MAGIC_MASK) == LOV_MAGIC_MAGIC)
1452 v1->lmm_magic |= LOV_MAGIC_DEFINED;
1453 else if ((v1->lmm_magic & __swab32(LOV_MAGIC_MAGIC)) ==
1454 __swab32(LOV_MAGIC_MAGIC))
1455 v1->lmm_magic |= __swab32(LOV_MAGIC_DEFINED);
1459 static int mdt_open_unpack(struct mdt_thread_info *info)
1461 struct lu_ucred *uc = mdt_ucred(info);
1462 struct mdt_rec_create *rec;
1463 struct lu_attr *attr = &info->mti_attr.ma_attr;
1464 struct req_capsule *pill = info->mti_pill;
1465 struct mdt_reint_record *rr = &info->mti_rr;
1466 struct ptlrpc_request *req = mdt_info_req(info);
1467 struct md_op_spec *sp = &info->mti_spec;
1471 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1472 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1476 /* This prior initialization is needed for old_init_ucred_reint() */
1477 uc->uc_fsuid = rec->cr_fsuid;
1478 uc->uc_fsgid = rec->cr_fsgid;
1479 uc->uc_cap = rec->cr_cap;
1480 uc->uc_suppgids[0] = rec->cr_suppgid1;
1481 uc->uc_suppgids[1] = rec->cr_suppgid2;
1482 uc->uc_umask = rec->cr_umask;
1484 rr->rr_fid1 = &rec->cr_fid1;
1485 rr->rr_fid2 = &rec->cr_fid2;
1486 rr->rr_handle = &rec->cr_old_handle;
1487 attr->la_mode = rec->cr_mode;
1488 attr->la_rdev = rec->cr_rdev;
1489 attr->la_uid = rec->cr_fsuid;
1490 attr->la_gid = rec->cr_fsgid;
1491 attr->la_ctime = rec->cr_time;
1492 attr->la_mtime = rec->cr_time;
1493 attr->la_atime = rec->cr_time;
1494 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1495 LA_CTIME | LA_MTIME | LA_ATIME;
1496 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1497 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1498 /* Do not trigger ASSERTION if client miss to set such flags. */
1499 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1502 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1504 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1506 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1507 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1509 if (rr->rr_eadatalen > 0) {
1510 rr->rr_eadata = req_capsule_client_get(pill,
1512 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1513 sp->u.sp_ea.eadata = rr->rr_eadata;
1514 sp->no_create = !!req_is_replay(req);
1515 mdt_fix_lov_magic(info, rr->rr_eadata);
1519 * Client default md_size may be 0 right after client start,
1520 * until all osc are connected, set here just some reasonable
1521 * value to prevent misbehavior.
1523 if (rr->rr_eadatalen == 0 &&
1524 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1525 rr->rr_eadatalen = MIN_MD_SIZE;
1528 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1529 &sp->sp_cr_file_secctx,
1530 &sp->sp_cr_file_secctx_size);
1535 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1537 struct mdt_reint_record *rr = &info->mti_rr;
1538 struct lu_ucred *uc = mdt_ucred(info);
1539 struct lu_attr *attr = &info->mti_attr.ma_attr;
1540 struct req_capsule *pill = info->mti_pill;
1541 struct mdt_rec_setxattr *rec;
1546 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1547 sizeof(struct mdt_rec_reint));
1549 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1553 /* This prior initialization is needed for old_init_ucred_reint() */
1554 uc->uc_fsuid = rec->sx_fsuid;
1555 uc->uc_fsgid = rec->sx_fsgid;
1556 uc->uc_cap = rec->sx_cap;
1557 uc->uc_suppgids[0] = rec->sx_suppgid1;
1558 uc->uc_suppgids[1] = -1;
1560 rr->rr_opcode = rec->sx_opcode;
1561 rr->rr_fid1 = &rec->sx_fid;
1562 attr->la_valid = rec->sx_valid;
1563 attr->la_ctime = rec->sx_time;
1564 attr->la_size = rec->sx_size;
1565 attr->la_flags = rec->sx_flags;
1567 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1571 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1572 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1574 if (rr->rr_eadatalen > 0) {
1575 rr->rr_eadata = req_capsule_client_get(pill,
1577 if (rr->rr_eadata == NULL)
1580 rr->rr_eadata = NULL;
1582 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1583 CDEBUG(D_INFO, "no xattr data supplied\n");
1587 if (mdt_dlmreq_unpack(info) < 0)
1593 static int mdt_resync_unpack(struct mdt_thread_info *info)
1595 struct req_capsule *pill = info->mti_pill;
1596 struct mdt_reint_record *rr = &info->mti_rr;
1597 struct lu_ucred *uc = mdt_ucred(info);
1598 struct mdt_rec_resync *rec;
1601 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1602 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1606 /* This prior initialization is needed for old_init_ucred_reint() */
1607 uc->uc_fsuid = rec->rs_fsuid;
1608 uc->uc_fsgid = rec->rs_fsgid;
1609 uc->uc_cap = rec->rs_cap;
1611 rr->rr_fid1 = &rec->rs_fid;
1613 /* cookie doesn't need to be swapped but it has been swapped
1614 * in lustre_swab_mdt_rec_reint() as rr_mtime, so here it needs
1616 if (ptlrpc_req_need_swab(mdt_info_req(info)))
1617 __swab64s(&rec->rs_handle.cookie);
1618 rr->rr_handle = &rec->rs_handle;
1620 RETURN(mdt_dlmreq_unpack(info));
1623 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1625 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1626 [REINT_SETATTR] = mdt_setattr_unpack,
1627 [REINT_CREATE] = mdt_create_unpack,
1628 [REINT_LINK] = mdt_link_unpack,
1629 [REINT_UNLINK] = mdt_unlink_unpack,
1630 [REINT_RENAME] = mdt_rename_unpack,
1631 [REINT_OPEN] = mdt_open_unpack,
1632 [REINT_SETXATTR] = mdt_setxattr_unpack,
1633 [REINT_RMENTRY] = mdt_rmentry_unpack,
1634 [REINT_MIGRATE] = mdt_rename_unpack,
1635 [REINT_RESYNC] = mdt_resync_unpack,
1638 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1643 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1644 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1645 info->mti_rr.rr_opcode = op;
1646 rc = mdt_reint_unpackers[op](info);
1648 CERROR("Unexpected opcode %d\n", op);