1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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>
51 # define EXPORT_SYMTAB
53 #define DEBUG_SUBSYSTEM S_MDS
55 #include "mdt_internal.h"
58 typedef enum ucred_init_type {
64 void mdt_exit_ucred(struct mdt_thread_info *info)
66 struct md_ucred *uc = mdt_ucred(info);
67 struct mdt_device *mdt = info->mti_mdt;
69 if (uc->mu_valid != UCRED_INIT) {
70 uc->mu_suppgids[0] = uc->mu_suppgids[1] = -1;
72 groups_free(uc->mu_ginfo);
75 if (uc->mu_identity) {
76 mdt_identity_put(mdt->mdt_identity_cache,
78 uc->mu_identity = NULL;
80 uc->mu_valid = UCRED_INIT;
84 /* XXX: root_squash will be redesigned in Lustre 1.7.
85 * Do not root_squash for inter-MDS operations */
86 static int mdt_root_squash(struct mdt_thread_info *info)
91 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
94 struct ptlrpc_request *req = mdt_info_req(info);
95 struct mdt_export_data *med = mdt_req2med(req);
96 struct mdt_device *mdt = info->mti_mdt;
97 struct ptlrpc_user_desc *pud = req->rq_user_desc;
98 struct md_ucred *ucred = mdt_ucred(info);
99 lnet_nid_t peernid = req->rq_peer.nid;
107 LASSERT(req->rq_auth_gss);
108 LASSERT(!req->rq_auth_usr_mdt);
109 LASSERT(req->rq_user_desc);
111 ucred->mu_valid = UCRED_INVALID;
113 ucred->mu_o_uid = pud->pud_uid;
114 ucred->mu_o_gid = pud->pud_gid;
115 ucred->mu_o_fsuid = pud->pud_fsuid;
116 ucred->mu_o_fsgid = pud->pud_fsgid;
118 if (type == BODY_INIT) {
119 struct mdt_body *body = (struct mdt_body *)buf;
121 ucred->mu_suppgids[0] = body->suppgid;
122 ucred->mu_suppgids[1] = -1;
125 /* sanity check: we expect the uid which client claimed is true */
126 if (med->med_rmtclient) {
127 if (req->rq_auth_mapped_uid == INVALID_UID) {
128 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
132 if (ptlrpc_user_desc_do_idmap(req, pud))
135 if (req->rq_auth_mapped_uid != pud->pud_uid) {
136 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
137 "while client claims %u:%u/%u:%u\n",
138 libcfs_nid2str(peernid), req->rq_auth_uid,
139 req->rq_auth_mapped_uid,
140 pud->pud_uid, pud->pud_gid,
141 pud->pud_fsuid, pud->pud_fsgid);
145 if (req->rq_auth_uid != pud->pud_uid) {
146 CDEBUG(D_SEC, "local client %s: auth uid %u "
147 "while client claims %u:%u/%u:%u\n",
148 libcfs_nid2str(peernid), req->rq_auth_uid,
149 pud->pud_uid, pud->pud_gid,
150 pud->pud_fsuid, pud->pud_fsgid);
155 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
156 if (med->med_rmtclient) {
157 CDEBUG(D_SEC, "remote client must run with identity_get "
161 ucred->mu_identity = NULL;
162 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
166 struct md_identity *identity;
168 identity = mdt_identity_get(mdt->mdt_identity_cache,
170 if (IS_ERR(identity)) {
171 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
172 !med->med_rmtclient)) {
173 ucred->mu_identity = NULL;
174 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
177 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
182 ucred->mu_identity = identity;
183 perm = mdt_identity_get_perm(ucred->mu_identity,
189 /* find out the setuid/setgid attempt */
190 setuid = (pud->pud_uid != pud->pud_fsuid);
191 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
192 (ucred->mu_identity &&
193 (pud->pud_gid != ucred->mu_identity->mi_gid)));
195 /* check permission of setuid */
196 if (setuid && !(perm & CFS_SETUID_PERM)) {
197 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
198 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
199 GOTO(out, rc = -EACCES);
202 /* check permission of setgid */
203 if (setgid && !(perm & CFS_SETGID_PERM)) {
204 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
205 "from %s\n", pud->pud_uid, pud->pud_gid,
206 pud->pud_fsuid, pud->pud_fsgid,
207 ucred->mu_identity->mi_gid, libcfs_nid2str(peernid));
208 GOTO(out, rc = -EACCES);
212 * NB: remote client not allowed to setgroups anyway.
214 if (!med->med_rmtclient && perm & CFS_SETGRP_PERM) {
215 if (pud->pud_ngroups) {
216 /* setgroups for local client */
217 ucred->mu_ginfo = groups_alloc(pud->pud_ngroups);
218 if (!ucred->mu_ginfo) {
219 CERROR("failed to alloc %d groups\n",
221 GOTO(out, rc = -ENOMEM);
224 lustre_groups_from_list(ucred->mu_ginfo,
226 lustre_groups_sort(ucred->mu_ginfo);
228 ucred->mu_ginfo = NULL;
231 ucred->mu_suppgids[0] = -1;
232 ucred->mu_suppgids[1] = -1;
233 ucred->mu_ginfo = NULL;
236 ucred->mu_uid = pud->pud_uid;
237 ucred->mu_gid = pud->pud_gid;
238 ucred->mu_fsuid = pud->pud_fsuid;
239 ucred->mu_fsgid = pud->pud_fsgid;
241 /* XXX: need to process root_squash here. */
242 mdt_root_squash(info);
244 /* remove fs privilege for non-root user */
246 ucred->mu_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
248 ucred->mu_cap = pud->pud_cap;
249 ucred->mu_valid = UCRED_NEW;
255 if (ucred->mu_ginfo) {
256 groups_free(ucred->mu_ginfo);
257 ucred->mu_ginfo = NULL;
259 if (ucred->mu_identity) {
260 mdt_identity_put(mdt->mdt_identity_cache,
262 ucred->mu_identity = NULL;
269 int mdt_check_ucred(struct mdt_thread_info *info)
271 struct ptlrpc_request *req = mdt_info_req(info);
272 struct mdt_export_data *med = mdt_req2med(req);
273 struct mdt_device *mdt = info->mti_mdt;
274 struct ptlrpc_user_desc *pud = req->rq_user_desc;
275 struct md_ucred *ucred = mdt_ucred(info);
276 struct md_identity *identity = NULL;
277 lnet_nid_t peernid = req->rq_peer.nid;
285 if ((ucred->mu_valid == UCRED_OLD) || (ucred->mu_valid == UCRED_NEW))
288 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
291 /* sanity check: if we use strong authentication, we expect the
292 * uid which client claimed is true */
293 if (med->med_rmtclient) {
294 if (req->rq_auth_mapped_uid == INVALID_UID) {
295 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
299 if (ptlrpc_user_desc_do_idmap(req, pud))
302 if (req->rq_auth_mapped_uid != pud->pud_uid) {
303 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
304 "while client claims %u:%u/%u:%u\n",
305 libcfs_nid2str(peernid), req->rq_auth_uid,
306 req->rq_auth_mapped_uid,
307 pud->pud_uid, pud->pud_gid,
308 pud->pud_fsuid, pud->pud_fsgid);
312 if (req->rq_auth_uid != pud->pud_uid) {
313 CDEBUG(D_SEC, "local client %s: auth uid %u "
314 "while client claims %u:%u/%u:%u\n",
315 libcfs_nid2str(peernid), req->rq_auth_uid,
316 pud->pud_uid, pud->pud_gid,
317 pud->pud_fsuid, pud->pud_fsgid);
322 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
323 if (med->med_rmtclient) {
324 CDEBUG(D_SEC, "remote client must run with identity_get "
331 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
332 if (IS_ERR(identity)) {
333 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
334 !med->med_rmtclient)) {
337 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
343 perm = mdt_identity_get_perm(identity, med->med_rmtclient, peernid);
344 /* find out the setuid/setgid attempt */
345 setuid = (pud->pud_uid != pud->pud_fsuid);
346 setgid = (pud->pud_gid != pud->pud_fsgid ||
347 pud->pud_gid != identity->mi_gid);
349 /* check permission of setuid */
350 if (setuid && !(perm & CFS_SETUID_PERM)) {
351 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
352 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
353 GOTO(out, rc = -EACCES);
356 /* check permission of setgid */
357 if (setgid && !(perm & CFS_SETGID_PERM)) {
358 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
359 "from %s\n", pud->pud_uid, pud->pud_gid,
360 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
361 libcfs_nid2str(peernid));
362 GOTO(out, rc = -EACCES);
368 mdt_identity_put(mdt->mdt_identity_cache, identity);
372 static int old_init_ucred(struct mdt_thread_info *info,
373 struct mdt_body *body)
375 struct md_ucred *uc = mdt_ucred(info);
376 struct mdt_device *mdt = info->mti_mdt;
377 struct md_identity *identity = NULL;
381 uc->mu_valid = UCRED_INVALID;
382 uc->mu_o_uid = uc->mu_uid = body->uid;
383 uc->mu_o_gid = uc->mu_gid = body->gid;
384 uc->mu_o_fsuid = uc->mu_fsuid = body->fsuid;
385 uc->mu_o_fsgid = uc->mu_fsgid = body->fsgid;
386 uc->mu_suppgids[0] = body->suppgid;
387 uc->mu_suppgids[1] = -1;
389 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
390 identity = mdt_identity_get(mdt->mdt_identity_cache,
392 if (IS_ERR(identity)) {
393 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
396 CDEBUG(D_SEC, "Deny access without identity: "
397 "uid %u\n", uc->mu_fsuid);
402 uc->mu_identity = identity;
404 /* XXX: need to process root_squash here. */
405 mdt_root_squash(info);
407 /* remove fs privilege for non-root user */
409 uc->mu_cap = body->capability & ~CFS_CAP_FS_MASK;
411 uc->mu_cap = body->capability;
412 uc->mu_valid = UCRED_OLD;
417 static int old_init_ucred_reint(struct mdt_thread_info *info)
419 struct md_ucred *uc = mdt_ucred(info);
420 struct mdt_device *mdt = info->mti_mdt;
421 struct md_identity *identity = NULL;
425 uc->mu_valid = UCRED_INVALID;
426 uc->mu_o_uid = uc->mu_o_fsuid = uc->mu_uid = uc->mu_fsuid;
427 uc->mu_o_gid = uc->mu_o_fsgid = uc->mu_gid = uc->mu_fsgid;
429 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
430 identity = mdt_identity_get(mdt->mdt_identity_cache,
432 if (IS_ERR(identity)) {
433 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
436 CDEBUG(D_SEC, "Deny access without identity: "
437 "uid %u\n", uc->mu_fsuid);
442 uc->mu_identity = identity;
444 /* XXX: need to process root_squash here. */
445 mdt_root_squash(info);
447 /* remove fs privilege for non-root user */
449 uc->mu_cap &= ~CFS_CAP_FS_MASK;
450 uc->mu_valid = UCRED_OLD;
455 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
457 struct ptlrpc_request *req = mdt_info_req(info);
458 struct md_ucred *uc = mdt_ucred(info);
460 if ((uc->mu_valid == UCRED_OLD) || (uc->mu_valid == UCRED_NEW))
463 mdt_exit_ucred(info);
465 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
466 return old_init_ucred(info, body);
468 return new_init_ucred(info, BODY_INIT, body);
471 int mdt_init_ucred_reint(struct mdt_thread_info *info)
473 struct ptlrpc_request *req = mdt_info_req(info);
474 struct md_ucred *uc = mdt_ucred(info);
476 if ((uc->mu_valid == UCRED_OLD) || (uc->mu_valid == UCRED_NEW))
479 mdt_exit_ucred(info);
481 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
482 return old_init_ucred_reint(info);
484 return new_init_ucred(info, REC_INIT, NULL);
487 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
488 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm)
490 const struct lov_ost_data_v1 *lod;
493 le16_to_cpu(((struct lov_user_md*)lmm)->lmm_stripe_count);
495 CDEBUG(level, "objid "LPX64", magic 0x%08X, pattern %#X\n",
496 le64_to_cpu(lmm->lmm_object_id), le32_to_cpu(lmm->lmm_magic),
497 le32_to_cpu(lmm->lmm_pattern));
498 CDEBUG(level,"stripe_size=0x%x, stripe_count=0x%x\n",
499 le32_to_cpu(lmm->lmm_stripe_size),
500 le32_to_cpu(lmm->lmm_stripe_count));
501 LASSERT(stripe_count <= (__s16)LOV_MAX_STRIPE_COUNT);
502 for (i = 0, lod = lmm->lmm_objects; i < stripe_count; i++, lod++) {
503 CDEBUG(level, "stripe %u idx %u subobj "LPX64"/"LPX64"\n",
504 i, le32_to_cpu(lod->l_ost_idx),
505 le64_to_cpu(lod->l_object_gr),
506 le64_to_cpu(lod->l_object_id));
510 void mdt_shrink_reply(struct mdt_thread_info *info)
512 struct req_capsule *pill = info->mti_pill;
513 struct mdt_body *body;
518 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
519 LASSERT(body != NULL);
521 if (body->valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE | OBD_MD_LINKNAME))
522 md_size = body->eadatasize;
526 acl_size = body->aclsize;
528 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d"
529 " MDSCAPA = "LPX64", OSSCAPA = "LPX64"\n",
531 body->valid & OBD_MD_FLMDSCAPA,
532 body->valid & OBD_MD_FLOSSCAPA);
536 &RMF_ACL, or &RMF_LOGCOOKIES
537 (optional) &RMF_CAPA1,
538 (optional) &RMF_CAPA2,
539 (optional) something else
542 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
543 req_capsule_shrink(pill, &RMF_MDT_MD, md_size,
545 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
546 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
547 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
548 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
549 acl_size, RCL_SERVER);
551 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
552 !(body->valid & OBD_MD_FLMDSCAPA))
553 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
555 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
556 !(body->valid & OBD_MD_FLOSSCAPA))
557 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
560 * Some more field should be shrinked if needed.
561 * This should be done by those who added fields to reply message.
567 /* if object is dying, pack the lov/llog data,
568 * parameter info->mti_attr should be valid at this point! */
569 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
570 const struct md_attr *ma)
572 struct mdt_body *repbody;
573 const struct lu_attr *la = &ma->ma_attr;
576 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
577 LASSERT(repbody != NULL);
579 if (ma->ma_valid & MA_INODE)
580 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
582 if (ma->ma_valid & MA_LOV) {
585 if (mdt_object_exists(mo) < 0)
586 /* If it is a remote object, and we do not retrieve
587 * EA back unlink reg file*/
590 mode = lu_object_attr(&mo->mot_obj.mo_lu);
592 LASSERT(ma->ma_lmm_size);
593 mdt_dump_lmm(D_INFO, ma->ma_lmm);
594 repbody->eadatasize = ma->ma_lmm_size;
596 repbody->valid |= OBD_MD_FLEASIZE;
597 else if (S_ISDIR(mode))
598 repbody->valid |= OBD_MD_FLDIREA;
603 if (ma->ma_cookie_size && (ma->ma_valid & MA_COOKIE)) {
604 repbody->aclsize = ma->ma_cookie_size;
605 repbody->valid |= OBD_MD_FLCOOKIE;
611 static inline unsigned int attr_unpack(__u64 sa_valid) {
612 unsigned int ia_valid = 0;
614 if (sa_valid & MDS_ATTR_MODE)
615 ia_valid |= ATTR_MODE;
616 if (sa_valid & MDS_ATTR_UID)
617 ia_valid |= ATTR_UID;
618 if (sa_valid & MDS_ATTR_GID)
619 ia_valid |= ATTR_GID;
620 if (sa_valid & MDS_ATTR_SIZE)
621 ia_valid |= ATTR_SIZE;
622 if (sa_valid & MDS_ATTR_ATIME)
623 ia_valid |= ATTR_ATIME;
624 if (sa_valid & MDS_ATTR_MTIME)
625 ia_valid |= ATTR_MTIME;
626 if (sa_valid & MDS_ATTR_CTIME)
627 ia_valid |= ATTR_CTIME;
628 if (sa_valid & MDS_ATTR_ATIME_SET)
629 ia_valid |= ATTR_ATIME_SET;
630 if (sa_valid & MDS_ATTR_MTIME_SET)
631 ia_valid |= ATTR_MTIME_SET;
632 if (sa_valid & MDS_ATTR_FORCE)
633 ia_valid |= ATTR_FORCE;
634 if (sa_valid & MDS_ATTR_ATTR_FLAG)
635 ia_valid |= ATTR_ATTR_FLAG;
636 if (sa_valid & MDS_ATTR_KILL_SUID)
637 ia_valid |= ATTR_KILL_SUID;
638 if (sa_valid & MDS_ATTR_KILL_SGID)
639 ia_valid |= ATTR_KILL_SGID;
640 if (sa_valid & MDS_ATTR_CTIME_SET)
641 ia_valid |= ATTR_CTIME_SET;
642 if (sa_valid & MDS_ATTR_FROM_OPEN)
643 ia_valid |= ATTR_FROM_OPEN;
644 if (sa_valid & MDS_ATTR_BLOCKS)
645 ia_valid |= ATTR_BLOCKS;
646 if (sa_valid & MDS_OPEN_OWNEROVERRIDE)
647 ia_valid |= MDS_OPEN_OWNEROVERRIDE;
651 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
665 if (in & ATTR_BLOCKS)
668 if (in & ATTR_FROM_OPEN)
669 rr->rr_flags |= MRF_SETATTR_LOCKED;
671 if (in & ATTR_ATIME_SET)
674 if (in & ATTR_CTIME_SET)
677 if (in & ATTR_MTIME_SET)
680 if (in & ATTR_ATTR_FLAG)
683 if (in & MDS_OPEN_OWNEROVERRIDE)
684 ma->ma_attr_flags |= MDS_OPEN_OWNEROVERRIDE;
686 if (in & (ATTR_KILL_SUID|ATTR_KILL_SGID))
687 ma->ma_attr_flags |= MDS_PERM_BYPASS;
689 /*XXX need ATTR_RAW?*/
690 in &= ~(ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_BLOCKS|
691 ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_FROM_OPEN|
692 ATTR_ATIME_SET|ATTR_CTIME_SET|ATTR_MTIME_SET|
693 ATTR_ATTR_FLAG|ATTR_RAW|MDS_OPEN_OWNEROVERRIDE|
694 ATTR_FORCE|ATTR_KILL_SUID);
696 CERROR("Unknown attr bits: %#llx\n", in);
701 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
703 struct md_ucred *uc = mdt_ucred(info);
704 struct md_attr *ma = &info->mti_attr;
705 struct lu_attr *la = &ma->ma_attr;
706 struct req_capsule *pill = info->mti_pill;
707 struct mdt_reint_record *rr = &info->mti_rr;
708 struct mdt_rec_setattr *rec;
711 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
712 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
716 uc->mu_fsuid = rec->sa_fsuid;
717 uc->mu_fsgid = rec->sa_fsgid;
718 uc->mu_cap = rec->sa_cap;
719 uc->mu_suppgids[0] = rec->sa_suppgid;
720 uc->mu_suppgids[1] = -1;
722 rr->rr_fid1 = &rec->sa_fid;
723 la->la_valid = mdt_attr_valid_xlate(attr_unpack(rec->sa_valid), rr, ma);
724 la->la_mode = rec->sa_mode;
725 la->la_flags = rec->sa_attr_flags;
726 la->la_uid = rec->sa_uid;
727 la->la_gid = rec->sa_gid;
728 la->la_size = rec->sa_size;
729 la->la_blocks = rec->sa_blocks;
730 la->la_ctime = rec->sa_ctime;
731 la->la_atime = rec->sa_atime;
732 la->la_mtime = rec->sa_mtime;
733 ma->ma_valid = MA_INODE;
735 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
736 mdt_set_capainfo(info, 0, rr->rr_fid1,
737 req_capsule_client_get(pill, &RMF_CAPA1));
742 static int mdt_epoch_unpack(struct mdt_thread_info *info)
744 struct req_capsule *pill = info->mti_pill;
747 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
748 info->mti_epoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
750 info->mti_epoch = NULL;
751 RETURN(info->mti_epoch == NULL ? -EFAULT : 0);
754 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
755 struct req_capsule *pill = info->mti_pill;
757 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
758 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
759 if (info->mti_dlm_req == NULL)
766 static int mdt_setattr_unpack(struct mdt_thread_info *info)
768 struct md_attr *ma = &info->mti_attr;
769 struct req_capsule *pill = info->mti_pill;
773 rc = mdt_setattr_unpack_rec(info);
777 /* Epoch may be absent */
778 mdt_epoch_unpack(info);
780 ma->ma_lmm_size = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
781 if (ma->ma_lmm_size) {
782 ma->ma_lmm = req_capsule_client_get(pill, &RMF_EADATA);
783 ma->ma_valid |= MA_LOV;
786 ma->ma_cookie_size = req_capsule_get_size(pill, &RMF_LOGCOOKIES,
788 if (ma->ma_cookie_size) {
789 ma->ma_cookie = req_capsule_client_get(pill, &RMF_LOGCOOKIES);
790 ma->ma_valid |= MA_COOKIE;
793 rc = mdt_dlmreq_unpack(info);
797 int mdt_close_unpack(struct mdt_thread_info *info)
802 rc = mdt_epoch_unpack(info);
806 RETURN(mdt_setattr_unpack_rec(info));
809 static int mdt_create_unpack(struct mdt_thread_info *info)
811 struct md_ucred *uc = mdt_ucred(info);
812 struct mdt_rec_create *rec;
813 struct lu_attr *attr = &info->mti_attr.ma_attr;
814 struct mdt_reint_record *rr = &info->mti_rr;
815 struct req_capsule *pill = info->mti_pill;
816 struct md_op_spec *sp = &info->mti_spec;
820 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
821 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
825 uc->mu_fsuid = rec->cr_fsuid;
826 uc->mu_fsgid = rec->cr_fsgid;
827 uc->mu_cap = rec->cr_cap;
828 uc->mu_suppgids[0] = rec->cr_suppgid1;
829 uc->mu_suppgids[1] = -1;
831 rr->rr_fid1 = &rec->cr_fid1;
832 rr->rr_fid2 = &rec->cr_fid2;
833 attr->la_mode = rec->cr_mode;
834 attr->la_rdev = rec->cr_rdev;
835 attr->la_uid = rec->cr_fsuid;
836 attr->la_gid = rec->cr_fsgid;
837 attr->la_ctime = rec->cr_time;
838 attr->la_mtime = rec->cr_time;
839 attr->la_atime = rec->cr_time;
840 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
841 LA_CTIME | LA_MTIME | LA_ATIME;
842 memset(&sp->u, 0, sizeof(sp->u));
843 sp->sp_cr_flags = rec->cr_flags;
844 sp->sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
845 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
847 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
848 mdt_set_capainfo(info, 0, rr->rr_fid1,
849 req_capsule_client_get(pill, &RMF_CAPA1));
850 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
852 if (!info->mti_cross_ref) {
853 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
854 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
855 LASSERT(rr->rr_name && rr->rr_namelen > 0);
861 #ifdef CONFIG_FS_POSIX_ACL
862 if (sp->sp_cr_flags & MDS_CREATE_RMT_ACL) {
863 if (S_ISDIR(attr->la_mode))
864 sp->u.sp_pfid = rr->rr_fid1;
865 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
866 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
868 sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA);
869 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
871 sp->u.sp_ea.fid = rr->rr_fid1;
875 if (S_ISDIR(attr->la_mode)) {
876 /* pass parent fid for cross-ref cases */
877 sp->u.sp_pfid = rr->rr_fid1;
878 if (sp->sp_cr_flags & MDS_CREATE_SLAVE_OBJ) {
879 /* create salve object req, need
880 * unpack split ea here
882 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SLAVE);
883 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
885 sp->u.sp_ea.eadata = req_capsule_client_get(pill,
887 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill,
890 sp->u.sp_ea.fid = rr->rr_fid1;
893 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
894 } else if (S_ISLNK(attr->la_mode)) {
895 const char *tgt = NULL;
897 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
898 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
899 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
900 sp->u.sp_symname = tgt;
905 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
907 rc = mdt_dlmreq_unpack(info);
911 static int mdt_link_unpack(struct mdt_thread_info *info)
913 struct md_ucred *uc = mdt_ucred(info);
914 struct mdt_rec_link *rec;
915 struct lu_attr *attr = &info->mti_attr.ma_attr;
916 struct mdt_reint_record *rr = &info->mti_rr;
917 struct req_capsule *pill = info->mti_pill;
921 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
922 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
926 uc->mu_fsuid = rec->lk_fsuid;
927 uc->mu_fsgid = rec->lk_fsgid;
928 uc->mu_cap = rec->lk_cap;
929 uc->mu_suppgids[0] = rec->lk_suppgid1;
930 uc->mu_suppgids[1] = rec->lk_suppgid2;
932 attr->la_uid = rec->lk_fsuid;
933 attr->la_gid = rec->lk_fsgid;
934 rr->rr_fid1 = &rec->lk_fid1;
935 rr->rr_fid2 = &rec->lk_fid2;
936 attr->la_ctime = rec->lk_time;
937 attr->la_mtime = rec->lk_time;
938 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
940 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
941 mdt_set_capainfo(info, 0, rr->rr_fid1,
942 req_capsule_client_get(pill, &RMF_CAPA1));
943 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
944 mdt_set_capainfo(info, 1, rr->rr_fid2,
945 req_capsule_client_get(pill, &RMF_CAPA2));
947 info->mti_spec.sp_ck_split = !!(rec->lk_bias & MDS_CHECK_SPLIT);
948 info->mti_cross_ref = !!(rec->lk_bias & MDS_CROSS_REF);
949 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
950 if (rr->rr_name == NULL)
952 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
953 if (!info->mti_cross_ref)
954 LASSERT(rr->rr_namelen > 0);
956 rc = mdt_dlmreq_unpack(info);
960 static int mdt_unlink_unpack(struct mdt_thread_info *info)
962 struct md_ucred *uc = mdt_ucred(info);
963 struct mdt_rec_unlink *rec;
964 struct md_attr *ma = &info->mti_attr;
965 struct lu_attr *attr = &info->mti_attr.ma_attr;
966 struct mdt_reint_record *rr = &info->mti_rr;
967 struct req_capsule *pill = info->mti_pill;
971 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
972 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
976 uc->mu_fsuid = rec->ul_fsuid;
977 uc->mu_fsgid = rec->ul_fsgid;
978 uc->mu_cap = rec->ul_cap;
979 uc->mu_suppgids[0] = rec->ul_suppgid1;
980 uc->mu_suppgids[1] = -1;
982 attr->la_uid = rec->ul_fsuid;
983 attr->la_gid = rec->ul_fsgid;
984 rr->rr_fid1 = &rec->ul_fid1;
985 rr->rr_fid2 = &rec->ul_fid2;
986 attr->la_ctime = rec->ul_time;
987 attr->la_mtime = rec->ul_time;
988 attr->la_mode = rec->ul_mode;
989 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
991 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
992 mdt_set_capainfo(info, 0, rr->rr_fid1,
993 req_capsule_client_get(pill, &RMF_CAPA1));
995 info->mti_cross_ref = !!(rec->ul_bias & MDS_CROSS_REF);
996 if (!info->mti_cross_ref) {
997 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
998 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
999 if (rr->rr_name == NULL || rr->rr_namelen == 0)
1006 info->mti_spec.sp_ck_split = !!(rec->ul_bias & MDS_CHECK_SPLIT);
1007 if (rec->ul_bias & MDS_VTX_BYPASS)
1008 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1010 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1012 rc = mdt_dlmreq_unpack(info);
1016 static int mdt_rename_unpack(struct mdt_thread_info *info)
1018 struct md_ucred *uc = mdt_ucred(info);
1019 struct mdt_rec_rename *rec;
1020 struct md_attr *ma = &info->mti_attr;
1021 struct lu_attr *attr = &info->mti_attr.ma_attr;
1022 struct mdt_reint_record *rr = &info->mti_rr;
1023 struct req_capsule *pill = info->mti_pill;
1027 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1028 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1032 uc->mu_fsuid = rec->rn_fsuid;
1033 uc->mu_fsgid = rec->rn_fsgid;
1034 uc->mu_cap = rec->rn_cap;
1035 uc->mu_suppgids[0] = rec->rn_suppgid1;
1036 uc->mu_suppgids[1] = rec->rn_suppgid2;
1038 attr->la_uid = rec->rn_fsuid;
1039 attr->la_gid = rec->rn_fsgid;
1040 rr->rr_fid1 = &rec->rn_fid1;
1041 rr->rr_fid2 = &rec->rn_fid2;
1042 attr->la_ctime = rec->rn_time;
1043 attr->la_mtime = rec->rn_time;
1044 /* rename_tgt contains the mode already */
1045 attr->la_mode = rec->rn_mode;
1046 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1048 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1049 mdt_set_capainfo(info, 0, rr->rr_fid1,
1050 req_capsule_client_get(pill, &RMF_CAPA1));
1051 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1052 mdt_set_capainfo(info, 1, rr->rr_fid2,
1053 req_capsule_client_get(pill, &RMF_CAPA2));
1055 info->mti_spec.sp_ck_split = !!(rec->rn_bias & MDS_CHECK_SPLIT);
1056 info->mti_cross_ref = !!(rec->rn_bias & MDS_CROSS_REF);
1057 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1058 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1059 if (rr->rr_name == NULL || rr->rr_tgt == NULL)
1061 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1062 rr->rr_tgtlen = req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT) - 1;
1063 if (!info->mti_cross_ref)
1064 LASSERT(rr->rr_namelen > 0 && rr->rr_tgtlen > 0);
1065 if (rec->rn_bias & MDS_VTX_BYPASS)
1066 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1068 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1070 rc = mdt_dlmreq_unpack(info);
1074 static int mdt_open_unpack(struct mdt_thread_info *info)
1076 struct md_ucred *uc = mdt_ucred(info);
1077 struct mdt_rec_create *rec;
1078 struct lu_attr *attr = &info->mti_attr.ma_attr;
1079 struct req_capsule *pill = info->mti_pill;
1080 struct mdt_reint_record *rr = &info->mti_rr;
1081 struct ptlrpc_request *req = mdt_info_req(info);
1082 struct md_op_spec *sp = &info->mti_spec;
1085 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1086 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1090 uc->mu_fsuid = rec->cr_fsuid;
1091 uc->mu_fsgid = rec->cr_fsgid;
1092 uc->mu_cap = rec->cr_cap;
1093 uc->mu_suppgids[0] = rec->cr_suppgid1;
1094 uc->mu_suppgids[1] = rec->cr_suppgid2;
1096 rr->rr_fid1 = &rec->cr_fid1;
1097 rr->rr_fid2 = &rec->cr_fid2;
1098 rr->rr_handle = &rec->cr_old_handle;
1099 attr->la_mode = rec->cr_mode;
1100 attr->la_rdev = rec->cr_rdev;
1101 attr->la_uid = rec->cr_fsuid;
1102 attr->la_gid = rec->cr_fsgid;
1103 attr->la_ctime = rec->cr_time;
1104 attr->la_mtime = rec->cr_time;
1105 attr->la_atime = rec->cr_time;
1106 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1107 LA_CTIME | LA_MTIME | LA_ATIME;
1108 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1109 info->mti_spec.sp_cr_flags = rec->cr_flags;
1110 info->mti_replayepoch = rec->cr_ioepoch;
1112 info->mti_spec.sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
1113 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1115 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1116 mdt_set_capainfo(info, 0, rr->rr_fid1,
1117 req_capsule_client_get(pill, &RMF_CAPA1));
1118 if ((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
1119 (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))) {
1121 mdt_set_capainfo(info, 1, rr->rr_fid2,
1122 req_capsule_client_get(pill, &RMF_CAPA2));
1125 * FIXME: capa in replay open request might have expired,
1126 * bypass capa check. Security hole?
1128 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1129 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1133 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1134 if (rr->rr_name == NULL)
1136 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1138 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1140 if (sp->u.sp_ea.eadatalen) {
1141 sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA);
1142 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1143 sp->u.sp_ea.no_lov_create = 1;
1149 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1151 struct mdt_reint_record *rr = &info->mti_rr;
1152 struct md_ucred *uc = mdt_ucred(info);
1153 struct lu_attr *attr = &info->mti_attr.ma_attr;
1154 struct req_capsule *pill = info->mti_pill;
1155 struct mdt_rec_setxattr *rec;
1159 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1160 sizeof(struct mdt_rec_reint));
1162 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1166 uc->mu_fsuid = rec->sx_fsuid;
1167 uc->mu_fsgid = rec->sx_fsgid;
1168 uc->mu_cap = rec->sx_cap;
1169 uc->mu_suppgids[0] = rec->sx_suppgid1;
1170 uc->mu_suppgids[1] = -1;
1172 rr->rr_opcode = rec->sx_opcode;
1173 rr->rr_fid1 = &rec->sx_fid;
1174 attr->la_valid = rec->sx_valid;
1175 attr->la_ctime = rec->sx_time;
1176 attr->la_size = rec->sx_size;
1177 attr->la_flags = rec->sx_flags;
1179 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1180 mdt_set_capainfo(info, 0, rr->rr_fid1,
1181 req_capsule_client_get(pill, &RMF_CAPA1));
1183 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1185 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1186 if (rr->rr_name == NULL)
1188 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1189 LASSERT(rr->rr_namelen > 0);
1191 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
1192 if (rr->rr_eadatalen > 0) {
1193 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1194 if (rr->rr_eadata == NULL)
1202 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1204 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1205 [REINT_SETATTR] = mdt_setattr_unpack,
1206 [REINT_CREATE] = mdt_create_unpack,
1207 [REINT_LINK] = mdt_link_unpack,
1208 [REINT_UNLINK] = mdt_unlink_unpack,
1209 [REINT_RENAME] = mdt_rename_unpack,
1210 [REINT_OPEN] = mdt_open_unpack,
1211 [REINT_SETXATTR] = mdt_setxattr_unpack
1214 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1219 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1220 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1221 info->mti_rr.rr_opcode = op;
1222 rc = mdt_reint_unpackers[op](info);
1224 CERROR("Unexpected opcode %d\n", op);