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.
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"
56 #include <lnet/lib-lnet.h>
59 typedef enum ucred_init_type {
65 void mdt_exit_ucred(struct mdt_thread_info *info)
67 struct md_ucred *uc = mdt_ucred(info);
68 struct mdt_device *mdt = info->mti_mdt;
70 if (uc->mu_valid != UCRED_INIT) {
71 uc->mu_suppgids[0] = uc->mu_suppgids[1] = -1;
73 cfs_put_group_info(uc->mu_ginfo);
76 if (uc->mu_identity) {
77 mdt_identity_put(mdt->mdt_identity_cache,
79 uc->mu_identity = NULL;
81 uc->mu_valid = UCRED_INIT;
85 static int match_nosquash_list(cfs_rw_semaphore_t *sem,
92 rc = cfs_match_nid(peernid, nidlist);
97 /* root_squash for inter-MDS operations */
98 static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid)
100 struct md_ucred *ucred = mdt_ucred(info);
103 if (!info->mti_mdt->mdt_squash_uid || ucred->mu_fsuid)
106 if (match_nosquash_list(&info->mti_mdt->mdt_squash_sem,
107 &info->mti_mdt->mdt_nosquash_nids,
109 CDEBUG(D_OTHER, "%s is in nosquash_nids list\n",
110 libcfs_nid2str(peernid));
114 CDEBUG(D_OTHER, "squash req from %s, (%d:%d/%x)=>(%d:%d/%x)\n",
115 libcfs_nid2str(peernid),
116 ucred->mu_fsuid, ucred->mu_fsgid, ucred->mu_cap,
117 info->mti_mdt->mdt_squash_uid, info->mti_mdt->mdt_squash_gid,
120 ucred->mu_fsuid = info->mti_mdt->mdt_squash_uid;
121 ucred->mu_fsgid = info->mti_mdt->mdt_squash_gid;
123 ucred->mu_suppgids[0] = -1;
124 ucred->mu_suppgids[1] = -1;
129 static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type,
132 struct ptlrpc_request *req = mdt_info_req(info);
133 struct mdt_device *mdt = info->mti_mdt;
134 struct ptlrpc_user_desc *pud = req->rq_user_desc;
135 struct md_ucred *ucred = mdt_ucred(info);
136 lnet_nid_t peernid = req->rq_peer.nid;
138 __u32 remote = exp_connect_rmtclient(info->mti_exp);
145 LASSERT(req->rq_auth_gss);
146 LASSERT(!req->rq_auth_usr_mdt);
147 LASSERT(req->rq_user_desc);
149 ucred->mu_valid = UCRED_INVALID;
151 ucred->mu_o_uid = pud->pud_uid;
152 ucred->mu_o_gid = pud->pud_gid;
153 ucred->mu_o_fsuid = pud->pud_fsuid;
154 ucred->mu_o_fsgid = pud->pud_fsgid;
156 if (type == BODY_INIT) {
157 struct mdt_body *body = (struct mdt_body *)buf;
159 ucred->mu_suppgids[0] = body->suppgid;
160 ucred->mu_suppgids[1] = -1;
163 /* sanity check: we expect the uid which client claimed is true */
165 if (req->rq_auth_mapped_uid == INVALID_UID) {
166 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
170 if (ptlrpc_user_desc_do_idmap(req, pud))
173 if (req->rq_auth_mapped_uid != pud->pud_uid) {
174 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
175 "while client claims %u:%u/%u:%u\n",
176 libcfs_nid2str(peernid), req->rq_auth_uid,
177 req->rq_auth_mapped_uid,
178 pud->pud_uid, pud->pud_gid,
179 pud->pud_fsuid, pud->pud_fsgid);
183 if (req->rq_auth_uid != pud->pud_uid) {
184 CDEBUG(D_SEC, "local client %s: auth uid %u "
185 "while client claims %u:%u/%u:%u\n",
186 libcfs_nid2str(peernid), req->rq_auth_uid,
187 pud->pud_uid, pud->pud_gid,
188 pud->pud_fsuid, pud->pud_fsgid);
193 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
195 CDEBUG(D_SEC, "remote client must run with identity_get "
199 ucred->mu_identity = NULL;
200 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
204 struct md_identity *identity;
206 identity = mdt_identity_get(mdt->mdt_identity_cache,
208 if (IS_ERR(identity)) {
209 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
211 ucred->mu_identity = NULL;
212 perm = CFS_SETUID_PERM | CFS_SETGID_PERM |
215 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
220 ucred->mu_identity = identity;
221 perm = mdt_identity_get_perm(ucred->mu_identity,
226 /* find out the setuid/setgid attempt */
227 setuid = (pud->pud_uid != pud->pud_fsuid);
228 setgid = ((pud->pud_gid != pud->pud_fsgid) ||
229 (ucred->mu_identity &&
230 (pud->pud_gid != ucred->mu_identity->mi_gid)));
232 /* check permission of setuid */
233 if (setuid && !(perm & CFS_SETUID_PERM)) {
234 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
235 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
236 GOTO(out, rc = -EACCES);
239 /* check permission of setgid */
240 if (setgid && !(perm & CFS_SETGID_PERM)) {
241 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
242 "from %s\n", pud->pud_uid, pud->pud_gid,
243 pud->pud_fsuid, pud->pud_fsgid,
244 ucred->mu_identity->mi_gid, libcfs_nid2str(peernid));
245 GOTO(out, rc = -EACCES);
249 * NB: remote client not allowed to setgroups anyway.
251 if (!remote && perm & CFS_SETGRP_PERM) {
252 if (pud->pud_ngroups) {
253 /* setgroups for local client */
254 ucred->mu_ginfo = cfs_groups_alloc(pud->pud_ngroups);
255 if (!ucred->mu_ginfo) {
256 CERROR("failed to alloc %d groups\n",
258 GOTO(out, rc = -ENOMEM);
261 lustre_groups_from_list(ucred->mu_ginfo,
263 lustre_groups_sort(ucred->mu_ginfo);
265 ucred->mu_ginfo = NULL;
268 ucred->mu_suppgids[0] = -1;
269 ucred->mu_suppgids[1] = -1;
270 ucred->mu_ginfo = NULL;
273 ucred->mu_uid = pud->pud_uid;
274 ucred->mu_gid = pud->pud_gid;
275 ucred->mu_fsuid = pud->pud_fsuid;
276 ucred->mu_fsgid = pud->pud_fsgid;
278 /* process root_squash here. */
279 mdt_root_squash(info, peernid);
281 /* remove fs privilege for non-root user. */
283 ucred->mu_cap = pud->pud_cap & ~CFS_CAP_FS_MASK;
285 ucred->mu_cap = pud->pud_cap;
286 if (remote && !(perm & CFS_RMTOWN_PERM))
287 ucred->mu_cap &= ~(CFS_CAP_SYS_RESOURCE_MASK |
289 ucred->mu_valid = UCRED_NEW;
295 if (ucred->mu_ginfo) {
296 cfs_put_group_info(ucred->mu_ginfo);
297 ucred->mu_ginfo = NULL;
299 if (ucred->mu_identity) {
300 mdt_identity_put(mdt->mdt_identity_cache,
302 ucred->mu_identity = NULL;
309 int mdt_check_ucred(struct mdt_thread_info *info)
311 struct ptlrpc_request *req = mdt_info_req(info);
312 struct mdt_device *mdt = info->mti_mdt;
313 struct ptlrpc_user_desc *pud = req->rq_user_desc;
314 struct md_ucred *ucred = mdt_ucred(info);
315 struct md_identity *identity = NULL;
316 lnet_nid_t peernid = req->rq_peer.nid;
318 __u32 remote = exp_connect_rmtclient(info->mti_exp);
325 if ((ucred->mu_valid == UCRED_OLD) || (ucred->mu_valid == UCRED_NEW))
328 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
331 /* sanity check: if we use strong authentication, we expect the
332 * uid which client claimed is true */
334 if (req->rq_auth_mapped_uid == INVALID_UID) {
335 CDEBUG(D_SEC, "remote user not mapped, deny access!\n");
339 if (ptlrpc_user_desc_do_idmap(req, pud))
342 if (req->rq_auth_mapped_uid != pud->pud_uid) {
343 CDEBUG(D_SEC, "remote client %s: auth/mapped uid %u/%u "
344 "while client claims %u:%u/%u:%u\n",
345 libcfs_nid2str(peernid), req->rq_auth_uid,
346 req->rq_auth_mapped_uid,
347 pud->pud_uid, pud->pud_gid,
348 pud->pud_fsuid, pud->pud_fsgid);
352 if (req->rq_auth_uid != pud->pud_uid) {
353 CDEBUG(D_SEC, "local client %s: auth uid %u "
354 "while client claims %u:%u/%u:%u\n",
355 libcfs_nid2str(peernid), req->rq_auth_uid,
356 pud->pud_uid, pud->pud_gid,
357 pud->pud_fsuid, pud->pud_fsgid);
362 if (is_identity_get_disabled(mdt->mdt_identity_cache)) {
364 CDEBUG(D_SEC, "remote client must run with identity_get "
371 identity = mdt_identity_get(mdt->mdt_identity_cache, pud->pud_uid);
372 if (IS_ERR(identity)) {
373 if (unlikely(PTR_ERR(identity) == -EREMCHG &&
377 CDEBUG(D_SEC, "Deny access without identity: uid %u\n",
383 perm = mdt_identity_get_perm(identity, remote, peernid);
384 /* find out the setuid/setgid attempt */
385 setuid = (pud->pud_uid != pud->pud_fsuid);
386 setgid = (pud->pud_gid != pud->pud_fsgid ||
387 pud->pud_gid != identity->mi_gid);
389 /* check permission of setuid */
390 if (setuid && !(perm & CFS_SETUID_PERM)) {
391 CDEBUG(D_SEC, "mdt blocked setuid attempt (%u -> %u) from %s\n",
392 pud->pud_uid, pud->pud_fsuid, libcfs_nid2str(peernid));
393 GOTO(out, rc = -EACCES);
396 /* check permission of setgid */
397 if (setgid && !(perm & CFS_SETGID_PERM)) {
398 CDEBUG(D_SEC, "mdt blocked setgid attempt (%u:%u/%u:%u -> %u) "
399 "from %s\n", pud->pud_uid, pud->pud_gid,
400 pud->pud_fsuid, pud->pud_fsgid, identity->mi_gid,
401 libcfs_nid2str(peernid));
402 GOTO(out, rc = -EACCES);
408 mdt_identity_put(mdt->mdt_identity_cache, identity);
412 static int old_init_ucred(struct mdt_thread_info *info,
413 struct mdt_body *body)
415 struct md_ucred *uc = mdt_ucred(info);
416 struct mdt_device *mdt = info->mti_mdt;
417 struct md_identity *identity = NULL;
421 uc->mu_valid = UCRED_INVALID;
422 uc->mu_o_uid = uc->mu_uid = body->uid;
423 uc->mu_o_gid = uc->mu_gid = body->gid;
424 uc->mu_o_fsuid = uc->mu_fsuid = body->fsuid;
425 uc->mu_o_fsgid = uc->mu_fsgid = body->fsgid;
426 uc->mu_suppgids[0] = body->suppgid;
427 uc->mu_suppgids[1] = -1;
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 /* process root_squash here. */
445 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
447 /* remove fs privilege for non-root user. */
449 uc->mu_cap = body->capability & ~CFS_CAP_FS_MASK;
451 uc->mu_cap = body->capability;
452 uc->mu_valid = UCRED_OLD;
457 static int old_init_ucred_reint(struct mdt_thread_info *info)
459 struct md_ucred *uc = mdt_ucred(info);
460 struct mdt_device *mdt = info->mti_mdt;
461 struct md_identity *identity = NULL;
465 uc->mu_valid = UCRED_INVALID;
466 uc->mu_o_uid = uc->mu_o_fsuid = uc->mu_uid = uc->mu_fsuid;
467 uc->mu_o_gid = uc->mu_o_fsgid = uc->mu_gid = uc->mu_fsgid;
469 if (!is_identity_get_disabled(mdt->mdt_identity_cache)) {
470 identity = mdt_identity_get(mdt->mdt_identity_cache,
472 if (IS_ERR(identity)) {
473 if (unlikely(PTR_ERR(identity) == -EREMCHG)) {
476 CDEBUG(D_SEC, "Deny access without identity: "
477 "uid %u\n", uc->mu_fsuid);
482 uc->mu_identity = identity;
484 /* process root_squash here. */
485 mdt_root_squash(info, mdt_info_req(info)->rq_peer.nid);
487 /* remove fs privilege for non-root user. */
489 uc->mu_cap &= ~CFS_CAP_FS_MASK;
490 uc->mu_valid = UCRED_OLD;
495 int mdt_init_ucred(struct mdt_thread_info *info, struct mdt_body *body)
497 struct ptlrpc_request *req = mdt_info_req(info);
498 struct md_ucred *uc = mdt_ucred(info);
500 if ((uc->mu_valid == UCRED_OLD) || (uc->mu_valid == UCRED_NEW))
503 mdt_exit_ucred(info);
505 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
506 return old_init_ucred(info, body);
508 return new_init_ucred(info, BODY_INIT, body);
511 int mdt_init_ucred_reint(struct mdt_thread_info *info)
513 struct ptlrpc_request *req = mdt_info_req(info);
514 struct md_ucred *uc = mdt_ucred(info);
516 if ((uc->mu_valid == UCRED_OLD) || (uc->mu_valid == UCRED_NEW))
519 mdt_exit_ucred(info);
521 if (!req->rq_auth_gss || req->rq_auth_usr_mdt || !req->rq_user_desc)
522 return old_init_ucred_reint(info);
524 return new_init_ucred(info, REC_INIT, NULL);
527 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
528 void mdt_dump_lmm(int level, const struct lov_mds_md *lmm)
530 const struct lov_ost_data_v1 *lod;
534 count = le16_to_cpu(((struct lov_user_md*)lmm)->lmm_stripe_count);
536 CDEBUG(level, "objid "LPX64", magic 0x%08X, pattern %#X\n",
537 le64_to_cpu(lmm->lmm_object_id), le32_to_cpu(lmm->lmm_magic),
538 le32_to_cpu(lmm->lmm_pattern));
539 CDEBUG(level,"stripe_size=0x%x, stripe_count=0x%x\n",
540 le32_to_cpu(lmm->lmm_stripe_size), count);
541 if (count == LOV_ALL_STRIPES)
543 LASSERT(count <= LOV_MAX_STRIPE_COUNT);
544 for (i = 0, lod = lmm->lmm_objects; i < count; i++, lod++)
545 CDEBUG(level, "stripe %u idx %u subobj "LPX64"/"LPX64"\n",
546 i, le32_to_cpu(lod->l_ost_idx),
547 le64_to_cpu(lod->l_object_seq),
548 le64_to_cpu(lod->l_object_id));
551 void mdt_shrink_reply(struct mdt_thread_info *info)
553 struct req_capsule *pill = info->mti_pill;
554 struct mdt_body *body;
559 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
560 LASSERT(body != NULL);
562 if (body->valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE | OBD_MD_LINKNAME))
563 md_size = body->eadatasize;
567 acl_size = body->aclsize;
569 /* this replay - not send info to client */
570 if (info->mti_spec.no_create == 1) {
575 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d"
576 " MDSCAPA = %llx, OSSCAPA = %llx\n",
578 (unsigned long long)(body->valid & OBD_MD_FLMDSCAPA),
579 (unsigned long long)(body->valid & OBD_MD_FLOSSCAPA));
583 &RMF_ACL, or &RMF_LOGCOOKIES
584 (optional) &RMF_CAPA1,
585 (optional) &RMF_CAPA2,
586 (optional) something else
589 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
590 req_capsule_shrink(pill, &RMF_MDT_MD, md_size,
592 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
593 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
594 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
595 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
596 acl_size, RCL_SERVER);
598 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
599 !(body->valid & OBD_MD_FLMDSCAPA))
600 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
602 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
603 !(body->valid & OBD_MD_FLOSSCAPA))
604 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
607 * Some more field should be shrinked if needed.
608 * This should be done by those who added fields to reply message.
614 /* if object is dying, pack the lov/llog data,
615 * parameter info->mti_attr should be valid at this point! */
616 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
617 const struct md_attr *ma)
619 struct mdt_body *repbody;
620 const struct lu_attr *la = &ma->ma_attr;
624 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
625 LASSERT(repbody != NULL);
627 if (ma->ma_valid & MA_INODE)
628 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
630 if (ma->ma_valid & MA_LOV) {
633 if (mdt_object_exists(mo) < 0)
634 /* If it is a remote object, and we do not retrieve
635 * EA back unlink reg file*/
638 mode = lu_object_attr(&mo->mot_obj.mo_lu);
640 LASSERT(ma->ma_lmm_size);
641 mdt_dump_lmm(D_INFO, ma->ma_lmm);
642 repbody->eadatasize = ma->ma_lmm_size;
644 repbody->valid |= OBD_MD_FLEASIZE;
645 else if (S_ISDIR(mode))
646 repbody->valid |= OBD_MD_FLDIREA;
651 if (ma->ma_cookie_size && (ma->ma_valid & MA_COOKIE)) {
652 repbody->aclsize = ma->ma_cookie_size;
653 repbody->valid |= OBD_MD_FLCOOKIE;
656 if (info->mti_mdt->mdt_opts.mo_oss_capa &&
657 info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA &&
658 repbody->valid & OBD_MD_FLEASIZE) {
659 struct lustre_capa *capa;
661 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
663 capa->lc_opc = CAPA_OPC_OSS_DESTROY;
664 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0);
668 repbody->valid |= OBD_MD_FLOSSCAPA;
674 static inline unsigned int attr_unpack(__u64 sa_valid) {
675 unsigned int ia_valid = 0;
677 if (sa_valid & MDS_ATTR_MODE)
678 ia_valid |= ATTR_MODE;
679 if (sa_valid & MDS_ATTR_UID)
680 ia_valid |= ATTR_UID;
681 if (sa_valid & MDS_ATTR_GID)
682 ia_valid |= ATTR_GID;
683 if (sa_valid & MDS_ATTR_SIZE)
684 ia_valid |= ATTR_SIZE;
685 if (sa_valid & MDS_ATTR_ATIME)
686 ia_valid |= ATTR_ATIME;
687 if (sa_valid & MDS_ATTR_MTIME)
688 ia_valid |= ATTR_MTIME;
689 if (sa_valid & MDS_ATTR_CTIME)
690 ia_valid |= ATTR_CTIME;
691 if (sa_valid & MDS_ATTR_ATIME_SET)
692 ia_valid |= ATTR_ATIME_SET;
693 if (sa_valid & MDS_ATTR_MTIME_SET)
694 ia_valid |= ATTR_MTIME_SET;
695 if (sa_valid & MDS_ATTR_FORCE)
696 ia_valid |= ATTR_FORCE;
697 if (sa_valid & MDS_ATTR_ATTR_FLAG)
698 ia_valid |= ATTR_ATTR_FLAG;
699 if (sa_valid & MDS_ATTR_KILL_SUID)
700 ia_valid |= ATTR_KILL_SUID;
701 if (sa_valid & MDS_ATTR_KILL_SGID)
702 ia_valid |= ATTR_KILL_SGID;
703 if (sa_valid & MDS_ATTR_CTIME_SET)
704 ia_valid |= ATTR_CTIME_SET;
705 if (sa_valid & MDS_ATTR_FROM_OPEN)
706 ia_valid |= ATTR_FROM_OPEN;
707 if (sa_valid & MDS_ATTR_BLOCKS)
708 ia_valid |= ATTR_BLOCKS;
709 if (sa_valid & MDS_OPEN_OWNEROVERRIDE)
710 ia_valid |= MDS_OPEN_OWNEROVERRIDE;
714 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
728 if (in & ATTR_BLOCKS)
731 if (in & ATTR_FROM_OPEN)
732 rr->rr_flags |= MRF_OPEN_TRUNC;
734 if (in & ATTR_ATIME_SET)
737 if (in & ATTR_CTIME_SET)
740 if (in & ATTR_MTIME_SET)
743 if (in & ATTR_ATTR_FLAG)
746 if (in & ATTR_KILL_SUID)
749 if (in & ATTR_KILL_SGID)
752 if (in & MDS_OPEN_OWNEROVERRIDE)
753 ma->ma_attr_flags |= MDS_OPEN_OWNEROVERRIDE;
756 ma->ma_attr_flags |= MDS_PERM_BYPASS;
758 /*XXX need ATTR_RAW?*/
759 in &= ~(ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_BLOCKS|
760 ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_FROM_OPEN|
761 ATTR_ATIME_SET|ATTR_CTIME_SET|ATTR_MTIME_SET|
762 ATTR_ATTR_FLAG|ATTR_RAW|MDS_OPEN_OWNEROVERRIDE|
763 ATTR_FORCE|ATTR_KILL_SUID|ATTR_KILL_SGID);
765 CERROR("Unknown attr bits: "LPX64"\n", in);
770 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
772 struct md_ucred *uc = mdt_ucred(info);
773 struct md_attr *ma = &info->mti_attr;
774 struct lu_attr *la = &ma->ma_attr;
775 struct req_capsule *pill = info->mti_pill;
776 struct mdt_reint_record *rr = &info->mti_rr;
777 struct mdt_rec_setattr *rec;
780 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
781 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
785 uc->mu_fsuid = rec->sa_fsuid;
786 uc->mu_fsgid = rec->sa_fsgid;
787 uc->mu_cap = rec->sa_cap;
788 uc->mu_suppgids[0] = rec->sa_suppgid;
789 uc->mu_suppgids[1] = -1;
791 rr->rr_fid1 = &rec->sa_fid;
792 la->la_valid = mdt_attr_valid_xlate(attr_unpack(rec->sa_valid), rr, ma);
793 la->la_mode = rec->sa_mode;
794 la->la_flags = rec->sa_attr_flags;
795 la->la_uid = rec->sa_uid;
796 la->la_gid = rec->sa_gid;
797 la->la_size = rec->sa_size;
798 la->la_blocks = rec->sa_blocks;
799 la->la_ctime = rec->sa_ctime;
800 la->la_atime = rec->sa_atime;
801 la->la_mtime = rec->sa_mtime;
802 ma->ma_valid = MA_INODE;
804 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
805 mdt_set_capainfo(info, 0, rr->rr_fid1,
806 req_capsule_client_get(pill, &RMF_CAPA1));
811 static int mdt_ioepoch_unpack(struct mdt_thread_info *info)
813 struct req_capsule *pill = info->mti_pill;
816 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
818 req_capsule_client_get(pill, &RMF_MDT_EPOCH);
820 info->mti_ioepoch = NULL;
821 RETURN(info->mti_ioepoch == NULL ? -EFAULT : 0);
824 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
825 struct req_capsule *pill = info->mti_pill;
827 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
828 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
829 if (info->mti_dlm_req == NULL)
836 static int mdt_setattr_unpack(struct mdt_thread_info *info)
838 struct md_attr *ma = &info->mti_attr;
839 struct req_capsule *pill = info->mti_pill;
843 rc = mdt_setattr_unpack_rec(info);
847 /* Epoch may be absent */
848 mdt_ioepoch_unpack(info);
850 ma->ma_lmm_size = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
851 if (ma->ma_lmm_size) {
852 ma->ma_lmm = req_capsule_client_get(pill, &RMF_EADATA);
853 ma->ma_valid |= MA_LOV;
856 ma->ma_cookie_size = req_capsule_get_size(pill, &RMF_LOGCOOKIES,
858 if (ma->ma_cookie_size) {
859 ma->ma_cookie = req_capsule_client_get(pill, &RMF_LOGCOOKIES);
860 ma->ma_valid |= MA_COOKIE;
863 rc = mdt_dlmreq_unpack(info);
867 int mdt_close_unpack(struct mdt_thread_info *info)
872 rc = mdt_ioepoch_unpack(info);
876 RETURN(mdt_setattr_unpack_rec(info));
879 static int mdt_create_unpack(struct mdt_thread_info *info)
881 struct md_ucred *uc = mdt_ucred(info);
882 struct mdt_rec_create *rec;
883 struct lu_attr *attr = &info->mti_attr.ma_attr;
884 struct mdt_reint_record *rr = &info->mti_rr;
885 struct req_capsule *pill = info->mti_pill;
886 struct md_op_spec *sp = &info->mti_spec;
890 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
891 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
895 uc->mu_fsuid = rec->cr_fsuid;
896 uc->mu_fsgid = rec->cr_fsgid;
897 uc->mu_cap = rec->cr_cap;
898 uc->mu_suppgids[0] = rec->cr_suppgid1;
899 uc->mu_suppgids[1] = -1;
901 rr->rr_fid1 = &rec->cr_fid1;
902 rr->rr_fid2 = &rec->cr_fid2;
903 attr->la_mode = rec->cr_mode;
904 attr->la_rdev = rec->cr_rdev;
905 attr->la_uid = rec->cr_fsuid;
906 attr->la_gid = rec->cr_fsgid;
907 attr->la_ctime = rec->cr_time;
908 attr->la_mtime = rec->cr_time;
909 attr->la_atime = rec->cr_time;
910 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
911 LA_CTIME | LA_MTIME | LA_ATIME;
912 memset(&sp->u, 0, sizeof(sp->u));
913 sp->sp_cr_flags = get_mrc_cr_flags(rec);
914 sp->sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
915 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
917 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
918 mdt_set_capainfo(info, 0, rr->rr_fid1,
919 req_capsule_client_get(pill, &RMF_CAPA1));
920 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
922 if (!info->mti_cross_ref) {
923 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
924 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME,
926 LASSERT(rr->rr_name && rr->rr_namelen > 0);
932 #ifdef CONFIG_FS_POSIX_ACL
933 if (sp->sp_cr_flags & MDS_CREATE_RMT_ACL) {
934 if (S_ISDIR(attr->la_mode))
935 sp->u.sp_pfid = rr->rr_fid1;
936 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
937 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
939 sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA);
940 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
942 sp->u.sp_ea.fid = rr->rr_fid1;
946 if (S_ISDIR(attr->la_mode)) {
947 /* pass parent fid for cross-ref cases */
948 sp->u.sp_pfid = rr->rr_fid1;
949 if (sp->sp_cr_flags & MDS_CREATE_SLAVE_OBJ) {
950 /* create salve object req, need
951 * unpack split ea here
953 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SLAVE);
954 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
956 sp->u.sp_ea.eadata = req_capsule_client_get(pill,
958 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill,
961 sp->u.sp_ea.fid = rr->rr_fid1;
964 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
965 } else if (S_ISLNK(attr->la_mode)) {
966 const char *tgt = NULL;
968 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
969 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
970 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
971 sp->u.sp_symname = tgt;
976 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
978 rc = mdt_dlmreq_unpack(info);
982 static int mdt_link_unpack(struct mdt_thread_info *info)
984 struct md_ucred *uc = mdt_ucred(info);
985 struct mdt_rec_link *rec;
986 struct lu_attr *attr = &info->mti_attr.ma_attr;
987 struct mdt_reint_record *rr = &info->mti_rr;
988 struct req_capsule *pill = info->mti_pill;
992 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
993 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
997 uc->mu_fsuid = rec->lk_fsuid;
998 uc->mu_fsgid = rec->lk_fsgid;
999 uc->mu_cap = rec->lk_cap;
1000 uc->mu_suppgids[0] = rec->lk_suppgid1;
1001 uc->mu_suppgids[1] = rec->lk_suppgid2;
1003 attr->la_uid = rec->lk_fsuid;
1004 attr->la_gid = rec->lk_fsgid;
1005 rr->rr_fid1 = &rec->lk_fid1;
1006 rr->rr_fid2 = &rec->lk_fid2;
1007 attr->la_ctime = rec->lk_time;
1008 attr->la_mtime = rec->lk_time;
1009 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1011 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1012 mdt_set_capainfo(info, 0, rr->rr_fid1,
1013 req_capsule_client_get(pill, &RMF_CAPA1));
1014 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1015 mdt_set_capainfo(info, 1, rr->rr_fid2,
1016 req_capsule_client_get(pill, &RMF_CAPA2));
1018 info->mti_spec.sp_ck_split = !!(rec->lk_bias & MDS_CHECK_SPLIT);
1019 info->mti_cross_ref = !!(rec->lk_bias & MDS_CROSS_REF);
1020 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1021 if (rr->rr_name == NULL)
1023 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1024 if (!info->mti_cross_ref)
1025 LASSERT(rr->rr_namelen > 0);
1027 rc = mdt_dlmreq_unpack(info);
1031 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1033 struct md_ucred *uc = mdt_ucred(info);
1034 struct mdt_rec_unlink *rec;
1035 struct md_attr *ma = &info->mti_attr;
1036 struct lu_attr *attr = &info->mti_attr.ma_attr;
1037 struct mdt_reint_record *rr = &info->mti_rr;
1038 struct req_capsule *pill = info->mti_pill;
1042 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1043 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1047 uc->mu_fsuid = rec->ul_fsuid;
1048 uc->mu_fsgid = rec->ul_fsgid;
1049 uc->mu_cap = rec->ul_cap;
1050 uc->mu_suppgids[0] = rec->ul_suppgid1;
1051 uc->mu_suppgids[1] = -1;
1053 attr->la_uid = rec->ul_fsuid;
1054 attr->la_gid = rec->ul_fsgid;
1055 rr->rr_fid1 = &rec->ul_fid1;
1056 rr->rr_fid2 = &rec->ul_fid2;
1057 attr->la_ctime = rec->ul_time;
1058 attr->la_mtime = rec->ul_time;
1059 attr->la_mode = rec->ul_mode;
1060 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1062 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1063 mdt_set_capainfo(info, 0, rr->rr_fid1,
1064 req_capsule_client_get(pill, &RMF_CAPA1));
1066 info->mti_cross_ref = !!(rec->ul_bias & MDS_CROSS_REF);
1067 if (!info->mti_cross_ref) {
1068 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1069 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1070 if (rr->rr_name == NULL || rr->rr_namelen == 0)
1076 info->mti_spec.sp_ck_split = !!(rec->ul_bias & MDS_CHECK_SPLIT);
1077 if (rec->ul_bias & MDS_VTX_BYPASS)
1078 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1080 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1082 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1084 rc = mdt_dlmreq_unpack(info);
1088 static int mdt_rename_unpack(struct mdt_thread_info *info)
1090 struct md_ucred *uc = mdt_ucred(info);
1091 struct mdt_rec_rename *rec;
1092 struct md_attr *ma = &info->mti_attr;
1093 struct lu_attr *attr = &info->mti_attr.ma_attr;
1094 struct mdt_reint_record *rr = &info->mti_rr;
1095 struct req_capsule *pill = info->mti_pill;
1099 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1100 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1104 uc->mu_fsuid = rec->rn_fsuid;
1105 uc->mu_fsgid = rec->rn_fsgid;
1106 uc->mu_cap = rec->rn_cap;
1107 uc->mu_suppgids[0] = rec->rn_suppgid1;
1108 uc->mu_suppgids[1] = rec->rn_suppgid2;
1110 attr->la_uid = rec->rn_fsuid;
1111 attr->la_gid = rec->rn_fsgid;
1112 rr->rr_fid1 = &rec->rn_fid1;
1113 rr->rr_fid2 = &rec->rn_fid2;
1114 attr->la_ctime = rec->rn_time;
1115 attr->la_mtime = rec->rn_time;
1116 /* rename_tgt contains the mode already */
1117 attr->la_mode = rec->rn_mode;
1118 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1120 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1121 mdt_set_capainfo(info, 0, rr->rr_fid1,
1122 req_capsule_client_get(pill, &RMF_CAPA1));
1123 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1124 mdt_set_capainfo(info, 1, rr->rr_fid2,
1125 req_capsule_client_get(pill, &RMF_CAPA2));
1127 info->mti_spec.sp_ck_split = !!(rec->rn_bias & MDS_CHECK_SPLIT);
1128 info->mti_cross_ref = !!(rec->rn_bias & MDS_CROSS_REF);
1129 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1130 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1131 if (rr->rr_name == NULL || rr->rr_tgt == NULL)
1133 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1134 rr->rr_tgtlen = req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT) - 1;
1135 if (!info->mti_cross_ref)
1136 LASSERT(rr->rr_namelen > 0 && rr->rr_tgtlen > 0);
1137 if (rec->rn_bias & MDS_VTX_BYPASS)
1138 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1140 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1142 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1144 rc = mdt_dlmreq_unpack(info);
1148 static int mdt_open_unpack(struct mdt_thread_info *info)
1150 struct md_ucred *uc = mdt_ucred(info);
1151 struct mdt_rec_create *rec;
1152 struct lu_attr *attr = &info->mti_attr.ma_attr;
1153 struct req_capsule *pill = info->mti_pill;
1154 struct mdt_reint_record *rr = &info->mti_rr;
1155 struct ptlrpc_request *req = mdt_info_req(info);
1156 struct md_op_spec *sp = &info->mti_spec;
1159 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1160 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1164 uc->mu_fsuid = rec->cr_fsuid;
1165 uc->mu_fsgid = rec->cr_fsgid;
1166 uc->mu_cap = rec->cr_cap;
1167 uc->mu_suppgids[0] = rec->cr_suppgid1;
1168 uc->mu_suppgids[1] = rec->cr_suppgid2;
1170 rr->rr_fid1 = &rec->cr_fid1;
1171 rr->rr_fid2 = &rec->cr_fid2;
1172 rr->rr_handle = &rec->cr_old_handle;
1173 attr->la_mode = rec->cr_mode;
1174 attr->la_rdev = rec->cr_rdev;
1175 attr->la_uid = rec->cr_fsuid;
1176 attr->la_gid = rec->cr_fsgid;
1177 attr->la_ctime = rec->cr_time;
1178 attr->la_mtime = rec->cr_time;
1179 attr->la_atime = rec->cr_time;
1180 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1181 LA_CTIME | LA_MTIME | LA_ATIME;
1182 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1183 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1184 /* Do not trigger ASSERTION if client miss to set such flags. */
1185 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1187 info->mti_replayepoch = rec->cr_ioepoch;
1189 info->mti_spec.sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
1190 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1192 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1193 mdt_set_capainfo(info, 0, rr->rr_fid1,
1194 req_capsule_client_get(pill, &RMF_CAPA1));
1195 if (req_is_replay(req) &&
1196 req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) {
1198 mdt_set_capainfo(info, 1, rr->rr_fid2,
1199 req_capsule_client_get(pill, &RMF_CAPA2));
1202 * FIXME: capa in replay open request might have expired,
1203 * bypass capa check. Security hole?
1205 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1206 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1210 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1211 if (rr->rr_name == NULL)
1213 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1215 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1217 if (sp->u.sp_ea.eadatalen) {
1218 sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA);
1219 sp->no_create = !!req_is_replay(req);
1225 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1227 struct mdt_reint_record *rr = &info->mti_rr;
1228 struct md_ucred *uc = mdt_ucred(info);
1229 struct lu_attr *attr = &info->mti_attr.ma_attr;
1230 struct req_capsule *pill = info->mti_pill;
1231 struct mdt_rec_setxattr *rec;
1235 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1236 sizeof(struct mdt_rec_reint));
1238 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1242 uc->mu_fsuid = rec->sx_fsuid;
1243 uc->mu_fsgid = rec->sx_fsgid;
1244 uc->mu_cap = rec->sx_cap;
1245 uc->mu_suppgids[0] = rec->sx_suppgid1;
1246 uc->mu_suppgids[1] = -1;
1248 rr->rr_opcode = rec->sx_opcode;
1249 rr->rr_fid1 = &rec->sx_fid;
1250 attr->la_valid = rec->sx_valid;
1251 attr->la_ctime = rec->sx_time;
1252 attr->la_size = rec->sx_size;
1253 attr->la_flags = rec->sx_flags;
1255 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1256 mdt_set_capainfo(info, 0, rr->rr_fid1,
1257 req_capsule_client_get(pill, &RMF_CAPA1));
1259 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1261 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1262 if (rr->rr_name == NULL)
1264 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1265 LASSERT(rr->rr_namelen > 0);
1267 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
1268 if (rr->rr_eadatalen > 0) {
1269 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
1270 if (rr->rr_eadata == NULL)
1278 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1280 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1281 [REINT_SETATTR] = mdt_setattr_unpack,
1282 [REINT_CREATE] = mdt_create_unpack,
1283 [REINT_LINK] = mdt_link_unpack,
1284 [REINT_UNLINK] = mdt_unlink_unpack,
1285 [REINT_RENAME] = mdt_rename_unpack,
1286 [REINT_OPEN] = mdt_open_unpack,
1287 [REINT_SETXATTR] = mdt_setxattr_unpack
1290 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1295 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1296 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1297 info->mti_rr.rr_opcode = op;
1298 rc = mdt_reint_unpackers[op](info);
1300 CERROR("Unexpected opcode %d\n", op);