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 <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 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;
609 __u32 lmm_magic = le32_to_cpu(lmm->lmm_magic);
613 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
616 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
617 POSTID(&lmm->lmm_oi), lmm_magic,
618 le32_to_cpu(lmm->lmm_pattern));
620 /* No support for compount layouts yet */
621 if (lmm_magic != LOV_MAGIC_V1 && lmm_magic != LOV_MAGIC_V3)
624 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
625 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
626 le32_to_cpu(lmm->lmm_stripe_size), count);
628 /* If it's a directory or a released file, then there are
629 * no actual objects to print, so bail out. */
630 if (valid & OBD_MD_FLDIREA ||
631 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
634 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
635 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
638 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
639 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
640 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
644 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
646 const struct lmv_mds_md_v1 *lmm1;
649 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
652 lmm1 = &lmv->lmv_md_v1;
654 "magic 0x%08X, master %#X stripe_count %#x hash_type %#x\n",
655 le32_to_cpu(lmm1->lmv_magic),
656 le32_to_cpu(lmm1->lmv_master_mdt_index),
657 le32_to_cpu(lmm1->lmv_stripe_count),
658 le32_to_cpu(lmm1->lmv_hash_type));
660 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
663 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
666 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
667 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
671 /* Shrink and/or grow reply buffers */
672 int mdt_fix_reply(struct mdt_thread_info *info)
674 struct req_capsule *pill = info->mti_pill;
675 struct mdt_body *body;
676 int md_size, md_packed = 0;
681 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
682 LASSERT(body != NULL);
684 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
686 md_size = body->mbo_eadatasize;
690 acl_size = body->mbo_aclsize;
692 /* this replay - not send info to client */
693 if (info->mti_spec.no_create) {
698 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
703 &RMF_ACL, or &RMF_LOGCOOKIES
704 (optional) &RMF_CAPA1,
705 (optional) &RMF_CAPA2,
706 (optional) something else
709 /* MDT_MD buffer may be bigger than packed value, let's shrink all
710 * buffers before growing it */
711 if (info->mti_big_lmm_used) {
712 /* big_lmm buffer may be used even without packing the result
713 * into reply, just for internal server needs */
714 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
715 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
718 /* free big lmm if md_size is not needed */
719 if (md_size == 0 || md_packed == 0) {
720 info->mti_big_lmm_used = 0;
722 /* buffer must be allocated separately */
723 LASSERT(info->mti_attr.ma_lmm !=
724 req_capsule_server_get(pill, &RMF_MDT_MD));
725 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
727 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
728 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
731 if (info->mti_big_acl_used) {
733 info->mti_big_acl_used = 0;
735 req_capsule_shrink(pill, &RMF_ACL, 0, RCL_SERVER);
736 } else if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER)) {
737 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
738 } else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
739 req_capsule_shrink(pill, &RMF_LOGCOOKIES, acl_size, RCL_SERVER);
742 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
743 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
744 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
746 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
747 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
748 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
751 * Some more field should be shrinked if needed.
752 * This should be done by those who added fields to reply message.
755 /* Grow MD buffer if needed finally */
756 if (info->mti_big_lmm_used) {
759 LASSERT(md_size > md_packed);
760 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
761 md_size - md_packed);
762 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
764 /* we can't answer with proper LOV EA, drop flags,
765 * the rc is also returned so this request is
766 * considered as failed */
767 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
768 /* don't return transno along with error */
769 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
771 /* now we need to pack right LOV/LMV EA */
772 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
773 if (info->mti_attr.ma_valid & MA_LOV) {
774 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
776 info->mti_attr.ma_lmm_size);
777 memcpy(lmm, info->mti_attr.ma_lmm,
778 info->mti_attr.ma_lmm_size);
779 } else if (info->mti_attr.ma_valid & MA_LMV) {
780 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
782 info->mti_attr.ma_lmv_size);
783 memcpy(lmm, info->mti_attr.ma_lmv,
784 info->mti_attr.ma_lmv_size);
788 /* update mdt_max_mdsize so clients will be aware about that */
789 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
790 info->mti_mdt->mdt_max_mdsize =
791 info->mti_attr.ma_lmm_size;
792 info->mti_big_lmm_used = 0;
795 if (info->mti_big_acl_used) {
796 CDEBUG(D_INFO, "Enlarge reply ACL buffer to %d bytes\n",
799 rc = req_capsule_server_grow(pill, &RMF_ACL, acl_size);
801 body->mbo_valid &= ~OBD_MD_FLACL;
803 void *acl = req_capsule_server_get(pill, &RMF_ACL);
805 memcpy(acl, info->mti_big_acl, acl_size);
808 info->mti_big_acl_used = 0;
815 /* if object is dying, pack the lov/llog data,
816 * parameter info->mti_attr should be valid at this point!
817 * Also implements RAoLU policy */
818 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
821 struct mdt_body *repbody = NULL;
822 const struct lu_attr *la = &ma->ma_attr;
823 struct coordinator *cdt = &info->mti_mdt->mdt_coordinator;
826 struct hsm_action_item hai = {
827 .hai_len = sizeof(hai),
828 .hai_action = HSMA_REMOVE,
829 .hai_extent.length = -1,
838 if (mdt_info_req(info) != NULL) {
839 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
840 LASSERT(repbody != NULL);
842 CDEBUG(D_INFO, "not running in a request/reply context\n");
845 if ((ma->ma_valid & MA_INODE) && repbody != NULL)
846 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
848 if (ma->ma_valid & MA_LOV) {
849 CERROR("No need in LOV EA upon unlink\n");
853 repbody->mbo_eadatasize = 0;
855 /* Only check unlinked and archived if RAoLU and upon last close */
856 if (!cdt->cdt_remove_archive_on_last_unlink ||
857 atomic_read(&mo->mot_open_count) != 0)
860 /* mdt_attr_get_complex will clear ma_valid, so check here first */
861 if ((ma->ma_valid & MA_INODE) && (ma->ma_attr.la_nlink != 0))
864 if ((ma->ma_valid & MA_HSM) && (!(ma->ma_hsm.mh_flags & HS_EXISTS)))
867 need |= (MA_INODE | MA_HSM) & ~ma->ma_valid;
869 /* ma->ma_valid is missing either MA_INODE, MA_HSM, or both,
870 * try setting them */
872 rc = mdt_attr_get_complex(info, mo, ma);
874 CERROR("%s: unable to fetch missing attributes of"
875 DFID": rc=%d\n", mdt_obd_name(info->mti_mdt),
876 PFID(mdt_object_fid(mo)), rc);
880 if (need & MA_INODE) {
881 if (ma->ma_valid & MA_INODE) {
882 if (ma->ma_attr.la_nlink != 0)
890 if (ma->ma_valid & MA_HSM) {
891 if (!(ma->ma_hsm.mh_flags & HS_EXISTS))
899 /* RAoLU policy is active, last close on file has occured,
900 * file is unlinked, file is archived, so create remove request
902 * If CDT is not running, requests will be logged for later. */
903 compound_id = atomic_inc_return(&cdt->cdt_compound_id);
904 if (ma->ma_hsm.mh_arch_id != 0)
905 archive_id = ma->ma_hsm.mh_arch_id;
907 archive_id = cdt->cdt_default_archive_id;
909 hai.hai_fid = *mdt_object_fid(mo);
911 rc = mdt_agent_record_add(info->mti_env, info->mti_mdt,
912 compound_id, archive_id, 0, &hai);
914 CERROR("%s: unable to add HSM remove request for "DFID
915 ": rc=%d\n", mdt_obd_name(info->mti_mdt),
916 PFID(mdt_object_fid(mo)), rc);
921 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
927 if (in & MDS_ATTR_MODE)
929 if (in & MDS_ATTR_UID)
931 if (in & MDS_ATTR_GID)
933 if (in & MDS_ATTR_SIZE)
935 if (in & MDS_ATTR_BLOCKS)
937 if (in & MDS_ATTR_ATIME_SET)
939 if (in & MDS_ATTR_CTIME_SET)
941 if (in & MDS_ATTR_MTIME_SET)
943 if (in & MDS_ATTR_ATTR_FLAG)
945 if (in & MDS_ATTR_KILL_SUID)
947 if (in & MDS_ATTR_KILL_SGID)
949 if (in & MDS_ATTR_PROJID)
952 if (in & MDS_ATTR_FROM_OPEN)
953 rr->rr_flags |= MRF_OPEN_TRUNC;
954 if (in & MDS_OPEN_OWNEROVERRIDE)
955 ma->ma_attr_flags |= MDS_OWNEROVERRIDE;
956 if (in & MDS_ATTR_FORCE)
957 ma->ma_attr_flags |= MDS_PERM_BYPASS;
959 in &= ~(MDS_ATTR_MODE | MDS_ATTR_UID | MDS_ATTR_GID | MDS_ATTR_PROJID |
960 MDS_ATTR_ATIME | MDS_ATTR_MTIME | MDS_ATTR_CTIME |
961 MDS_ATTR_ATIME_SET | MDS_ATTR_CTIME_SET | MDS_ATTR_MTIME_SET |
962 MDS_ATTR_SIZE | MDS_ATTR_BLOCKS | MDS_ATTR_ATTR_FLAG |
963 MDS_ATTR_FORCE | MDS_ATTR_KILL_SUID | MDS_ATTR_KILL_SGID |
964 MDS_ATTR_FROM_OPEN | MDS_OPEN_OWNEROVERRIDE);
966 CERROR("Unknown attr bits: %#llx\n", in);
972 int mdt_name_unpack(struct req_capsule *pill,
973 const struct req_msg_field *field,
975 enum mdt_name_flags flags)
977 ln->ln_name = req_capsule_client_get(pill, field);
978 ln->ln_namelen = req_capsule_get_size(pill, field, RCL_CLIENT) - 1;
980 if (!lu_name_is_valid(ln)) {
987 if ((flags & MNF_FIX_ANON) &&
988 ln->ln_namelen == 1 && ln->ln_name[0] == '/') {
989 /* Newer (3.x) kernels use a name of "/" for the
990 * "anonymous" disconnected dentries from NFS
991 * filehandle conversion. See d_obtain_alias(). */
999 static int mdt_file_secctx_unpack(struct req_capsule *pill,
1000 const char **secctx_name,
1001 void **secctx, size_t *secctx_size)
1006 *secctx_name = NULL;
1010 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT) ||
1011 !req_capsule_field_present(pill, &RMF_FILE_SECCTX_NAME, RCL_CLIENT))
1014 name_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX_NAME,
1019 name = req_capsule_client_get(pill, &RMF_FILE_SECCTX_NAME);
1020 if (strnlen(name, name_size) != name_size - 1)
1023 if (!req_capsule_has_field(pill, &RMF_FILE_SECCTX, RCL_CLIENT) ||
1024 !req_capsule_field_present(pill, &RMF_FILE_SECCTX, RCL_CLIENT))
1027 *secctx_name = name;
1028 *secctx = req_capsule_client_get(pill, &RMF_FILE_SECCTX);
1029 *secctx_size = req_capsule_get_size(pill, &RMF_FILE_SECCTX, RCL_CLIENT);
1034 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
1036 struct lu_ucred *uc = mdt_ucred(info);
1037 struct md_attr *ma = &info->mti_attr;
1038 struct lu_attr *la = &ma->ma_attr;
1039 struct req_capsule *pill = info->mti_pill;
1040 struct mdt_reint_record *rr = &info->mti_rr;
1041 struct mdt_rec_setattr *rec;
1042 struct lu_nodemap *nodemap;
1046 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1047 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1051 /* This prior initialization is needed for old_init_ucred_reint() */
1052 uc->uc_fsuid = rec->sa_fsuid;
1053 uc->uc_fsgid = rec->sa_fsgid;
1054 uc->uc_cap = rec->sa_cap;
1055 uc->uc_suppgids[0] = rec->sa_suppgid;
1056 uc->uc_suppgids[1] = -1;
1058 rr->rr_fid1 = &rec->sa_fid;
1059 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
1060 la->la_mode = rec->sa_mode;
1061 la->la_flags = rec->sa_attr_flags;
1063 nodemap = nodemap_get_from_exp(info->mti_exp);
1064 if (IS_ERR(nodemap))
1065 RETURN(PTR_ERR(nodemap));
1067 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
1068 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
1069 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
1070 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
1071 la->la_projid = rec->sa_projid;
1072 nodemap_putref(nodemap);
1074 la->la_size = rec->sa_size;
1075 la->la_blocks = rec->sa_blocks;
1076 la->la_ctime = rec->sa_ctime;
1077 la->la_atime = rec->sa_atime;
1078 la->la_mtime = rec->sa_mtime;
1079 ma->ma_valid = MA_INODE;
1081 if (rec->sa_bias & MDS_DATA_MODIFIED)
1082 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
1084 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
1086 ma->ma_attr_flags &= ~MDS_CLOSE_INTENT;
1087 ma->ma_attr_flags |= rec->sa_bias & MDS_CLOSE_INTENT;
1091 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
1093 struct req_capsule *pill = info->mti_pill;
1094 struct mdt_ioepoch *ioepoch;
1097 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
1098 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
1102 if (ioepoch == NULL)
1105 info->mti_close_handle = ioepoch->mio_handle;
1110 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
1111 struct req_capsule *pill = info->mti_pill;
1113 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
1114 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
1115 if (info->mti_dlm_req == NULL)
1122 static int mdt_setattr_unpack(struct mdt_thread_info *info)
1124 struct mdt_reint_record *rr = &info->mti_rr;
1125 struct md_attr *ma = &info->mti_attr;
1126 struct req_capsule *pill = info->mti_pill;
1130 rc = mdt_setattr_unpack_rec(info);
1134 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1135 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1136 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1138 if (rr->rr_eadatalen > 0) {
1139 const struct lmv_user_md *lum;
1141 lum = rr->rr_eadata;
1142 /* Sigh ma_valid(from req) does not indicate whether
1143 * it will set LOV/LMV EA, so we have to check magic */
1144 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1145 ma->ma_valid |= MA_LMV;
1146 ma->ma_lmv = (void *)rr->rr_eadata;
1147 ma->ma_lmv_size = rr->rr_eadatalen;
1149 ma->ma_valid |= MA_LOV;
1150 ma->ma_lmm = (void *)rr->rr_eadata;
1151 ma->ma_lmm_size = rr->rr_eadatalen;
1156 rc = mdt_dlmreq_unpack(info);
1160 static int mdt_close_intent_unpack(struct mdt_thread_info *info)
1162 struct md_attr *ma = &info->mti_attr;
1163 struct req_capsule *pill = info->mti_pill;
1166 if (!(ma->ma_attr_flags & MDS_CLOSE_INTENT))
1169 req_capsule_extend(pill, &RQF_MDS_CLOSE_INTENT);
1171 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1172 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1178 int mdt_close_unpack(struct mdt_thread_info *info)
1183 rc = mdt_close_handle_unpack(info);
1187 rc = mdt_setattr_unpack_rec(info);
1191 rc = mdt_close_intent_unpack(info);
1195 RETURN(mdt_init_ucred_reint(info));
1198 static int mdt_create_unpack(struct mdt_thread_info *info)
1200 struct lu_ucred *uc = mdt_ucred(info);
1201 struct mdt_rec_create *rec;
1202 struct lu_attr *attr = &info->mti_attr.ma_attr;
1203 struct mdt_reint_record *rr = &info->mti_rr;
1204 struct req_capsule *pill = info->mti_pill;
1205 struct md_op_spec *sp = &info->mti_spec;
1210 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1211 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1215 /* This prior initialization is needed for old_init_ucred_reint() */
1216 uc->uc_fsuid = rec->cr_fsuid;
1217 uc->uc_fsgid = rec->cr_fsgid;
1218 uc->uc_cap = rec->cr_cap;
1219 uc->uc_suppgids[0] = rec->cr_suppgid1;
1220 uc->uc_suppgids[1] = -1;
1221 uc->uc_umask = rec->cr_umask;
1223 rr->rr_fid1 = &rec->cr_fid1;
1224 rr->rr_fid2 = &rec->cr_fid2;
1225 attr->la_mode = rec->cr_mode;
1226 attr->la_rdev = rec->cr_rdev;
1227 attr->la_uid = rec->cr_fsuid;
1228 attr->la_gid = rec->cr_fsgid;
1229 attr->la_ctime = rec->cr_time;
1230 attr->la_mtime = rec->cr_time;
1231 attr->la_atime = rec->cr_time;
1232 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1233 LA_CTIME | LA_MTIME | LA_ATIME;
1234 memset(&sp->u, 0, sizeof(sp->u));
1235 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1237 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1241 if (S_ISLNK(attr->la_mode)) {
1242 const char *tgt = NULL;
1244 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1245 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1246 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1247 sp->u.sp_symname = tgt;
1252 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_ACL);
1253 if (S_ISDIR(attr->la_mode) &&
1254 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1255 sp->u.sp_ea.eadata =
1256 req_capsule_client_get(pill, &RMF_EADATA);
1257 sp->u.sp_ea.eadatalen =
1258 req_capsule_get_size(pill, &RMF_EADATA,
1260 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1264 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1265 &sp->sp_cr_file_secctx,
1266 &sp->sp_cr_file_secctx_size);
1270 rc = mdt_dlmreq_unpack(info);
1274 static int mdt_link_unpack(struct mdt_thread_info *info)
1276 struct lu_ucred *uc = mdt_ucred(info);
1277 struct mdt_rec_link *rec;
1278 struct lu_attr *attr = &info->mti_attr.ma_attr;
1279 struct mdt_reint_record *rr = &info->mti_rr;
1280 struct req_capsule *pill = info->mti_pill;
1285 CLASSERT(sizeof(*rec) == 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;
1326 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1327 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1331 /* This prior initialization is needed for old_init_ucred_reint() */
1332 uc->uc_fsuid = rec->ul_fsuid;
1333 uc->uc_fsgid = rec->ul_fsgid;
1334 uc->uc_cap = rec->ul_cap;
1335 uc->uc_suppgids[0] = rec->ul_suppgid1;
1336 uc->uc_suppgids[1] = -1;
1338 attr->la_uid = rec->ul_fsuid;
1339 attr->la_gid = rec->ul_fsgid;
1340 rr->rr_fid1 = &rec->ul_fid1;
1341 rr->rr_fid2 = &rec->ul_fid2;
1342 attr->la_ctime = rec->ul_time;
1343 attr->la_mtime = rec->ul_time;
1344 attr->la_mode = rec->ul_mode;
1345 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1347 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1351 if (rec->ul_bias & MDS_VTX_BYPASS)
1352 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1354 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1356 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1358 rc = mdt_dlmreq_unpack(info);
1362 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1364 info->mti_spec.sp_rm_entry = 1;
1365 return mdt_unlink_unpack(info);
1368 static int mdt_rename_unpack(struct mdt_thread_info *info)
1370 struct lu_ucred *uc = mdt_ucred(info);
1371 struct mdt_rec_rename *rec;
1372 struct md_attr *ma = &info->mti_attr;
1373 struct lu_attr *attr = &info->mti_attr.ma_attr;
1374 struct mdt_reint_record *rr = &info->mti_rr;
1375 struct req_capsule *pill = info->mti_pill;
1380 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1381 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1385 /* This prior initialization is needed for old_init_ucred_reint() */
1386 uc->uc_fsuid = rec->rn_fsuid;
1387 uc->uc_fsgid = rec->rn_fsgid;
1388 uc->uc_cap = rec->rn_cap;
1389 uc->uc_suppgids[0] = rec->rn_suppgid1;
1390 uc->uc_suppgids[1] = rec->rn_suppgid2;
1392 attr->la_uid = rec->rn_fsuid;
1393 attr->la_gid = rec->rn_fsgid;
1394 rr->rr_fid1 = &rec->rn_fid1;
1395 rr->rr_fid2 = &rec->rn_fid2;
1396 attr->la_ctime = rec->rn_time;
1397 attr->la_mtime = rec->rn_time;
1398 /* rename_tgt contains the mode already */
1399 attr->la_mode = rec->rn_mode;
1400 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1402 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1406 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1410 if (rec->rn_bias & MDS_VTX_BYPASS)
1411 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1413 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1415 if (rec->rn_bias & MDS_RENAME_MIGRATE) {
1416 req_capsule_extend(info->mti_pill, &RQF_MDS_REINT_MIGRATE);
1417 rc = mdt_close_handle_unpack(info);
1420 info->mti_spec.sp_migrate_close = 1;
1423 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1426 rc = mdt_dlmreq_unpack(info);
1432 * please see comment above LOV_MAGIC_V1_DEFINED
1434 void mdt_fix_lov_magic(struct mdt_thread_info *info, void *eadata)
1436 struct lov_user_md_v1 *v1 = eadata;
1440 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1441 if ((v1->lmm_magic & LOV_MAGIC_MASK) == LOV_MAGIC_MAGIC)
1442 v1->lmm_magic |= LOV_MAGIC_DEFINED;
1443 else if ((v1->lmm_magic & __swab32(LOV_MAGIC_MAGIC)) ==
1444 __swab32(LOV_MAGIC_MAGIC))
1445 v1->lmm_magic |= __swab32(LOV_MAGIC_DEFINED);
1449 static int mdt_open_unpack(struct mdt_thread_info *info)
1451 struct lu_ucred *uc = mdt_ucred(info);
1452 struct mdt_rec_create *rec;
1453 struct lu_attr *attr = &info->mti_attr.ma_attr;
1454 struct req_capsule *pill = info->mti_pill;
1455 struct mdt_reint_record *rr = &info->mti_rr;
1456 struct ptlrpc_request *req = mdt_info_req(info);
1457 struct md_op_spec *sp = &info->mti_spec;
1461 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1462 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1466 /* This prior initialization is needed for old_init_ucred_reint() */
1467 uc->uc_fsuid = rec->cr_fsuid;
1468 uc->uc_fsgid = rec->cr_fsgid;
1469 uc->uc_cap = rec->cr_cap;
1470 uc->uc_suppgids[0] = rec->cr_suppgid1;
1471 uc->uc_suppgids[1] = rec->cr_suppgid2;
1472 uc->uc_umask = rec->cr_umask;
1474 rr->rr_fid1 = &rec->cr_fid1;
1475 rr->rr_fid2 = &rec->cr_fid2;
1476 rr->rr_handle = &rec->cr_old_handle;
1477 attr->la_mode = rec->cr_mode;
1478 attr->la_rdev = rec->cr_rdev;
1479 attr->la_uid = rec->cr_fsuid;
1480 attr->la_gid = rec->cr_fsgid;
1481 attr->la_ctime = rec->cr_time;
1482 attr->la_mtime = rec->cr_time;
1483 attr->la_atime = rec->cr_time;
1484 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1485 LA_CTIME | LA_MTIME | LA_ATIME;
1486 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1487 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1488 /* Do not trigger ASSERTION if client miss to set such flags. */
1489 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1492 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1494 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1496 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1497 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1499 if (rr->rr_eadatalen > 0) {
1500 rr->rr_eadata = req_capsule_client_get(pill,
1502 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1503 sp->u.sp_ea.eadata = rr->rr_eadata;
1504 sp->no_create = !!req_is_replay(req);
1505 mdt_fix_lov_magic(info, rr->rr_eadata);
1509 * Client default md_size may be 0 right after client start,
1510 * until all osc are connected, set here just some reasonable
1511 * value to prevent misbehavior.
1513 if (rr->rr_eadatalen == 0 &&
1514 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1515 rr->rr_eadatalen = MIN_MD_SIZE;
1518 rc = mdt_file_secctx_unpack(pill, &sp->sp_cr_file_secctx_name,
1519 &sp->sp_cr_file_secctx,
1520 &sp->sp_cr_file_secctx_size);
1525 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1527 struct mdt_reint_record *rr = &info->mti_rr;
1528 struct lu_ucred *uc = mdt_ucred(info);
1529 struct lu_attr *attr = &info->mti_attr.ma_attr;
1530 struct req_capsule *pill = info->mti_pill;
1531 struct mdt_rec_setxattr *rec;
1536 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1537 sizeof(struct mdt_rec_reint));
1539 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1543 /* This prior initialization is needed for old_init_ucred_reint() */
1544 uc->uc_fsuid = rec->sx_fsuid;
1545 uc->uc_fsgid = rec->sx_fsgid;
1546 uc->uc_cap = rec->sx_cap;
1547 uc->uc_suppgids[0] = rec->sx_suppgid1;
1548 uc->uc_suppgids[1] = -1;
1550 rr->rr_opcode = rec->sx_opcode;
1551 rr->rr_fid1 = &rec->sx_fid;
1552 attr->la_valid = rec->sx_valid;
1553 attr->la_ctime = rec->sx_time;
1554 attr->la_size = rec->sx_size;
1555 attr->la_flags = rec->sx_flags;
1557 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1561 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1562 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1564 if (rr->rr_eadatalen > 0) {
1565 rr->rr_eadata = req_capsule_client_get(pill,
1567 if (rr->rr_eadata == NULL)
1570 rr->rr_eadata = NULL;
1572 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1573 CDEBUG(D_INFO, "no xattr data supplied\n");
1577 if (mdt_dlmreq_unpack(info) < 0)
1583 static int mdt_resync_unpack(struct mdt_thread_info *info)
1585 struct req_capsule *pill = info->mti_pill;
1586 struct mdt_reint_record *rr = &info->mti_rr;
1587 struct lu_ucred *uc = mdt_ucred(info);
1588 struct mdt_rec_resync *rec;
1591 CLASSERT(sizeof(*rec) == sizeof(struct mdt_rec_reint));
1592 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1596 /* This prior initialization is needed for old_init_ucred_reint() */
1597 uc->uc_fsuid = rec->rs_fsuid;
1598 uc->uc_fsgid = rec->rs_fsgid;
1599 uc->uc_cap = rec->rs_cap;
1601 rr->rr_fid1 = &rec->rs_fid;
1603 /* cookie doesn't need to be swapped but it has been swapped
1604 * in lustre_swab_mdt_rec_reint() as rr_mtime, so here it needs
1606 if (ptlrpc_req_need_swab(mdt_info_req(info)))
1607 __swab64s(&rec->rs_handle.cookie);
1608 rr->rr_handle = &rec->rs_handle;
1610 RETURN(mdt_dlmreq_unpack(info));
1613 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1615 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1616 [REINT_SETATTR] = mdt_setattr_unpack,
1617 [REINT_CREATE] = mdt_create_unpack,
1618 [REINT_LINK] = mdt_link_unpack,
1619 [REINT_UNLINK] = mdt_unlink_unpack,
1620 [REINT_RENAME] = mdt_rename_unpack,
1621 [REINT_OPEN] = mdt_open_unpack,
1622 [REINT_SETXATTR] = mdt_setxattr_unpack,
1623 [REINT_RMENTRY] = mdt_rmentry_unpack,
1624 [REINT_MIGRATE] = mdt_rename_unpack,
1625 [REINT_RESYNC] = mdt_resync_unpack,
1628 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1633 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1634 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1635 info->mti_rr.rr_opcode = op;
1636 rc = mdt_reint_unpackers[op](info);
1638 CERROR("Unexpected opcode %d\n", op);