4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_lib.c
38 * Lustre Metadata Target (mdt) request unpacking helper.
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Fan Yong <fanyong@clusterfs.com>
49 #define DEBUG_SUBSYSTEM S_MDS
51 #include <linux/user_namespace.h>
52 #ifdef HAVE_UIDGID_HEADER
53 # include <linux/uidgid.h>
55 #include "mdt_internal.h"
56 #include <lnet/nidstr.h>
57 #include <lustre_nodemap.h>
59 typedef enum ucred_init_type {
65 void mdt_exit_ucred(struct mdt_thread_info *info)
67 struct lu_ucred *uc = mdt_ucred(info);
68 struct mdt_device *mdt = info->mti_mdt;
71 if (uc->uc_valid != UCRED_INIT) {
72 uc->uc_suppgids[0] = uc->uc_suppgids[1] = -1;
74 put_group_info(uc->uc_ginfo);
77 if (uc->uc_identity) {
78 mdt_identity_put(mdt->mdt_identity_cache,
80 uc->uc_identity = NULL;
82 uc->uc_valid = UCRED_INIT;
86 static int match_nosquash_list(struct rw_semaphore *sem,
87 struct list_head *nidlist,
93 rc = cfs_match_nid(peernid, nidlist);
98 /* root_squash for inter-MDS operations */
99 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid)
101 struct lu_ucred *ucred = mdt_ucred(info);
102 struct root_squash_info *squash = &info->mti_mdt->mdt_squash;
105 LASSERT(ucred != NULL);
106 if (!squash->rsi_uid || ucred->uc_fsuid)
109 if (match_nosquash_list(&squash->rsi_sem,
110 &squash->rsi_nosquash_nids,
112 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
113 libcfs_nid2str(peernid));
117 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
118 libcfs_nid2str(peernid),
119 ucred->uc_fsuid, ucred->uc_fsgid, ucred->uc_cap,
120 squash->rsi_uid, squash->rsi_gid, 0);
122 ucred->uc_fsuid = squash->rsi_uid;
123 ucred->uc_fsgid = squash->rsi_gid;
125 ucred->uc_suppgids[0] = -1;
126 ucred->uc_suppgids[1] = -1;
131 static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc)
133 struct ptlrpc_request *req = mdt_info_req(info);
134 const char *jobid = mdt_req_get_jobid(req);
136 /* set jobid if specified. */
138 strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid));
140 uc->uc_jobid[0] = '\0';
143 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
144 void *buf, bool drop_fs_cap)
146 struct ptlrpc_request *req = mdt_info_req(info);
147 struct mdt_device *mdt = info->mti_mdt;
148 struct ptlrpc_user_desc *pud = req->rq_user_desc;
149 struct lu_ucred *ucred = mdt_ucred(info);
150 lnet_nid_t peernid = req->rq_peer.nid;
152 __u32 remote = exp_connect_rmtclient(info->mti_exp);
159 LASSERT(req->rq_auth_gss);
160 LASSERT(!req->rq_auth_usr_mdt);
161 LASSERT(req->rq_user_desc);
162 LASSERT(ucred != NULL);
164 ucred->uc_valid = UCRED_INVALID;
166 ucred->uc_o_uid = pud->pud_uid;
167 ucred->uc_o_gid = pud->pud_gid;
168 ucred->uc_o_fsuid = pud->pud_fsuid;
169 ucred->uc_o_fsgid = pud->pud_fsgid;
171 if (type == BODY_INIT) {
172 struct mdt_body *body = (struct mdt_body *)buf;
174 ucred->uc_suppgids[0] = body->mbo_suppgid;
175 ucred->uc_suppgids[1] = -1;
178 /* sanity check: we expect the uid which client claimed is true */
180 if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_mapped_uid))) {
181 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
185 if (ptlrpc_user_desc_do_idmap(req, pud))
188 if (req->rq_auth_mapped_uid != pud->pud_uid) {
189 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
190 "while client claims %u:%u/%u:%u\n",
191 libcfs_nid2str(peernid), req->rq_auth_uid,
192 req->rq_auth_mapped_uid,
193 pud->pud_uid, pud->pud_gid,
194 pud->pud_fsuid, pud->pud_fsgid);
198 if (req->rq_auth_uid != pud->pud_uid) {
199 CDEBUG(D_SEC, "local client %s: auth uid %u "
200 "while client claims %u:%u/%u:%u\n",
201 libcfs_nid2str(peernid), req->rq_auth_uid,
202 pud->pud_uid, pud->pud_gid,
203 pud->pud_fsuid, pud->pud_fsgid);
208 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
210 CDEBUG(D_SEC, "remote client must run with identity_get "
214 ucred->uc_identity = NULL;
215 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
219 struct md_identity *identity;
221 identity = mdt_identity_get(mdt->mdt_identity_cache,
223 if (IS_ERR(identity)) {
224 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
226 ucred->uc_identity = NULL;
227 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
230 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
235 ucred->uc_identity = identity;
236 perm = mdt_identity_get_perm(ucred->uc_identity,
241 /* find out the setuid/setgid attempt */
242 setuid = (pud->pud_uid != pud->pud_fsuid);
243 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
244 (ucred->uc_identity &&
245 (pud->pud_gid != ucred->uc_identity->mi_gid)));
247 /* check permission of setuid */
248 if (setuid && !(perm & CFS_SETUID_PERM)) {
249 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
250 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
251 GOTO(out, rc = -EACCES);
254 /* check permission of setgid */
255 if (setgid && !(perm & CFS_SETGID_PERM)) {
256 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
257 "from %s\n", pud->pud_uid, pud->pud_gid,
258 pud->pud_fsuid, pud->pud_fsgid,
259 ucred->uc_identity->mi_gid, libcfs_nid2str(peernid));
260 GOTO(out, rc = -EACCES);
264 * NB: remote client not allowed to setgroups anyway.
266 if (!remote && perm & CFS_SETGRP_PERM) {
267 if (pud->pud_ngroups) {
268 /* setgroups for local client */
269 ucred->uc_ginfo = groups_alloc(pud->pud_ngroups);
270 if (!ucred->uc_ginfo) {
271 CERROR("failed to alloc %d groups\n",
273 GOTO(out, rc = -ENOMEM);
276 lustre_groups_from_list(ucred->uc_ginfo,
278 lustre_groups_sort(ucred->uc_ginfo);
280 ucred->uc_ginfo = NULL;
283 ucred->uc_suppgids[0] = -1;
284 ucred->uc_suppgids[1] = -1;
285 ucred->uc_ginfo = NULL;
288 ucred->uc_uid = pud->pud_uid;
289 ucred->uc_gid = pud->pud_gid;
290 ucred->uc_fsuid = pud->pud_fsuid;
291 ucred->uc_fsgid = pud->pud_fsgid;
293 /* process root_squash here. */
294 mdt_root_squash(info, peernid);
296 /* remove fs privilege for non-root user. */
297 if (ucred->uc_fsuid && drop_fs_cap)
298 ucred->uc_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
300 ucred->uc_cap = pud->pud_cap;
301 if (remote && !(perm & CFS_RMTOWN_PERM))
302 ucred->uc_cap &= ~(CFS_CAP_SYS_RESOURCE_MASK |
304 ucred->uc_valid = UCRED_NEW;
305 ucred_set_jobid(info, ucred);
311 if (ucred->uc_ginfo) {
312 put_group_info(ucred->uc_ginfo);
313 ucred->uc_ginfo = NULL;
315 if (ucred->uc_identity) {
316 mdt_identity_put(mdt->mdt_identity_cache,
318 ucred->uc_identity = NULL;
326 * Check whether allow the client to set supplementary group IDs or not.
328 * \param[in] info pointer to the thread context
329 * \param[in] uc pointer to the RPC user descriptor
331 * \retval true if allow to set supplementary group IDs
332 * \retval false for other cases
334 bool allow_client_chgrp(struct mdt_thread_info *info, struct lu_ucred *uc)
336 __u32 remote = exp_connect_rmtclient(info->mti_exp);
339 /* 1. If identity_upcall is disabled, then forbid remote client to set
340 * supplementary group IDs, but permit local client to do that. */
341 if (is_identity_get_disabled(info->mti_mdt->mdt_identity_cache)) {
348 /* 2. If fail to get related identities, then forbid any client to
349 * set supplementary group IDs. */
350 if (uc->uc_identity == NULL)
353 /* 3. Check the permission in the identities. */
354 perm = mdt_identity_get_perm(uc->uc_identity, remote,
355 mdt_info_req(info)->rq_peer.nid);
356 if (perm & CFS_SETGRP_PERM)
362 int mdt_check_ucred(struct mdt_thread_info *info)
364 struct ptlrpc_request *req = mdt_info_req(info);
365 struct mdt_device *mdt = info->mti_mdt;
366 struct ptlrpc_user_desc *pud = req->rq_user_desc;
367 struct lu_ucred *ucred = mdt_ucred(info);
368 struct md_identity *identity = NULL;
369 lnet_nid_t peernid = req->rq_peer.nid;
371 __u32 remote = exp_connect_rmtclient(info->mti_exp);
378 LASSERT(ucred != NULL);
379 if ((ucred->uc_valid == UCRED_OLD) || (ucred->uc_valid == UCRED_NEW))
382 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
385 /* sanity check: if we use strong authentication, we expect the
386 * uid which client claimed is true */
388 if (!uid_valid(make_kuid(&init_user_ns, req->rq_auth_mapped_uid))) {
389 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
393 if (ptlrpc_user_desc_do_idmap(req, pud))
396 if (req->rq_auth_mapped_uid != pud->pud_uid) {
397 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
398 "while client claims %u:%u/%u:%u\n",
399 libcfs_nid2str(peernid), req->rq_auth_uid,
400 req->rq_auth_mapped_uid,
401 pud->pud_uid, pud->pud_gid,
402 pud->pud_fsuid, pud->pud_fsgid);
406 if (req->rq_auth_uid != pud->pud_uid) {
407 CDEBUG(D_SEC, "local client %s: auth uid %u "
408 "while client claims %u:%u/%u:%u\n",
409 libcfs_nid2str(peernid), req->rq_auth_uid,
410 pud->pud_uid, pud->pud_gid,
411 pud->pud_fsuid, pud->pud_fsgid);
416 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
418 CDEBUG(D_SEC, "remote client must run with identity_get "
425 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
426 if (IS_ERR(identity)) {
427 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
431 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
437 perm = mdt_identity_get_perm(identity, remote, peernid);
438 /* find out the setuid/setgid attempt */
439 setuid = (pud->pud_uid != pud->pud_fsuid);
440 setgid = (pud->pud_gid != pud->pud_fsgid ||
441 pud->pud_gid != identity->mi_gid);
443 /* check permission of setuid */
444 if (setuid && !(perm & CFS_SETUID_PERM)) {
445 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
446 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
447 GOTO(out, rc = -EACCES);
450 /* check permission of setgid */
451 if (setgid && !(perm & CFS_SETGID_PERM)) {
452 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
453 "from %s\n", pud->pud_uid, pud->pud_gid,
454 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
455 libcfs_nid2str(peernid));
456 GOTO(out, rc = -EACCES);
462 mdt_identity_put(mdt->mdt_identity_cache, identity);
466 static int old_init_ucred_common(struct mdt_thread_info *info,
469 struct lu_ucred *uc = mdt_ucred(info);
470 struct mdt_device *mdt = info->mti_mdt;
471 struct md_identity *identity = NULL;
472 struct lu_nodemap *nodemap =
473 info->mti_exp->exp_target_data.ted_nodemap;
475 if (nodemap == NULL) {
476 CDEBUG(D_SEC, "%s: cli %s/%p nodemap not set.\n",
477 mdt2obd_dev(mdt)->obd_name,
478 info->mti_exp->exp_client_uuid.uuid, info->mti_exp);
482 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
483 identity = mdt_identity_get(mdt->mdt_identity_cache,
485 if (IS_ERR(identity)) {
486 if (unlikely(PTR_ERR(identity) == -EREMCHG ||
487 uc->uc_cap & CFS_CAP_FS_MASK)) {
490 CDEBUG(D_SEC, "Deny access without identity: "
491 "uid %u\n", uc->uc_fsuid);
496 uc->uc_identity = identity;
498 if (uc->uc_o_uid == nodemap->nm_squash_uid) {
499 uc->uc_fsuid = nodemap->nm_squash_uid;
500 uc->uc_fsgid = nodemap->nm_squash_gid;
502 uc->uc_suppgids[0] = -1;
503 uc->uc_suppgids[1] = -1;
506 /* process root_squash here. */
507 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
509 /* remove fs privilege for non-root user. */
510 if (uc->uc_fsuid && drop_fs_cap)
511 uc->uc_cap &= ~CFS_CAP_FS_MASK;
512 uc->uc_valid = UCRED_OLD;
513 ucred_set_jobid(info, uc);
518 static int old_init_ucred(struct mdt_thread_info *info,
519 struct mdt_body *body, bool drop_fs_cap)
521 struct lu_ucred *uc = mdt_ucred(info);
522 struct lu_nodemap *nodemap =
523 info->mti_exp->exp_target_data.ted_nodemap;
527 body->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
528 NODEMAP_CLIENT_TO_FS, body->mbo_uid);
529 body->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
530 NODEMAP_CLIENT_TO_FS, body->mbo_gid);
531 body->mbo_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
532 NODEMAP_CLIENT_TO_FS, body->mbo_fsuid);
533 body->mbo_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
534 NODEMAP_CLIENT_TO_FS, body->mbo_fsgid);
537 uc->uc_valid = UCRED_INVALID;
538 uc->uc_o_uid = uc->uc_uid = body->mbo_uid;
539 uc->uc_o_gid = uc->uc_gid = body->mbo_gid;
540 uc->uc_o_fsuid = uc->uc_fsuid = body->mbo_fsuid;
541 uc->uc_o_fsgid = uc->uc_fsgid = body->mbo_fsgid;
542 uc->uc_suppgids[0] = body->mbo_suppgid;
543 uc->uc_suppgids[1] = -1;
545 uc->uc_cap = body->mbo_capability;
547 rc = old_init_ucred_common(info, drop_fs_cap);
552 static int old_init_ucred_reint(struct mdt_thread_info *info)
554 struct lu_ucred *uc = mdt_ucred(info);
555 struct lu_nodemap *nodemap =
556 info->mti_exp->exp_target_data.ted_nodemap;
562 uc->uc_fsuid = nodemap_map_id(nodemap, NODEMAP_UID,
563 NODEMAP_CLIENT_TO_FS, uc->uc_fsuid);
564 uc->uc_fsgid = nodemap_map_id(nodemap, NODEMAP_GID,
565 NODEMAP_CLIENT_TO_FS, uc->uc_fsgid);
567 uc->uc_valid = UCRED_INVALID;
568 uc->uc_o_uid = uc->uc_o_fsuid = uc->uc_uid = uc->uc_fsuid;
569 uc->uc_o_gid = uc->uc_o_fsgid = uc->uc_gid = uc->uc_fsgid;
572 rc = old_init_ucred_common(info, true); /* drop_fs_cap = true */
577 static inline int __mdt_init_ucred(struct mdt_thread_info *info,
578 struct mdt_body *body,
581 struct ptlrpc_request *req = mdt_info_req(info);
582 struct lu_ucred *uc = mdt_ucred(info);
585 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
588 mdt_exit_ucred(info);
590 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
591 return old_init_ucred(info, body, drop_fs_cap);
593 return new_init_ucred(info, BODY_INIT, body, drop_fs_cap);
596 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
598 return __mdt_init_ucred(info, body, true);
601 /* LU-6528 when "no_subtree_check" is set for NFS export, nfsd_set_fh_dentry()
602 * doesn't set correct fsuid explicitely, but raise capability to allow
603 * exportfs_decode_fh() to reconnect disconnected dentry into dcache. So for
604 * lookup (i.e. intent_getattr), we should keep FS capability, otherwise it
605 * will fail permission check. */
606 int mdt_init_ucred_intent_getattr(struct mdt_thread_info *info,
607 struct mdt_body *body)
609 return __mdt_init_ucred(info, body, false);
612 int mdt_init_ucred_reint(struct mdt_thread_info *info)
614 struct ptlrpc_request *req = mdt_info_req(info);
615 struct lu_ucred *uc = mdt_ucred(info);
618 if ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW))
621 mdt_exit_ucred(info);
623 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
624 return old_init_ucred_reint(info);
626 return new_init_ucred(info, REC_INIT, NULL, true);
629 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
630 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm, __u64 valid)
632 const struct lov_ost_data_v1 *lod;
636 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
639 count = le16_to_cpu(((struct lov_user_md *)lmm)->lmm_stripe_count);
641 CDEBUG(level, "objid "DOSTID", magic 0x%08X, pattern %#X\n",
642 POSTID(&lmm->lmm_oi), le32_to_cpu(lmm->lmm_magic),
643 le32_to_cpu(lmm->lmm_pattern));
644 CDEBUG(level, "stripe_size=0x%x, stripe_count=0x%x\n",
645 le32_to_cpu(lmm->lmm_stripe_size), count);
647 /* If it's a directory or a released file, then there are
648 * no actual objects to print, so bail out. */
649 if (valid & OBD_MD_FLDIREA ||
650 le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_RELEASED)
653 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
654 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++) {
657 ostid_le_to_cpu(&lod->l_ost_oi, &oi);
658 CDEBUG(level, "stripe %u idx %u subobj "DOSTID"\n",
659 i, le32_to_cpu(lod->l_ost_idx), POSTID(&oi));
663 void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
665 const struct lmv_mds_md_v1 *lmm1;
668 if (likely(!cfs_cdebug_show(level, DEBUG_SUBSYSTEM)))
671 lmm1 = &lmv->lmv_md_v1;
672 CDEBUG(level, "magic 0x%08X, master %#X stripe_count %#x\n",
673 le32_to_cpu(lmm1->lmv_magic),
674 le32_to_cpu(lmm1->lmv_master_mdt_index),
675 le32_to_cpu(lmm1->lmv_stripe_count));
677 if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
680 for (i = 0; i < le32_to_cpu(lmm1->lmv_stripe_count); i++) {
683 fid_le_to_cpu(&fid, &lmm1->lmv_stripe_fids[i]);
684 CDEBUG(level, "idx %u subobj "DFID"\n", i, PFID(&fid));
688 /* Shrink and/or grow reply buffers */
689 int mdt_fix_reply(struct mdt_thread_info *info)
691 struct req_capsule *pill = info->mti_pill;
692 struct mdt_body *body;
693 int md_size, md_packed = 0;
698 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
699 LASSERT(body != NULL);
701 if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE |
703 md_size = body->mbo_eadatasize;
707 acl_size = body->mbo_aclsize;
709 /* this replay - not send info to client */
710 if (info->mti_spec.no_create) {
715 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d\n",
720 &RMF_ACL, or &RMF_LOGCOOKIES
721 (optional) &RMF_CAPA1,
722 (optional) &RMF_CAPA2,
723 (optional) something else
726 /* MDT_MD buffer may be bigger than packed value, let's shrink all
727 * buffers before growing it */
728 if (info->mti_big_lmm_used) {
729 /* big_lmm buffer may be used even without packing the result
730 * into reply, just for internal server needs */
731 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
732 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
735 /* free big lmm if md_size is not needed */
736 if (md_size == 0 || md_packed == 0) {
737 info->mti_big_lmm_used = 0;
739 /* buffer must be allocated separately */
740 LASSERT(info->mti_attr.ma_lmm !=
741 req_capsule_server_get(pill, &RMF_MDT_MD));
742 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
744 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
745 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
748 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
749 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
750 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
751 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
752 acl_size, RCL_SERVER);
754 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
755 !(body->mbo_valid & OBD_MD_FLMDSCAPA))
756 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
758 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
759 !(body->mbo_valid & OBD_MD_FLOSSCAPA))
760 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
763 * Some more field should be shrinked if needed.
764 * This should be done by those who added fields to reply message.
767 /* Grow MD buffer if needed finally */
768 if (info->mti_big_lmm_used) {
771 LASSERT(md_size > md_packed);
772 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
773 md_size - md_packed);
774 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
776 /* we can't answer with proper LOV EA, drop flags,
777 * the rc is also returned so this request is
778 * considered as failed */
779 body->mbo_valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
780 /* don't return transno along with error */
781 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
783 /* now we need to pack right LOV/LMV EA */
784 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
785 if (info->mti_attr.ma_valid & MA_LOV) {
786 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
788 info->mti_attr.ma_lmm_size);
789 memcpy(lmm, info->mti_attr.ma_lmm,
790 info->mti_attr.ma_lmm_size);
791 } else if (info->mti_attr.ma_valid & MA_LMV) {
792 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
794 info->mti_attr.ma_lmv_size);
795 memcpy(lmm, info->mti_attr.ma_lmv,
796 info->mti_attr.ma_lmv_size);
799 /* update mdt_max_mdsize so clients will be aware about that */
800 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
801 info->mti_mdt->mdt_max_mdsize =
802 info->mti_attr.ma_lmm_size;
803 info->mti_big_lmm_used = 0;
809 /* if object is dying, pack the lov/llog data,
810 * parameter info->mti_attr should be valid at this point! */
811 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
814 struct mdt_body *repbody = NULL;
815 const struct lu_attr *la = &ma->ma_attr;
816 struct coordinator *cdt = &info->mti_mdt->mdt_coordinator;
819 struct hsm_action_item hai = {
820 .hai_len = sizeof(hai),
821 .hai_action = HSMA_REMOVE,
822 .hai_extent.length = -1,
831 if (mdt_info_req(info) != NULL) {
832 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
833 LASSERT(repbody != NULL);
835 CDEBUG(D_INFO, "not running in a request/reply context\n");
838 if ((ma->ma_valid & MA_INODE) && repbody != NULL)
839 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
841 if (ma->ma_valid & MA_LOV) {
842 CERROR("No need in LOV EA upon unlink\n");
846 repbody->mbo_eadatasize = 0;
848 /* Only check unlinked and archived if RAoLU and upon last close */
849 if (!cdt->cdt_remove_archive_on_last_unlink ||
850 atomic_read(&mo->mot_open_count) != 0)
853 if (ma->ma_valid & MA_INODE) {
854 if (ma->ma_attr.la_nlink != 0)
860 if (ma->ma_valid & MA_HSM) {
861 if (!(ma->ma_hsm.mh_flags & HS_EXISTS))
869 rc = mdt_attr_get_complex(info, mo, ma);
871 CERROR("%s: unable to fetch missing attributes of"
872 DFID": rc=%d\n", mdt_obd_name(info->mti_mdt),
873 PFID(mdt_object_fid(mo)), rc);
877 if (need & MA_INODE) {
878 if (ma->ma_valid & MA_INODE) {
879 if (ma->ma_attr.la_nlink != 0)
887 if (ma->ma_valid & MA_HSM) {
888 if (!(ma->ma_hsm.mh_flags & HS_EXISTS))
896 /* RAoLU policy is active, last close on file has occured,
897 * file is unlinked, file is archived, so create remove request
899 * If CDT is not running, requests will be logged for later. */
900 compound_id = atomic_inc_return(&cdt->cdt_compound_id);
901 if (ma->ma_hsm.mh_arch_id != 0)
902 archive_id = ma->ma_hsm.mh_arch_id;
904 archive_id = cdt->cdt_default_archive_id;
906 hai.hai_fid = *mdt_object_fid(mo);
908 rc = mdt_agent_record_add(info->mti_env, info->mti_mdt,
909 compound_id, archive_id, 0, &hai);
911 CERROR("%s: unable to add HSM remove request for "DFID
912 ": rc=%d\n", mdt_obd_name(info->mti_mdt),
913 PFID(mdt_object_fid(mo)), rc);
918 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
924 if (in & MDS_ATTR_MODE)
926 if (in & MDS_ATTR_UID)
928 if (in & MDS_ATTR_GID)
930 if (in & MDS_ATTR_SIZE)
932 if (in & MDS_ATTR_BLOCKS)
934 if (in & MDS_ATTR_ATIME_SET)
936 if (in & MDS_ATTR_CTIME_SET)
938 if (in & MDS_ATTR_MTIME_SET)
940 if (in & MDS_ATTR_ATTR_FLAG)
942 if (in & MDS_ATTR_KILL_SUID)
944 if (in & MDS_ATTR_KILL_SGID)
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 |
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: "LPX64"\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_setattr_unpack_rec(struct mdt_thread_info *info)
996 struct lu_ucred *uc = mdt_ucred(info);
997 struct md_attr *ma = &info->mti_attr;
998 struct lu_attr *la = &ma->ma_attr;
999 struct req_capsule *pill = info->mti_pill;
1000 struct mdt_reint_record *rr = &info->mti_rr;
1001 struct mdt_rec_setattr *rec;
1002 struct lu_nodemap *nodemap =
1003 info->mti_exp->exp_target_data.ted_nodemap;
1006 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
1007 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1011 /* This prior initialization is needed for old_init_ucred_reint() */
1012 uc->uc_fsuid = rec->sa_fsuid;
1013 uc->uc_fsgid = rec->sa_fsgid;
1014 uc->uc_cap = rec->sa_cap;
1015 uc->uc_suppgids[0] = rec->sa_suppgid;
1016 uc->uc_suppgids[1] = -1;
1018 rr->rr_fid1 = &rec->sa_fid;
1019 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
1020 la->la_mode = rec->sa_mode;
1021 la->la_flags = rec->sa_attr_flags;
1022 la->la_uid = nodemap_map_id(nodemap, NODEMAP_UID,
1023 NODEMAP_CLIENT_TO_FS, rec->sa_uid);
1024 la->la_gid = nodemap_map_id(nodemap, NODEMAP_GID,
1025 NODEMAP_CLIENT_TO_FS, rec->sa_gid);
1026 la->la_size = rec->sa_size;
1027 la->la_blocks = rec->sa_blocks;
1028 la->la_ctime = rec->sa_ctime;
1029 la->la_atime = rec->sa_atime;
1030 la->la_mtime = rec->sa_mtime;
1031 ma->ma_valid = MA_INODE;
1033 if (rec->sa_bias & MDS_DATA_MODIFIED)
1034 ma->ma_attr_flags |= MDS_DATA_MODIFIED;
1036 ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
1038 if (rec->sa_bias & MDS_HSM_RELEASE)
1039 ma->ma_attr_flags |= MDS_HSM_RELEASE;
1041 ma->ma_attr_flags &= ~MDS_HSM_RELEASE;
1043 if (rec->sa_bias & MDS_CLOSE_LAYOUT_SWAP)
1044 ma->ma_attr_flags |= MDS_CLOSE_LAYOUT_SWAP;
1046 ma->ma_attr_flags &= ~MDS_CLOSE_LAYOUT_SWAP;
1051 static int mdt_close_handle_unpack(struct mdt_thread_info *info)
1053 struct req_capsule *pill = info->mti_pill;
1054 struct mdt_ioepoch *ioepoch;
1057 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
1058 ioepoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
1062 if (ioepoch == NULL)
1065 info->mti_close_handle = ioepoch->mio_handle;
1070 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
1071 struct req_capsule *pill = info->mti_pill;
1073 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
1074 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
1075 if (info->mti_dlm_req == NULL)
1082 static int mdt_setattr_unpack(struct mdt_thread_info *info)
1084 struct mdt_reint_record *rr = &info->mti_rr;
1085 struct md_attr *ma = &info->mti_attr;
1086 struct req_capsule *pill = info->mti_pill;
1090 rc = mdt_setattr_unpack_rec(info);
1094 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1095 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1096 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1098 if (rr->rr_eadatalen > 0) {
1099 const struct lmv_user_md *lum;
1101 lum = rr->rr_eadata;
1102 /* Sigh ma_valid(from req) does not indicate whether
1103 * it will set LOV/LMV EA, so we have to check magic */
1104 if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
1105 ma->ma_valid |= MA_LMV;
1106 ma->ma_lmv = (void *)rr->rr_eadata;
1107 ma->ma_lmv_size = rr->rr_eadatalen;
1109 ma->ma_valid |= MA_LOV;
1110 ma->ma_lmm = (void *)rr->rr_eadata;
1111 ma->ma_lmm_size = rr->rr_eadatalen;
1116 rc = mdt_dlmreq_unpack(info);
1120 static int mdt_intent_close_unpack(struct mdt_thread_info *info)
1122 struct md_attr *ma = &info->mti_attr;
1123 struct req_capsule *pill = info->mti_pill;
1126 if (!(ma->ma_attr_flags & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)))
1129 req_capsule_extend(pill, &RQF_MDS_INTENT_CLOSE);
1131 if (!(req_capsule_has_field(pill, &RMF_CLOSE_DATA, RCL_CLIENT) &&
1132 req_capsule_field_present(pill, &RMF_CLOSE_DATA, RCL_CLIENT)))
1138 int mdt_close_unpack(struct mdt_thread_info *info)
1143 rc = mdt_close_handle_unpack(info);
1147 rc = mdt_setattr_unpack_rec(info);
1151 rc = mdt_intent_close_unpack(info);
1155 RETURN(mdt_init_ucred_reint(info));
1158 static int mdt_create_unpack(struct mdt_thread_info *info)
1160 struct lu_ucred *uc = mdt_ucred(info);
1161 struct mdt_rec_create *rec;
1162 struct lu_attr *attr = &info->mti_attr.ma_attr;
1163 struct mdt_reint_record *rr = &info->mti_rr;
1164 struct req_capsule *pill = info->mti_pill;
1165 struct md_op_spec *sp = &info->mti_spec;
1169 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1170 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1174 /* This prior initialization is needed for old_init_ucred_reint() */
1175 uc->uc_fsuid = rec->cr_fsuid;
1176 uc->uc_fsgid = rec->cr_fsgid;
1177 uc->uc_cap = rec->cr_cap;
1178 uc->uc_suppgids[0] = rec->cr_suppgid1;
1179 uc->uc_suppgids[1] = -1;
1180 uc->uc_umask = rec->cr_umask;
1182 rr->rr_fid1 = &rec->cr_fid1;
1183 rr->rr_fid2 = &rec->cr_fid2;
1184 attr->la_mode = rec->cr_mode;
1185 attr->la_rdev = rec->cr_rdev;
1186 attr->la_uid = rec->cr_fsuid;
1187 attr->la_gid = rec->cr_fsgid;
1188 attr->la_ctime = rec->cr_time;
1189 attr->la_mtime = rec->cr_time;
1190 attr->la_atime = rec->cr_time;
1191 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_TYPE |
1192 LA_CTIME | LA_MTIME | LA_ATIME;
1193 memset(&sp->u, 0, sizeof(sp->u));
1194 sp->sp_cr_flags = get_mrc_cr_flags(rec);
1196 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1200 if (S_ISLNK(attr->la_mode)) {
1201 const char *tgt = NULL;
1203 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1204 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1205 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1206 sp->u.sp_symname = tgt;
1211 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
1212 if (S_ISDIR(attr->la_mode) &&
1213 req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT) > 0) {
1214 sp->u.sp_ea.eadata =
1215 req_capsule_client_get(pill, &RMF_EADATA);
1216 sp->u.sp_ea.eadatalen =
1217 req_capsule_get_size(pill, &RMF_EADATA,
1219 sp->sp_cr_flags |= MDS_OPEN_HAS_EA;
1223 rc = mdt_dlmreq_unpack(info);
1227 static int mdt_link_unpack(struct mdt_thread_info *info)
1229 struct lu_ucred *uc = mdt_ucred(info);
1230 struct mdt_rec_link *rec;
1231 struct lu_attr *attr = &info->mti_attr.ma_attr;
1232 struct mdt_reint_record *rr = &info->mti_rr;
1233 struct req_capsule *pill = info->mti_pill;
1237 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1238 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1242 /* This prior initialization is needed for old_init_ucred_reint() */
1243 uc->uc_fsuid = rec->lk_fsuid;
1244 uc->uc_fsgid = rec->lk_fsgid;
1245 uc->uc_cap = rec->lk_cap;
1246 uc->uc_suppgids[0] = rec->lk_suppgid1;
1247 uc->uc_suppgids[1] = rec->lk_suppgid2;
1249 attr->la_uid = rec->lk_fsuid;
1250 attr->la_gid = rec->lk_fsgid;
1251 rr->rr_fid1 = &rec->lk_fid1;
1252 rr->rr_fid2 = &rec->lk_fid2;
1253 attr->la_ctime = rec->lk_time;
1254 attr->la_mtime = rec->lk_time;
1255 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1257 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1261 rc = mdt_dlmreq_unpack(info);
1266 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1268 struct lu_ucred *uc = mdt_ucred(info);
1269 struct mdt_rec_unlink *rec;
1270 struct md_attr *ma = &info->mti_attr;
1271 struct lu_attr *attr = &info->mti_attr.ma_attr;
1272 struct mdt_reint_record *rr = &info->mti_rr;
1273 struct req_capsule *pill = info->mti_pill;
1277 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1278 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1282 /* This prior initialization is needed for old_init_ucred_reint() */
1283 uc->uc_fsuid = rec->ul_fsuid;
1284 uc->uc_fsgid = rec->ul_fsgid;
1285 uc->uc_cap = rec->ul_cap;
1286 uc->uc_suppgids[0] = rec->ul_suppgid1;
1287 uc->uc_suppgids[1] = -1;
1289 attr->la_uid = rec->ul_fsuid;
1290 attr->la_gid = rec->ul_fsgid;
1291 rr->rr_fid1 = &rec->ul_fid1;
1292 rr->rr_fid2 = &rec->ul_fid2;
1293 attr->la_ctime = rec->ul_time;
1294 attr->la_mtime = rec->ul_time;
1295 attr->la_mode = rec->ul_mode;
1296 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1298 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1302 if (rec->ul_bias & MDS_VTX_BYPASS)
1303 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1305 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1307 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1309 rc = mdt_dlmreq_unpack(info);
1313 static int mdt_rmentry_unpack(struct mdt_thread_info *info)
1315 info->mti_spec.sp_rm_entry = 1;
1316 return mdt_unlink_unpack(info);
1319 static int mdt_rename_unpack(struct mdt_thread_info *info)
1321 struct lu_ucred *uc = mdt_ucred(info);
1322 struct mdt_rec_rename *rec;
1323 struct md_attr *ma = &info->mti_attr;
1324 struct lu_attr *attr = &info->mti_attr.ma_attr;
1325 struct mdt_reint_record *rr = &info->mti_rr;
1326 struct req_capsule *pill = info->mti_pill;
1330 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1331 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1335 /* This prior initialization is needed for old_init_ucred_reint() */
1336 uc->uc_fsuid = rec->rn_fsuid;
1337 uc->uc_fsgid = rec->rn_fsgid;
1338 uc->uc_cap = rec->rn_cap;
1339 uc->uc_suppgids[0] = rec->rn_suppgid1;
1340 uc->uc_suppgids[1] = rec->rn_suppgid2;
1342 attr->la_uid = rec->rn_fsuid;
1343 attr->la_gid = rec->rn_fsgid;
1344 rr->rr_fid1 = &rec->rn_fid1;
1345 rr->rr_fid2 = &rec->rn_fid2;
1346 attr->la_ctime = rec->rn_time;
1347 attr->la_mtime = rec->rn_time;
1348 /* rename_tgt contains the mode already */
1349 attr->la_mode = rec->rn_mode;
1350 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1352 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1356 rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0);
1360 if (rec->rn_bias & MDS_VTX_BYPASS)
1361 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1363 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1365 if (rec->rn_bias & MDS_RENAME_MIGRATE) {
1366 req_capsule_extend(info->mti_pill, &RQF_MDS_REINT_MIGRATE);
1367 rc = mdt_close_handle_unpack(info);
1370 info->mti_spec.sp_migrate_close = 1;
1373 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1376 rc = mdt_dlmreq_unpack(info);
1382 * please see comment above LOV_MAGIC_V1_DEF
1384 static void mdt_fix_lov_magic(struct mdt_thread_info *info)
1386 struct mdt_reint_record *rr = &info->mti_rr;
1387 struct lov_user_md_v1 *v1;
1389 v1 = (void *)rr->rr_eadata;
1392 if (unlikely(req_is_replay(mdt_info_req(info)))) {
1393 if (v1->lmm_magic == LOV_USER_MAGIC_V1) {
1394 v1->lmm_magic = LOV_MAGIC_V1_DEF;
1395 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
1396 v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF);
1397 } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
1398 v1->lmm_magic = LOV_MAGIC_V3_DEF;
1399 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
1400 v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF);
1405 static int mdt_open_unpack(struct mdt_thread_info *info)
1407 struct lu_ucred *uc = mdt_ucred(info);
1408 struct mdt_rec_create *rec;
1409 struct lu_attr *attr = &info->mti_attr.ma_attr;
1410 struct req_capsule *pill = info->mti_pill;
1411 struct mdt_reint_record *rr = &info->mti_rr;
1412 struct ptlrpc_request *req = mdt_info_req(info);
1413 struct md_op_spec *sp = &info->mti_spec;
1416 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1417 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1421 /* This prior initialization is needed for old_init_ucred_reint() */
1422 uc->uc_fsuid = rec->cr_fsuid;
1423 uc->uc_fsgid = rec->cr_fsgid;
1424 uc->uc_cap = rec->cr_cap;
1425 uc->uc_suppgids[0] = rec->cr_suppgid1;
1426 uc->uc_suppgids[1] = rec->cr_suppgid2;
1427 uc->uc_umask = rec->cr_umask;
1429 rr->rr_fid1 = &rec->cr_fid1;
1430 rr->rr_fid2 = &rec->cr_fid2;
1431 rr->rr_handle = &rec->cr_old_handle;
1432 attr->la_mode = rec->cr_mode;
1433 attr->la_rdev = rec->cr_rdev;
1434 attr->la_uid = rec->cr_fsuid;
1435 attr->la_gid = rec->cr_fsgid;
1436 attr->la_ctime = rec->cr_time;
1437 attr->la_mtime = rec->cr_time;
1438 attr->la_atime = rec->cr_time;
1439 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1440 LA_CTIME | LA_MTIME | LA_ATIME;
1441 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1442 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1443 /* Do not trigger ASSERTION if client miss to set such flags. */
1444 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1447 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1449 mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON);
1451 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1452 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1454 if (rr->rr_eadatalen > 0) {
1455 rr->rr_eadata = req_capsule_client_get(pill,
1457 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1458 sp->u.sp_ea.eadata = rr->rr_eadata;
1459 sp->no_create = !!req_is_replay(req);
1460 mdt_fix_lov_magic(info);
1464 * Client default md_size may be 0 right after client start,
1465 * until all osc are connected, set here just some reasonable
1466 * value to prevent misbehavior.
1468 if (rr->rr_eadatalen == 0 &&
1469 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1470 rr->rr_eadatalen = MIN_MD_SIZE;
1476 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1478 struct mdt_reint_record *rr = &info->mti_rr;
1479 struct lu_ucred *uc = mdt_ucred(info);
1480 struct lu_attr *attr = &info->mti_attr.ma_attr;
1481 struct req_capsule *pill = info->mti_pill;
1482 struct mdt_rec_setxattr *rec;
1487 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1488 sizeof(struct mdt_rec_reint));
1490 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1494 /* This prior initialization is needed for old_init_ucred_reint() */
1495 uc->uc_fsuid = rec->sx_fsuid;
1496 uc->uc_fsgid = rec->sx_fsgid;
1497 uc->uc_cap = rec->sx_cap;
1498 uc->uc_suppgids[0] = rec->sx_suppgid1;
1499 uc->uc_suppgids[1] = -1;
1501 rr->rr_opcode = rec->sx_opcode;
1502 rr->rr_fid1 = &rec->sx_fid;
1503 attr->la_valid = rec->sx_valid;
1504 attr->la_ctime = rec->sx_time;
1505 attr->la_size = rec->sx_size;
1506 attr->la_flags = rec->sx_flags;
1508 rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0);
1512 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1513 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1515 if (rr->rr_eadatalen > 0) {
1516 rr->rr_eadata = req_capsule_client_get(pill,
1518 if (rr->rr_eadata == NULL)
1521 rr->rr_eadata = NULL;
1523 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1524 CDEBUG(D_INFO, "no xattr data supplied\n");
1528 if (mdt_dlmreq_unpack(info) < 0)
1535 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1537 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1538 [REINT_SETATTR] = mdt_setattr_unpack,
1539 [REINT_CREATE] = mdt_create_unpack,
1540 [REINT_LINK] = mdt_link_unpack,
1541 [REINT_UNLINK] = mdt_unlink_unpack,
1542 [REINT_RENAME] = mdt_rename_unpack,
1543 [REINT_OPEN] = mdt_open_unpack,
1544 [REINT_SETXATTR] = mdt_setxattr_unpack,
1545 [REINT_RMENTRY] = mdt_rmentry_unpack,
1546 [REINT_MIGRATE] = mdt_rename_unpack,
1549 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1554 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1555 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1556 info->mti_rr.rr_opcode = op;
1557 rc = mdt_reint_unpackers[op](info);
1559 CERROR("Unexpected opcode %d\n", op);