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 [sun.com URL with a
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 & ~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 & ~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 &= ~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 printk("in=%x,out=%x\n", in, out );
687 /*XXX need ATTR_RAW?*/
688 in &= ~(ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_BLOCKS|
689 ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_FROM_OPEN|
690 ATTR_ATIME_SET|ATTR_CTIME_SET|ATTR_MTIME_SET|
691 ATTR_ATTR_FLAG|ATTR_RAW|MDS_OPEN_OWNEROVERRIDE);
693 CERROR("Unknown attr bits: %#llx\n", in);
698 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
700 struct md_ucred *uc = mdt_ucred(info);
701 struct md_attr *ma = &info->mti_attr;
702 struct lu_attr *la = &ma->ma_attr;
703 struct req_capsule *pill = info->mti_pill;
704 struct mdt_reint_record *rr = &info->mti_rr;
705 struct mdt_rec_setattr *rec;
708 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
709 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
713 uc->mu_fsuid = rec->sa_fsuid;
714 uc->mu_fsgid = rec->sa_fsgid;
715 uc->mu_cap = rec->sa_cap;
716 uc->mu_suppgids[0] = rec->sa_suppgid;
717 uc->mu_suppgids[1] = -1;
719 rr->rr_fid1 = &rec->sa_fid;
720 la->la_valid = mdt_attr_valid_xlate(attr_unpack(rec->sa_valid), rr, ma);
721 la->la_mode = rec->sa_mode;
722 la->la_flags = rec->sa_attr_flags;
723 la->la_uid = rec->sa_uid;
724 la->la_gid = rec->sa_gid;
725 la->la_size = rec->sa_size;
726 la->la_blocks = rec->sa_blocks;
727 la->la_ctime = rec->sa_ctime;
728 la->la_atime = rec->sa_atime;
729 la->la_mtime = rec->sa_mtime;
730 ma->ma_valid = MA_INODE;
732 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
733 mdt_set_capainfo(info, 0, rr->rr_fid1,
734 req_capsule_client_get(pill, &RMF_CAPA1));
739 static int mdt_epoch_unpack(struct mdt_thread_info *info)
741 struct req_capsule *pill = info->mti_pill;
744 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
745 info->mti_epoch = req_capsule_client_get(pill, &RMF_MDT_EPOCH);
747 info->mti_epoch = NULL;
748 RETURN(info->mti_epoch == NULL ? -EFAULT : 0);
751 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
752 struct req_capsule *pill = info->mti_pill;
754 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
755 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
756 if (info->mti_dlm_req == NULL)
763 static int mdt_setattr_unpack(struct mdt_thread_info *info)
765 struct md_attr *ma = &info->mti_attr;
766 struct req_capsule *pill = info->mti_pill;
770 rc = mdt_setattr_unpack_rec(info);
774 /* Epoch may be absent */
775 mdt_epoch_unpack(info);
777 ma->ma_lmm_size = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
778 if (ma->ma_lmm_size) {
779 ma->ma_lmm = req_capsule_client_get(pill, &RMF_EADATA);
780 ma->ma_valid |= MA_LOV;
783 ma->ma_cookie_size = req_capsule_get_size(pill, &RMF_LOGCOOKIES,
785 if (ma->ma_cookie_size) {
786 ma->ma_cookie = req_capsule_client_get(pill, &RMF_LOGCOOKIES);
787 ma->ma_valid |= MA_COOKIE;
790 rc = mdt_dlmreq_unpack(info);
794 int mdt_close_unpack(struct mdt_thread_info *info)
799 rc = mdt_epoch_unpack(info);
803 RETURN(mdt_setattr_unpack_rec(info));
806 static int mdt_create_unpack(struct mdt_thread_info *info)
808 struct md_ucred *uc = mdt_ucred(info);
809 struct mdt_rec_create *rec;
810 struct lu_attr *attr = &info->mti_attr.ma_attr;
811 struct mdt_reint_record *rr = &info->mti_rr;
812 struct req_capsule *pill = info->mti_pill;
813 struct md_op_spec *sp = &info->mti_spec;
817 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
818 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
822 uc->mu_fsuid = rec->cr_fsuid;
823 uc->mu_fsgid = rec->cr_fsgid;
824 uc->mu_cap = rec->cr_cap;
825 uc->mu_suppgids[0] = rec->cr_suppgid1;
826 uc->mu_suppgids[1] = -1;
828 rr->rr_fid1 = &rec->cr_fid1;
829 rr->rr_fid2 = &rec->cr_fid2;
830 attr->la_mode = rec->cr_mode;
831 attr->la_rdev = rec->cr_rdev;
832 attr->la_uid = rec->cr_fsuid;
833 attr->la_gid = rec->cr_fsgid;
834 attr->la_ctime = rec->cr_time;
835 attr->la_mtime = rec->cr_time;
836 attr->la_atime = rec->cr_time;
837 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
838 LA_CTIME | LA_MTIME | LA_ATIME;
839 memset(&sp->u, 0, sizeof(sp->u));
840 sp->sp_cr_flags = rec->cr_flags;
841 sp->sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
842 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
844 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
845 mdt_set_capainfo(info, 0, rr->rr_fid1,
846 req_capsule_client_get(pill, &RMF_CAPA1));
847 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
849 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
850 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
851 LASSERT(rr->rr_name && rr->rr_namelen > 0);
853 #ifdef CONFIG_FS_POSIX_ACL
854 if (sp->sp_cr_flags & MDS_CREATE_RMT_ACL) {
855 if (S_ISDIR(attr->la_mode))
856 sp->u.sp_pfid = rr->rr_fid1;
857 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
858 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
860 sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA);
861 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
863 sp->u.sp_ea.fid = rr->rr_fid1;
867 if (S_ISDIR(attr->la_mode)) {
868 /* pass parent fid for cross-ref cases */
869 sp->u.sp_pfid = rr->rr_fid1;
870 if (sp->sp_cr_flags & MDS_CREATE_SLAVE_OBJ) {
871 /* create salve object req, need
872 * unpack split ea here
874 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SLAVE);
875 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
877 sp->u.sp_ea.eadata = req_capsule_client_get(pill,
879 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill,
882 sp->u.sp_ea.fid = rr->rr_fid1;
885 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
886 } else if (S_ISLNK(attr->la_mode)) {
887 const char *tgt = NULL;
889 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
890 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
891 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
892 sp->u.sp_symname = tgt;
897 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
899 rc = mdt_dlmreq_unpack(info);
903 static int mdt_link_unpack(struct mdt_thread_info *info)
905 struct md_ucred *uc = mdt_ucred(info);
906 struct mdt_rec_link *rec;
907 struct lu_attr *attr = &info->mti_attr.ma_attr;
908 struct mdt_reint_record *rr = &info->mti_rr;
909 struct req_capsule *pill = info->mti_pill;
913 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
914 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
918 uc->mu_fsuid = rec->lk_fsuid;
919 uc->mu_fsgid = rec->lk_fsgid;
920 uc->mu_cap = rec->lk_cap;
921 uc->mu_suppgids[0] = rec->lk_suppgid1;
922 uc->mu_suppgids[1] = rec->lk_suppgid2;
924 attr->la_uid = rec->lk_fsuid;
925 attr->la_gid = rec->lk_fsgid;
926 rr->rr_fid1 = &rec->lk_fid1;
927 rr->rr_fid2 = &rec->lk_fid2;
928 attr->la_ctime = rec->lk_time;
929 attr->la_mtime = rec->lk_time;
930 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
932 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
933 mdt_set_capainfo(info, 0, rr->rr_fid1,
934 req_capsule_client_get(pill, &RMF_CAPA1));
935 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
936 mdt_set_capainfo(info, 1, rr->rr_fid2,
937 req_capsule_client_get(pill, &RMF_CAPA2));
939 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
940 if (rr->rr_name == NULL)
942 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
943 LASSERT(rr->rr_namelen > 0);
944 info->mti_spec.sp_ck_split = !!(rec->lk_bias & MDS_CHECK_SPLIT);
945 info->mti_cross_ref = !!(rec->lk_bias & MDS_CROSS_REF);
947 rc = mdt_dlmreq_unpack(info);
951 static int mdt_unlink_unpack(struct mdt_thread_info *info)
953 struct md_ucred *uc = mdt_ucred(info);
954 struct mdt_rec_unlink *rec;
955 struct md_attr *ma = &info->mti_attr;
956 struct lu_attr *attr = &info->mti_attr.ma_attr;
957 struct mdt_reint_record *rr = &info->mti_rr;
958 struct req_capsule *pill = info->mti_pill;
962 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
963 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
967 uc->mu_fsuid = rec->ul_fsuid;
968 uc->mu_fsgid = rec->ul_fsgid;
969 uc->mu_cap = rec->ul_cap;
970 uc->mu_suppgids[0] = rec->ul_suppgid1;
971 uc->mu_suppgids[1] = -1;
973 attr->la_uid = rec->ul_fsuid;
974 attr->la_gid = rec->ul_fsgid;
975 rr->rr_fid1 = &rec->ul_fid1;
976 rr->rr_fid2 = &rec->ul_fid2;
977 attr->la_ctime = rec->ul_time;
978 attr->la_mtime = rec->ul_time;
979 attr->la_mode = rec->ul_mode;
980 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
982 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
983 mdt_set_capainfo(info, 0, rr->rr_fid1,
984 req_capsule_client_get(pill, &RMF_CAPA1));
986 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
987 if (rr->rr_name == NULL)
989 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
990 LASSERT(rr->rr_namelen > 0);
991 info->mti_spec.sp_ck_split = !!(rec->ul_bias & MDS_CHECK_SPLIT);
992 info->mti_cross_ref = !!(rec->ul_bias & MDS_CROSS_REF);
993 if (rec->ul_bias & MDS_VTX_BYPASS)
994 ma->ma_attr_flags |= MDS_VTX_BYPASS;
996 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
998 rc = mdt_dlmreq_unpack(info);
1002 static int mdt_rename_unpack(struct mdt_thread_info *info)
1004 struct md_ucred *uc = mdt_ucred(info);
1005 struct mdt_rec_rename *rec;
1006 struct md_attr *ma = &info->mti_attr;
1007 struct lu_attr *attr = &info->mti_attr.ma_attr;
1008 struct mdt_reint_record *rr = &info->mti_rr;
1009 struct req_capsule *pill = info->mti_pill;
1013 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1014 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1018 uc->mu_fsuid = rec->rn_fsuid;
1019 uc->mu_fsgid = rec->rn_fsgid;
1020 uc->mu_cap = rec->rn_cap;
1021 uc->mu_suppgids[0] = rec->rn_suppgid1;
1022 uc->mu_suppgids[1] = rec->rn_suppgid2;
1024 attr->la_uid = rec->rn_fsuid;
1025 attr->la_gid = rec->rn_fsgid;
1026 rr->rr_fid1 = &rec->rn_fid1;
1027 rr->rr_fid2 = &rec->rn_fid2;
1028 attr->la_ctime = rec->rn_time;
1029 attr->la_mtime = rec->rn_time;
1030 /* rename_tgt contains the mode already */
1031 attr->la_mode = rec->rn_mode;
1032 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1034 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1035 mdt_set_capainfo(info, 0, rr->rr_fid1,
1036 req_capsule_client_get(pill, &RMF_CAPA1));
1037 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1038 mdt_set_capainfo(info, 1, rr->rr_fid2,
1039 req_capsule_client_get(pill, &RMF_CAPA2));
1041 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1042 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1043 if (rr->rr_name == NULL || rr->rr_tgt == NULL)
1045 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1046 LASSERT(rr->rr_namelen > 0);
1047 rr->rr_tgtlen = req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT) - 1;
1048 LASSERT(rr->rr_tgtlen > 0);
1049 info->mti_spec.sp_ck_split = !!(rec->rn_bias & MDS_CHECK_SPLIT);
1050 info->mti_cross_ref = !!(rec->rn_bias & MDS_CROSS_REF);
1051 if (rec->rn_bias & MDS_VTX_BYPASS)
1052 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1054 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1056 rc = mdt_dlmreq_unpack(info);
1060 static int mdt_open_unpack(struct mdt_thread_info *info)
1062 struct md_ucred *uc = mdt_ucred(info);
1063 struct mdt_rec_create *rec;
1064 struct lu_attr *attr = &info->mti_attr.ma_attr;
1065 struct req_capsule *pill = info->mti_pill;
1066 struct mdt_reint_record *rr = &info->mti_rr;
1067 struct ptlrpc_request *req = mdt_info_req(info);
1068 struct md_op_spec *sp = &info->mti_spec;
1071 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1072 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1076 uc->mu_fsuid = rec->cr_fsuid;
1077 uc->mu_fsgid = rec->cr_fsgid;
1078 uc->mu_cap = rec->cr_cap;
1079 uc->mu_suppgids[0] = rec->cr_suppgid1;
1080 uc->mu_suppgids[1] = rec->cr_suppgid2;
1082 rr->rr_fid1 = &rec->cr_fid1;
1083 rr->rr_fid2 = &rec->cr_fid2;
1084 rr->rr_handle = &rec->cr_old_handle;
1085 attr->la_mode = rec->cr_mode;
1086 attr->la_rdev = rec->cr_rdev;
1087 attr->la_uid = rec->cr_fsuid;
1088 attr->la_gid = rec->cr_fsgid;
1089 attr->la_ctime = rec->cr_time;
1090 attr->la_mtime = rec->cr_time;
1091 attr->la_atime = rec->cr_time;
1092 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1093 LA_CTIME | LA_MTIME | LA_ATIME;
1094 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1095 info->mti_spec.sp_cr_flags = rec->cr_flags;
1096 info->mti_replayepoch = rec->cr_ioepoch;
1098 info->mti_spec.sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
1099 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1101 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1102 mdt_set_capainfo(info, 0, rr->rr_fid1,
1103 req_capsule_client_get(pill, &RMF_CAPA1));
1104 if ((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
1105 (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))) {
1107 mdt_set_capainfo(info, 1, rr->rr_fid2,
1108 req_capsule_client_get(pill, &RMF_CAPA2));
1111 * FIXME: capa in replay open request might have expired,
1112 * bypass capa check. Security hole?
1114 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1115 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1119 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1120 if (rr->rr_name == NULL)
1122 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1124 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1126 if (sp->u.sp_ea.eadatalen) {
1127 sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA);
1128 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1129 sp->u.sp_ea.no_lov_create = 1;
1135 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1137 struct mdt_reint_record *rr = &info->mti_rr;
1138 struct md_ucred *uc = mdt_ucred(info);
1139 struct lu_attr *attr = &info->mti_attr.ma_attr;
1140 struct req_capsule *pill = info->mti_pill;
1141 struct mdt_rec_setxattr *rec;
1145 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1146 sizeof(struct mdt_rec_reint));
1148 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1152 uc->mu_fsuid = rec->sx_fsuid;
1153 uc->mu_fsgid = rec->sx_fsgid;
1154 uc->mu_cap = rec->sx_cap;
1155 uc->mu_suppgids[0] = rec->sx_suppgid1;
1156 uc->mu_suppgids[1] = -1;
1158 rr->rr_opcode = rec->sx_opcode;
1159 rr->rr_fid1 = &rec->sx_fid;
1160 attr->la_valid = rec->sx_valid;
1161 attr->la_ctime = rec->sx_time;
1162 attr->la_size = rec->sx_size;
1163 attr->la_flags = rec->sx_flags;
1165 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1166 mdt_set_capainfo(info, 0, rr->rr_fid1,
1167 req_capsule_client_get(pill, &RMF_CAPA1));
1169 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1171 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1172 if (rr->rr_name == NULL)
1174 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1175 LASSERT(rr->rr_namelen > 0);
1177 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
1178 if (rr->rr_eadatalen > 0) {
1179 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1180 if (rr->rr_eadata == NULL)
1188 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1190 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1191 [REINT_SETATTR] = mdt_setattr_unpack,
1192 [REINT_CREATE] = mdt_create_unpack,
1193 [REINT_LINK] = mdt_link_unpack,
1194 [REINT_UNLINK] = mdt_unlink_unpack,
1195 [REINT_RENAME] = mdt_rename_unpack,
1196 [REINT_OPEN] = mdt_open_unpack,
1197 [REINT_SETXATTR] = mdt_setxattr_unpack
1200 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1205 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1206 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1207 info->mti_rr.rr_opcode = op;
1208 rc = mdt_reint_unpackers[op](info);
1210 CERROR("Unexpected opcode %d\n", op);