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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/mdt/mdt_lib.c
40 * Lustre Metadata Target (mdt) request unpacking helper.
42 * Author: Peter Braam <braam@clusterfs.com>
43 * Author: Andreas Dilger <adilger@clusterfs.com>
44 * Author: Phil Schwan <phil@clusterfs.com>
45 * Author: Mike Shaver <shaver@clusterfs.com>
46 * Author: Nikita Danilov <nikita@clusterfs.com>
47 * Author: Huang Hua <huanghua@clusterfs.com>
48 * Author: Fan Yong <fanyong@clusterfs.com>
53 # define EXPORT_SYMTAB
55 #define DEBUG_SUBSYSTEM S_MDS
57 #include "mdt_internal.h"
58 #include <lnet/lib-lnet.h>
61 typedef enum ucred_init_type {
67 void mdt_exit_ucred(struct mdt_thread_info *info)
69 struct md_ucred *uc = mdt_ucred(info);
70 struct mdt_device *mdt = info->mti_mdt;
72 if (uc->mu_valid != UCRED_INIT) {
73 uc->mu_suppgids[0] = uc->mu_suppgids[1] = -1;
75 cfs_put_group_info(uc->mu_ginfo);
78 if (uc->mu_identity) {
79 mdt_identity_put(mdt->mdt_identity_cache,
81 uc->mu_identity = NULL;
83 uc->mu_valid = UCRED_INIT;
87 static int match_nosquash_list(cfs_rw_semaphore_t *sem,
94 rc = cfs_match_nid(peernid, nidlist);
99 /* root_squash for inter-MDS operations */
100 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid)
102 struct md_ucred *ucred = mdt_ucred(info);
105 if (!info->mti_mdt->mdt_squash_uid || ucred->mu_fsuid)
108 if (match_nosquash_list(&info->mti_mdt->mdt_squash_sem,
109 &info->mti_mdt->mdt_nosquash_nids,
111 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
112 libcfs_nid2str(peernid));
116 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
117 libcfs_nid2str(peernid),
118 ucred->mu_fsuid, ucred->mu_fsgid, ucred->mu_cap,
119 info->mti_mdt->mdt_squash_uid, info->mti_mdt->mdt_squash_gid,
122 ucred->mu_fsuid = info->mti_mdt->mdt_squash_uid;
123 ucred->mu_fsgid = info->mti_mdt->mdt_squash_gid;
125 ucred->mu_suppgids[0] = -1;
126 ucred->mu_suppgids[1] = -1;
131 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
134 struct ptlrpc_request *req = mdt_info_req(info);
135 struct mdt_device *mdt = info->mti_mdt;
136 struct ptlrpc_user_desc *pud = req->rq_user_desc;
137 struct md_ucred *ucred = mdt_ucred(info);
138 lnet_nid_t peernid = req->rq_peer.nid;
140 __u32 remote = exp_connect_rmtclient(info->mti_exp);
147 LASSERT(req->rq_auth_gss);
148 LASSERT(!req->rq_auth_usr_mdt);
149 LASSERT(req->rq_user_desc);
151 ucred->mu_valid = UCRED_INVALID;
153 ucred->mu_o_uid = pud->pud_uid;
154 ucred->mu_o_gid = pud->pud_gid;
155 ucred->mu_o_fsuid = pud->pud_fsuid;
156 ucred->mu_o_fsgid = pud->pud_fsgid;
158 if (type == BODY_INIT) {
159 struct mdt_body *body = (struct mdt_body *)buf;
161 ucred->mu_suppgids[0] = body->suppgid;
162 ucred->mu_suppgids[1] = -1;
165 /* sanity check: we expect the uid which client claimed is true */
167 if (req->rq_auth_mapped_uid == INVALID_UID) {
168 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
172 if (ptlrpc_user_desc_do_idmap(req, pud))
175 if (req->rq_auth_mapped_uid != pud->pud_uid) {
176 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
177 "while client claims %u:%u/%u:%u\n",
178 libcfs_nid2str(peernid), req->rq_auth_uid,
179 req->rq_auth_mapped_uid,
180 pud->pud_uid, pud->pud_gid,
181 pud->pud_fsuid, pud->pud_fsgid);
185 if (req->rq_auth_uid != pud->pud_uid) {
186 CDEBUG(D_SEC, "local client %s: auth uid %u "
187 "while client claims %u:%u/%u:%u\n",
188 libcfs_nid2str(peernid), req->rq_auth_uid,
189 pud->pud_uid, pud->pud_gid,
190 pud->pud_fsuid, pud->pud_fsgid);
195 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
197 CDEBUG(D_SEC, "remote client must run with identity_get "
201 ucred->mu_identity = NULL;
202 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
206 struct md_identity *identity;
208 identity = mdt_identity_get(mdt->mdt_identity_cache,
210 if (IS_ERR(identity)) {
211 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
213 ucred->mu_identity = NULL;
214 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
217 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
222 ucred->mu_identity = identity;
223 perm = mdt_identity_get_perm(ucred->mu_identity,
228 /* find out the setuid/setgid attempt */
229 setuid = (pud->pud_uid != pud->pud_fsuid);
230 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
231 (ucred->mu_identity &&
232 (pud->pud_gid != ucred->mu_identity->mi_gid)));
234 /* check permission of setuid */
235 if (setuid && !(perm & CFS_SETUID_PERM)) {
236 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
237 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
238 GOTO(out, rc = -EACCES);
241 /* check permission of setgid */
242 if (setgid && !(perm & CFS_SETGID_PERM)) {
243 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
244 "from %s\n", pud->pud_uid, pud->pud_gid,
245 pud->pud_fsuid, pud->pud_fsgid,
246 ucred->mu_identity->mi_gid, libcfs_nid2str(peernid));
247 GOTO(out, rc = -EACCES);
251 * NB: remote client not allowed to setgroups anyway.
253 if (!remote && perm & CFS_SETGRP_PERM) {
254 if (pud->pud_ngroups) {
255 /* setgroups for local client */
256 ucred->mu_ginfo = cfs_groups_alloc(pud->pud_ngroups);
257 if (!ucred->mu_ginfo) {
258 CERROR("failed to alloc %d groups\n",
260 GOTO(out, rc = -ENOMEM);
263 lustre_groups_from_list(ucred->mu_ginfo,
265 lustre_groups_sort(ucred->mu_ginfo);
267 ucred->mu_ginfo = NULL;
270 ucred->mu_suppgids[0] = -1;
271 ucred->mu_suppgids[1] = -1;
272 ucred->mu_ginfo = NULL;
275 ucred->mu_uid = pud->pud_uid;
276 ucred->mu_gid = pud->pud_gid;
277 ucred->mu_fsuid = pud->pud_fsuid;
278 ucred->mu_fsgid = pud->pud_fsgid;
280 /* process root_squash here. */
281 mdt_root_squash(info, peernid);
283 /* remove fs privilege for non-root user. */
285 ucred->mu_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
287 ucred->mu_cap = pud->pud_cap;
288 if (remote && !(perm & CFS_RMTOWN_PERM))
289 ucred->mu_cap &= ~(CFS_CAP_SYS_RESOURCE_MASK |
291 ucred->mu_valid = UCRED_NEW;
297 if (ucred->mu_ginfo) {
298 cfs_put_group_info(ucred->mu_ginfo);
299 ucred->mu_ginfo = NULL;
301 if (ucred->mu_identity) {
302 mdt_identity_put(mdt->mdt_identity_cache,
304 ucred->mu_identity = NULL;
311 int mdt_check_ucred(struct mdt_thread_info *info)
313 struct ptlrpc_request *req = mdt_info_req(info);
314 struct mdt_device *mdt = info->mti_mdt;
315 struct ptlrpc_user_desc *pud = req->rq_user_desc;
316 struct md_ucred *ucred = mdt_ucred(info);
317 struct md_identity *identity = NULL;
318 lnet_nid_t peernid = req->rq_peer.nid;
320 __u32 remote = exp_connect_rmtclient(info->mti_exp);
327 if ((ucred->mu_valid == UCRED_OLD) || (ucred->mu_valid == UCRED_NEW))
330 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
333 /* sanity check: if we use strong authentication, we expect the
334 * uid which client claimed is true */
336 if (req->rq_auth_mapped_uid == INVALID_UID) {
337 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
341 if (ptlrpc_user_desc_do_idmap(req, pud))
344 if (req->rq_auth_mapped_uid != pud->pud_uid) {
345 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
346 "while client claims %u:%u/%u:%u\n",
347 libcfs_nid2str(peernid), req->rq_auth_uid,
348 req->rq_auth_mapped_uid,
349 pud->pud_uid, pud->pud_gid,
350 pud->pud_fsuid, pud->pud_fsgid);
354 if (req->rq_auth_uid != pud->pud_uid) {
355 CDEBUG(D_SEC, "local client %s: auth uid %u "
356 "while client claims %u:%u/%u:%u\n",
357 libcfs_nid2str(peernid), req->rq_auth_uid,
358 pud->pud_uid, pud->pud_gid,
359 pud->pud_fsuid, pud->pud_fsgid);
364 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
366 CDEBUG(D_SEC, "remote client must run with identity_get "
373 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
374 if (IS_ERR(identity)) {
375 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
379 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
385 perm = mdt_identity_get_perm(identity, remote, peernid);
386 /* find out the setuid/setgid attempt */
387 setuid = (pud->pud_uid != pud->pud_fsuid);
388 setgid = (pud->pud_gid != pud->pud_fsgid ||
389 pud->pud_gid != identity->mi_gid);
391 /* check permission of setuid */
392 if (setuid && !(perm & CFS_SETUID_PERM)) {
393 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
394 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
395 GOTO(out, rc = -EACCES);
398 /* check permission of setgid */
399 if (setgid && !(perm & CFS_SETGID_PERM)) {
400 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
401 "from %s\n", pud->pud_uid, pud->pud_gid,
402 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
403 libcfs_nid2str(peernid));
404 GOTO(out, rc = -EACCES);
410 mdt_identity_put(mdt->mdt_identity_cache, identity);
414 static int old_init_ucred(struct mdt_thread_info *info,
415 struct mdt_body *body)
417 struct md_ucred *uc = mdt_ucred(info);
418 struct mdt_device *mdt = info->mti_mdt;
419 struct md_identity *identity = NULL;
423 uc->mu_valid = UCRED_INVALID;
424 uc->mu_o_uid = uc->mu_uid = body->uid;
425 uc->mu_o_gid = uc->mu_gid = body->gid;
426 uc->mu_o_fsuid = uc->mu_fsuid = body->fsuid;
427 uc->mu_o_fsgid = uc->mu_fsgid = body->fsgid;
428 uc->mu_suppgids[0] = body->suppgid;
429 uc->mu_suppgids[1] = -1;
431 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
432 identity = mdt_identity_get(mdt->mdt_identity_cache,
434 if (IS_ERR(identity)) {
435 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
438 CDEBUG(D_SEC, "Deny access without identity: "
439 "uid %u\n", uc->mu_fsuid);
444 uc->mu_identity = identity;
446 /* process root_squash here. */
447 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
449 /* remove fs privilege for non-root user. */
451 uc->mu_cap = body->capability & ~CFS_CAP_FS_MASK;
453 uc->mu_cap = body->capability;
454 uc->mu_valid = UCRED_OLD;
459 static int old_init_ucred_reint(struct mdt_thread_info *info)
461 struct md_ucred *uc = mdt_ucred(info);
462 struct mdt_device *mdt = info->mti_mdt;
463 struct md_identity *identity = NULL;
467 uc->mu_valid = UCRED_INVALID;
468 uc->mu_o_uid = uc->mu_o_fsuid = uc->mu_uid = uc->mu_fsuid;
469 uc->mu_o_gid = uc->mu_o_fsgid = uc->mu_gid = uc->mu_fsgid;
471 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
472 identity = mdt_identity_get(mdt->mdt_identity_cache,
474 if (IS_ERR(identity)) {
475 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
478 CDEBUG(D_SEC, "Deny access without identity: "
479 "uid %u\n", uc->mu_fsuid);
484 uc->mu_identity = identity;
486 /* process root_squash here. */
487 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
489 /* remove fs privilege for non-root user. */
491 uc->mu_cap &= ~CFS_CAP_FS_MASK;
492 uc->mu_valid = UCRED_OLD;
497 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
499 struct ptlrpc_request *req = mdt_info_req(info);
500 struct md_ucred *uc = mdt_ucred(info);
502 if ((uc->mu_valid == UCRED_OLD) || (uc->mu_valid == UCRED_NEW))
505 mdt_exit_ucred(info);
507 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
508 return old_init_ucred(info, body);
510 return new_init_ucred(info, BODY_INIT, body);
513 int mdt_init_ucred_reint(struct mdt_thread_info *info)
515 struct ptlrpc_request *req = mdt_info_req(info);
516 struct md_ucred *uc = mdt_ucred(info);
518 if ((uc->mu_valid == UCRED_OLD) || (uc->mu_valid == UCRED_NEW))
521 mdt_exit_ucred(info);
523 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
524 return old_init_ucred_reint(info);
526 return new_init_ucred(info, REC_INIT, NULL);
529 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
530 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm)
532 const struct lov_ost_data_v1 *lod;
536 count = le16_to_cpu(((struct lov_user_md*)lmm)->lmm_stripe_count);
538 CDEBUG(level, "objid "LPX64", magic 0x%08X, pattern %#X\n",
539 le64_to_cpu(lmm->lmm_object_id), le32_to_cpu(lmm->lmm_magic),
540 le32_to_cpu(lmm->lmm_pattern));
541 CDEBUG(level,"stripe_size=0x%x, stripe_count=0x%x\n",
542 le32_to_cpu(lmm->lmm_stripe_size), count);
543 if (count == LOV_ALL_STRIPES)
545 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
546 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++)
547 CDEBUG(level, "stripe %u idx %u subobj "LPX64"/"LPX64"\n",
548 i, le32_to_cpu(lod->l_ost_idx),
549 le64_to_cpu(lod->l_object_seq),
550 le64_to_cpu(lod->l_object_id));
553 void mdt_shrink_reply(struct mdt_thread_info *info)
555 struct req_capsule *pill = info->mti_pill;
556 struct mdt_body *body;
561 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
562 LASSERT(body != NULL);
564 if (body->valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE | OBD_MD_LINKNAME))
565 md_size = body->eadatasize;
569 acl_size = body->aclsize;
571 /* this replay - not send info to client */
572 if (info->mti_spec.no_create == 1) {
577 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d"
578 " MDSCAPA = %llx, OSSCAPA = %llx\n",
580 (unsigned long long)(body->valid & OBD_MD_FLMDSCAPA),
581 (unsigned long long)(body->valid & OBD_MD_FLOSSCAPA));
585 &RMF_ACL, or &RMF_LOGCOOKIES
586 (optional) &RMF_CAPA1,
587 (optional) &RMF_CAPA2,
588 (optional) something else
591 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
592 req_capsule_shrink(pill, &RMF_MDT_MD, md_size,
594 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
595 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
596 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
597 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
598 acl_size, RCL_SERVER);
600 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
601 !(body->valid & OBD_MD_FLMDSCAPA))
602 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
604 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
605 !(body->valid & OBD_MD_FLOSSCAPA))
606 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
609 * Some more field should be shrinked if needed.
610 * This should be done by those who added fields to reply message.
616 /* if object is dying, pack the lov/llog data,
617 * parameter info->mti_attr should be valid at this point! */
618 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
619 const struct md_attr *ma)
621 struct mdt_body *repbody;
622 const struct lu_attr *la = &ma->ma_attr;
626 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
627 LASSERT(repbody != NULL);
629 if (ma->ma_valid & MA_INODE)
630 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
632 if (ma->ma_valid & MA_LOV) {
635 if (mdt_object_exists(mo) < 0)
636 /* If it is a remote object, and we do not retrieve
637 * EA back unlink reg file*/
640 mode = lu_object_attr(&mo->mot_obj.mo_lu);
642 LASSERT(ma->ma_lmm_size);
643 mdt_dump_lmm(D_INFO, ma->ma_lmm);
644 repbody->eadatasize = ma->ma_lmm_size;
646 repbody->valid |= OBD_MD_FLEASIZE;
647 else if (S_ISDIR(mode))
648 repbody->valid |= OBD_MD_FLDIREA;
653 if (ma->ma_cookie_size && (ma->ma_valid & MA_COOKIE)) {
654 repbody->aclsize = ma->ma_cookie_size;
655 repbody->valid |= OBD_MD_FLCOOKIE;
658 if (info->mti_mdt->mdt_opts.mo_oss_capa &&
659 info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA &&
660 repbody->valid & OBD_MD_FLEASIZE) {
661 struct lustre_capa *capa;
663 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
665 capa->lc_opc = CAPA_OPC_OSS_DESTROY;
666 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0);
670 repbody->valid |= OBD_MD_FLOSSCAPA;
676 static inline unsigned int attr_unpack(__u64 sa_valid) {
677 unsigned int ia_valid = 0;
679 if (sa_valid & MDS_ATTR_MODE)
680 ia_valid |= ATTR_MODE;
681 if (sa_valid & MDS_ATTR_UID)
682 ia_valid |= ATTR_UID;
683 if (sa_valid & MDS_ATTR_GID)
684 ia_valid |= ATTR_GID;
685 if (sa_valid & MDS_ATTR_SIZE)
686 ia_valid |= ATTR_SIZE;
687 if (sa_valid & MDS_ATTR_ATIME)
688 ia_valid |= ATTR_ATIME;
689 if (sa_valid & MDS_ATTR_MTIME)
690 ia_valid |= ATTR_MTIME;
691 if (sa_valid & MDS_ATTR_CTIME)
692 ia_valid |= ATTR_CTIME;
693 if (sa_valid & MDS_ATTR_ATIME_SET)
694 ia_valid |= ATTR_ATIME_SET;
695 if (sa_valid & MDS_ATTR_MTIME_SET)
696 ia_valid |= ATTR_MTIME_SET;
697 if (sa_valid & MDS_ATTR_FORCE)
698 ia_valid |= ATTR_FORCE;
699 if (sa_valid & MDS_ATTR_ATTR_FLAG)
700 ia_valid |= ATTR_ATTR_FLAG;
701 if (sa_valid & MDS_ATTR_KILL_SUID)
702 ia_valid |= ATTR_KILL_SUID;
703 if (sa_valid & MDS_ATTR_KILL_SGID)
704 ia_valid |= ATTR_KILL_SGID;
705 if (sa_valid & MDS_ATTR_CTIME_SET)
706 ia_valid |= ATTR_CTIME_SET;
707 if (sa_valid & MDS_ATTR_FROM_OPEN)
708 ia_valid |= ATTR_FROM_OPEN;
709 if (sa_valid & MDS_ATTR_BLOCKS)
710 ia_valid |= ATTR_BLOCKS;
711 if (sa_valid & MDS_OPEN_OWNEROVERRIDE)
712 ia_valid |= MDS_OPEN_OWNEROVERRIDE;
716 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
730 if (in & ATTR_BLOCKS)
733 if (in & ATTR_FROM_OPEN)
734 rr->rr_flags |= MRF_OPEN_TRUNC;
736 if (in & ATTR_ATIME_SET)
739 if (in & ATTR_CTIME_SET)
742 if (in & ATTR_MTIME_SET)
745 if (in & ATTR_ATTR_FLAG)
748 if (in & ATTR_KILL_SUID)
751 if (in & ATTR_KILL_SGID)
754 if (in & MDS_OPEN_OWNEROVERRIDE)
755 ma->ma_attr_flags |= MDS_OPEN_OWNEROVERRIDE;
758 ma->ma_attr_flags |= MDS_PERM_BYPASS;
760 /*XXX need ATTR_RAW?*/
761 in &= ~(ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_BLOCKS|
762 ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_FROM_OPEN|
763 ATTR_ATIME_SET|ATTR_CTIME_SET|ATTR_MTIME_SET|
764 ATTR_ATTR_FLAG|ATTR_RAW|MDS_OPEN_OWNEROVERRIDE|
765 ATTR_FORCE|ATTR_KILL_SUID|ATTR_KILL_SGID);
767 CERROR("Unknown attr bits: "LPX64"\n", in);
772 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
774 struct md_ucred *uc = mdt_ucred(info);
775 struct md_attr *ma = &info->mti_attr;
776 struct lu_attr *la = &ma->ma_attr;
777 struct req_capsule *pill = info->mti_pill;
778 struct mdt_reint_record *rr = &info->mti_rr;
779 struct mdt_rec_setattr *rec;
782 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
783 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
787 uc->mu_fsuid = rec->sa_fsuid;
788 uc->mu_fsgid = rec->sa_fsgid;
789 uc->mu_cap = rec->sa_cap;
790 uc->mu_suppgids[0] = rec->sa_suppgid;
791 uc->mu_suppgids[1] = -1;
793 rr->rr_fid1 = &rec->sa_fid;
794 la->la_valid = mdt_attr_valid_xlate(attr_unpack(rec->sa_valid), rr, ma);
795 la->la_mode = rec->sa_mode;
796 la->la_flags = rec->sa_attr_flags;
797 la->la_uid = rec->sa_uid;
798 la->la_gid = rec->sa_gid;
799 la->la_size = rec->sa_size;
800 la->la_blocks = rec->sa_blocks;
801 la->la_ctime = rec->sa_ctime;
802 la->la_atime = rec->sa_atime;
803 la->la_mtime = rec->sa_mtime;
804 ma->ma_valid = MA_INODE;
806 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
807 mdt_set_capainfo(info, 0, rr->rr_fid1,
808 req_capsule_client_get(pill, &RMF_CAPA1));
813 static int mdt_ioepoch_unpack(struct mdt_thread_info *info)
815 struct req_capsule *pill = info->mti_pill;
818 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
820 req_capsule_client_get(pill, &RMF_MDT_EPOCH);
822 info->mti_ioepoch = NULL;
823 RETURN(info->mti_ioepoch == NULL ? -EFAULT : 0);
826 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
827 struct req_capsule *pill = info->mti_pill;
829 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
830 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
831 if (info->mti_dlm_req == NULL)
838 static int mdt_setattr_unpack(struct mdt_thread_info *info)
840 struct md_attr *ma = &info->mti_attr;
841 struct req_capsule *pill = info->mti_pill;
845 rc = mdt_setattr_unpack_rec(info);
849 /* Epoch may be absent */
850 mdt_ioepoch_unpack(info);
852 ma->ma_lmm_size = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
853 if (ma->ma_lmm_size) {
854 ma->ma_lmm = req_capsule_client_get(pill, &RMF_EADATA);
855 ma->ma_valid |= MA_LOV;
858 ma->ma_cookie_size = req_capsule_get_size(pill, &RMF_LOGCOOKIES,
860 if (ma->ma_cookie_size) {
861 ma->ma_cookie = req_capsule_client_get(pill, &RMF_LOGCOOKIES);
862 ma->ma_valid |= MA_COOKIE;
865 rc = mdt_dlmreq_unpack(info);
869 int mdt_close_unpack(struct mdt_thread_info *info)
874 rc = mdt_ioepoch_unpack(info);
878 RETURN(mdt_setattr_unpack_rec(info));
881 static int mdt_create_unpack(struct mdt_thread_info *info)
883 struct md_ucred *uc = mdt_ucred(info);
884 struct mdt_rec_create *rec;
885 struct lu_attr *attr = &info->mti_attr.ma_attr;
886 struct mdt_reint_record *rr = &info->mti_rr;
887 struct req_capsule *pill = info->mti_pill;
888 struct md_op_spec *sp = &info->mti_spec;
892 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
893 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
897 uc->mu_fsuid = rec->cr_fsuid;
898 uc->mu_fsgid = rec->cr_fsgid;
899 uc->mu_cap = rec->cr_cap;
900 uc->mu_suppgids[0] = rec->cr_suppgid1;
901 uc->mu_suppgids[1] = -1;
903 rr->rr_fid1 = &rec->cr_fid1;
904 rr->rr_fid2 = &rec->cr_fid2;
905 attr->la_mode = rec->cr_mode;
906 attr->la_rdev = rec->cr_rdev;
907 attr->la_uid = rec->cr_fsuid;
908 attr->la_gid = rec->cr_fsgid;
909 attr->la_ctime = rec->cr_time;
910 attr->la_mtime = rec->cr_time;
911 attr->la_atime = rec->cr_time;
912 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
913 LA_CTIME | LA_MTIME | LA_ATIME;
914 memset(&sp->u, 0, sizeof(sp->u));
915 sp->sp_cr_flags = get_mrc_cr_flags(rec);
916 sp->sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
917 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
919 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
920 mdt_set_capainfo(info, 0, rr->rr_fid1,
921 req_capsule_client_get(pill, &RMF_CAPA1));
922 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
924 if (!info->mti_cross_ref) {
925 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
926 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME,
928 LASSERT(rr->rr_name && rr->rr_namelen > 0);
934 #ifdef CONFIG_FS_POSIX_ACL
935 if (sp->sp_cr_flags & MDS_CREATE_RMT_ACL) {
936 if (S_ISDIR(attr->la_mode))
937 sp->u.sp_pfid = rr->rr_fid1;
938 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
939 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
941 sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA);
942 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
944 sp->u.sp_ea.fid = rr->rr_fid1;
948 if (S_ISDIR(attr->la_mode)) {
949 /* pass parent fid for cross-ref cases */
950 sp->u.sp_pfid = rr->rr_fid1;
951 if (sp->sp_cr_flags & MDS_CREATE_SLAVE_OBJ) {
952 /* create salve object req, need
953 * unpack split ea here
955 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SLAVE);
956 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
958 sp->u.sp_ea.eadata = req_capsule_client_get(pill,
960 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill,
963 sp->u.sp_ea.fid = rr->rr_fid1;
966 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
967 } else if (S_ISLNK(attr->la_mode)) {
968 const char *tgt = NULL;
970 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
971 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
972 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
973 sp->u.sp_symname = tgt;
978 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
980 rc = mdt_dlmreq_unpack(info);
984 static int mdt_link_unpack(struct mdt_thread_info *info)
986 struct md_ucred *uc = mdt_ucred(info);
987 struct mdt_rec_link *rec;
988 struct lu_attr *attr = &info->mti_attr.ma_attr;
989 struct mdt_reint_record *rr = &info->mti_rr;
990 struct req_capsule *pill = info->mti_pill;
994 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
995 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
999 uc->mu_fsuid = rec->lk_fsuid;
1000 uc->mu_fsgid = rec->lk_fsgid;
1001 uc->mu_cap = rec->lk_cap;
1002 uc->mu_suppgids[0] = rec->lk_suppgid1;
1003 uc->mu_suppgids[1] = rec->lk_suppgid2;
1005 attr->la_uid = rec->lk_fsuid;
1006 attr->la_gid = rec->lk_fsgid;
1007 rr->rr_fid1 = &rec->lk_fid1;
1008 rr->rr_fid2 = &rec->lk_fid2;
1009 attr->la_ctime = rec->lk_time;
1010 attr->la_mtime = rec->lk_time;
1011 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1013 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1014 mdt_set_capainfo(info, 0, rr->rr_fid1,
1015 req_capsule_client_get(pill, &RMF_CAPA1));
1016 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1017 mdt_set_capainfo(info, 1, rr->rr_fid2,
1018 req_capsule_client_get(pill, &RMF_CAPA2));
1020 info->mti_spec.sp_ck_split = !!(rec->lk_bias & MDS_CHECK_SPLIT);
1021 info->mti_cross_ref = !!(rec->lk_bias & MDS_CROSS_REF);
1022 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1023 if (rr->rr_name == NULL)
1025 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1026 if (!info->mti_cross_ref)
1027 LASSERT(rr->rr_namelen > 0);
1029 rc = mdt_dlmreq_unpack(info);
1033 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1035 struct md_ucred *uc = mdt_ucred(info);
1036 struct mdt_rec_unlink *rec;
1037 struct md_attr *ma = &info->mti_attr;
1038 struct lu_attr *attr = &info->mti_attr.ma_attr;
1039 struct mdt_reint_record *rr = &info->mti_rr;
1040 struct req_capsule *pill = info->mti_pill;
1044 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1045 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1049 uc->mu_fsuid = rec->ul_fsuid;
1050 uc->mu_fsgid = rec->ul_fsgid;
1051 uc->mu_cap = rec->ul_cap;
1052 uc->mu_suppgids[0] = rec->ul_suppgid1;
1053 uc->mu_suppgids[1] = -1;
1055 attr->la_uid = rec->ul_fsuid;
1056 attr->la_gid = rec->ul_fsgid;
1057 rr->rr_fid1 = &rec->ul_fid1;
1058 rr->rr_fid2 = &rec->ul_fid2;
1059 attr->la_ctime = rec->ul_time;
1060 attr->la_mtime = rec->ul_time;
1061 attr->la_mode = rec->ul_mode;
1062 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1064 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1065 mdt_set_capainfo(info, 0, rr->rr_fid1,
1066 req_capsule_client_get(pill, &RMF_CAPA1));
1068 info->mti_cross_ref = !!(rec->ul_bias & MDS_CROSS_REF);
1069 if (!info->mti_cross_ref) {
1070 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1071 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1072 if (rr->rr_name == NULL || rr->rr_namelen == 0)
1078 info->mti_spec.sp_ck_split = !!(rec->ul_bias & MDS_CHECK_SPLIT);
1079 if (rec->ul_bias & MDS_VTX_BYPASS)
1080 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1082 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1084 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1086 rc = mdt_dlmreq_unpack(info);
1090 static int mdt_rename_unpack(struct mdt_thread_info *info)
1092 struct md_ucred *uc = mdt_ucred(info);
1093 struct mdt_rec_rename *rec;
1094 struct md_attr *ma = &info->mti_attr;
1095 struct lu_attr *attr = &info->mti_attr.ma_attr;
1096 struct mdt_reint_record *rr = &info->mti_rr;
1097 struct req_capsule *pill = info->mti_pill;
1101 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1102 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1106 uc->mu_fsuid = rec->rn_fsuid;
1107 uc->mu_fsgid = rec->rn_fsgid;
1108 uc->mu_cap = rec->rn_cap;
1109 uc->mu_suppgids[0] = rec->rn_suppgid1;
1110 uc->mu_suppgids[1] = rec->rn_suppgid2;
1112 attr->la_uid = rec->rn_fsuid;
1113 attr->la_gid = rec->rn_fsgid;
1114 rr->rr_fid1 = &rec->rn_fid1;
1115 rr->rr_fid2 = &rec->rn_fid2;
1116 attr->la_ctime = rec->rn_time;
1117 attr->la_mtime = rec->rn_time;
1118 /* rename_tgt contains the mode already */
1119 attr->la_mode = rec->rn_mode;
1120 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1122 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1123 mdt_set_capainfo(info, 0, rr->rr_fid1,
1124 req_capsule_client_get(pill, &RMF_CAPA1));
1125 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1126 mdt_set_capainfo(info, 1, rr->rr_fid2,
1127 req_capsule_client_get(pill, &RMF_CAPA2));
1129 info->mti_spec.sp_ck_split = !!(rec->rn_bias & MDS_CHECK_SPLIT);
1130 info->mti_cross_ref = !!(rec->rn_bias & MDS_CROSS_REF);
1131 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1132 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1133 if (rr->rr_name == NULL || rr->rr_tgt == NULL)
1135 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1136 rr->rr_tgtlen = req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT) - 1;
1137 if (!info->mti_cross_ref)
1138 LASSERT(rr->rr_namelen > 0 && rr->rr_tgtlen > 0);
1139 if (rec->rn_bias & MDS_VTX_BYPASS)
1140 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1142 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1144 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1146 rc = mdt_dlmreq_unpack(info);
1150 static int mdt_open_unpack(struct mdt_thread_info *info)
1152 struct md_ucred *uc = mdt_ucred(info);
1153 struct mdt_rec_create *rec;
1154 struct lu_attr *attr = &info->mti_attr.ma_attr;
1155 struct req_capsule *pill = info->mti_pill;
1156 struct mdt_reint_record *rr = &info->mti_rr;
1157 struct ptlrpc_request *req = mdt_info_req(info);
1158 struct md_op_spec *sp = &info->mti_spec;
1161 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1162 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1166 uc->mu_fsuid = rec->cr_fsuid;
1167 uc->mu_fsgid = rec->cr_fsgid;
1168 uc->mu_cap = rec->cr_cap;
1169 uc->mu_suppgids[0] = rec->cr_suppgid1;
1170 uc->mu_suppgids[1] = rec->cr_suppgid2;
1172 rr->rr_fid1 = &rec->cr_fid1;
1173 rr->rr_fid2 = &rec->cr_fid2;
1174 rr->rr_handle = &rec->cr_old_handle;
1175 attr->la_mode = rec->cr_mode;
1176 attr->la_rdev = rec->cr_rdev;
1177 attr->la_uid = rec->cr_fsuid;
1178 attr->la_gid = rec->cr_fsgid;
1179 attr->la_ctime = rec->cr_time;
1180 attr->la_mtime = rec->cr_time;
1181 attr->la_atime = rec->cr_time;
1182 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1183 LA_CTIME | LA_MTIME | LA_ATIME;
1184 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1185 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1186 /* Do not trigger ASSERTION if client miss to set such flags. */
1187 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1189 info->mti_replayepoch = rec->cr_ioepoch;
1191 info->mti_spec.sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
1192 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1194 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1195 mdt_set_capainfo(info, 0, rr->rr_fid1,
1196 req_capsule_client_get(pill, &RMF_CAPA1));
1197 if (req_is_replay(req) &&
1198 req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) {
1200 mdt_set_capainfo(info, 1, rr->rr_fid2,
1201 req_capsule_client_get(pill, &RMF_CAPA2));
1204 * FIXME: capa in replay open request might have expired,
1205 * bypass capa check. Security hole?
1207 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1208 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1212 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1213 if (rr->rr_name == NULL)
1215 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1217 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1219 if (sp->u.sp_ea.eadatalen) {
1220 sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA);
1221 sp->no_create = !!req_is_replay(req);
1227 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1229 struct mdt_reint_record *rr = &info->mti_rr;
1230 struct md_ucred *uc = mdt_ucred(info);
1231 struct lu_attr *attr = &info->mti_attr.ma_attr;
1232 struct req_capsule *pill = info->mti_pill;
1233 struct mdt_rec_setxattr *rec;
1237 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1238 sizeof(struct mdt_rec_reint));
1240 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1244 uc->mu_fsuid = rec->sx_fsuid;
1245 uc->mu_fsgid = rec->sx_fsgid;
1246 uc->mu_cap = rec->sx_cap;
1247 uc->mu_suppgids[0] = rec->sx_suppgid1;
1248 uc->mu_suppgids[1] = -1;
1250 rr->rr_opcode = rec->sx_opcode;
1251 rr->rr_fid1 = &rec->sx_fid;
1252 attr->la_valid = rec->sx_valid;
1253 attr->la_ctime = rec->sx_time;
1254 attr->la_size = rec->sx_size;
1255 attr->la_flags = rec->sx_flags;
1257 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1258 mdt_set_capainfo(info, 0, rr->rr_fid1,
1259 req_capsule_client_get(pill, &RMF_CAPA1));
1261 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1263 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1264 if (rr->rr_name == NULL)
1266 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1267 LASSERT(rr->rr_namelen > 0);
1269 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
1270 if (rr->rr_eadatalen > 0) {
1271 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1272 if (rr->rr_eadata == NULL)
1280 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1282 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1283 [REINT_SETATTR] = mdt_setattr_unpack,
1284 [REINT_CREATE] = mdt_create_unpack,
1285 [REINT_LINK] = mdt_link_unpack,
1286 [REINT_UNLINK] = mdt_unlink_unpack,
1287 [REINT_RENAME] = mdt_rename_unpack,
1288 [REINT_OPEN] = mdt_open_unpack,
1289 [REINT_SETXATTR] = mdt_setxattr_unpack
1292 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1297 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1298 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1299 info->mti_rr.rr_opcode = op;
1300 rc = mdt_reint_unpackers[op](info);
1302 CERROR("Unexpected opcode %d\n", op);