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 /* Shrink and/or grow reply buffers */
554 int mdt_fix_reply(struct mdt_thread_info *info)
556 struct req_capsule *pill = info->mti_pill;
557 struct mdt_body *body;
558 int md_size, md_packed = 0;
563 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
564 LASSERT(body != NULL);
566 if (body->valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE | OBD_MD_LINKNAME))
567 md_size = body->eadatasize;
571 acl_size = body->aclsize;
573 /* this replay - not send info to client */
574 if (info->mti_spec.no_create == 1) {
579 CDEBUG(D_INFO, "Shrink to md_size = %d cookie/acl_size = %d"
580 " MDSCAPA = %llx, OSSCAPA = %llx\n",
582 (unsigned long long)(body->valid & OBD_MD_FLMDSCAPA),
583 (unsigned long long)(body->valid & OBD_MD_FLOSSCAPA));
587 &RMF_ACL, or &RMF_LOGCOOKIES
588 (optional) &RMF_CAPA1,
589 (optional) &RMF_CAPA2,
590 (optional) something else
593 /* MDT_MD buffer may be bigger than packed value, let's shrink all
594 * buffers before growing it */
595 if (info->mti_attr.ma_big_lmm_used) {
596 LASSERT(req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER));
597 md_packed = req_capsule_get_size(pill, &RMF_MDT_MD,
599 LASSERT(md_packed > 0);
600 /* buffer must be allocated separately */
601 LASSERT(info->mti_attr.ma_lmm !=
602 req_capsule_server_get(pill, &RMF_MDT_MD));
603 req_capsule_shrink(pill, &RMF_MDT_MD, 0, RCL_SERVER);
604 /* free big lmm if md_size is not needed */
606 info->mti_attr.ma_big_lmm_used = 0;
607 } else if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
608 req_capsule_shrink(pill, &RMF_MDT_MD, md_size, RCL_SERVER);
611 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
612 req_capsule_shrink(pill, &RMF_ACL, acl_size, RCL_SERVER);
613 else if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
614 req_capsule_shrink(pill, &RMF_LOGCOOKIES,
615 acl_size, RCL_SERVER);
617 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_SERVER) &&
618 !(body->valid & OBD_MD_FLMDSCAPA))
619 req_capsule_shrink(pill, &RMF_CAPA1, 0, RCL_SERVER);
621 if (req_capsule_has_field(pill, &RMF_CAPA2, RCL_SERVER) &&
622 !(body->valid & OBD_MD_FLOSSCAPA))
623 req_capsule_shrink(pill, &RMF_CAPA2, 0, RCL_SERVER);
626 * Some more field should be shrinked if needed.
627 * This should be done by those who added fields to reply message.
630 /* Grow MD buffer if needed finally */
631 if (info->mti_attr.ma_big_lmm_used) {
634 LASSERT(md_size > md_packed);
635 CDEBUG(D_INFO, "Enlarge reply buffer, need extra %d bytes\n",
636 md_size - md_packed);
637 rc = req_capsule_server_grow(pill, &RMF_MDT_MD, md_size);
639 /* we can't answer with proper LOV EA, drop flags,
640 * the rc is also returned so this request is
641 * considered as failed */
642 body->valid &= ~(OBD_MD_FLDIREA | OBD_MD_FLEASIZE);
643 /* don't return transno along with error */
644 lustre_msg_set_transno(pill->rc_req->rq_repmsg, 0);
646 /* now we need to pack right LOV EA */
647 lmm = req_capsule_server_get(pill, &RMF_MDT_MD);
648 LASSERT(req_capsule_get_size(pill, &RMF_MDT_MD,
650 info->mti_attr.ma_lmm_size);
651 memcpy(lmm, info->mti_attr.ma_lmm,
652 info->mti_attr.ma_lmm_size);
654 /* update mdt_max_mdsize so clients will be aware about that */
655 if (info->mti_mdt->mdt_max_mdsize < info->mti_attr.ma_lmm_size)
656 info->mti_mdt->mdt_max_mdsize =
657 info->mti_attr.ma_lmm_size;
658 info->mti_attr.ma_big_lmm_used = 0;
664 /* if object is dying, pack the lov/llog data,
665 * parameter info->mti_attr should be valid at this point! */
666 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
667 const struct md_attr *ma)
669 struct mdt_body *repbody;
670 const struct lu_attr *la = &ma->ma_attr;
674 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
675 LASSERT(repbody != NULL);
677 if (ma->ma_valid & MA_INODE)
678 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(mo));
680 if (ma->ma_valid & MA_LOV) {
683 if (mdt_object_exists(mo) < 0)
684 /* If it is a remote object, and we do not retrieve
685 * EA back unlink reg file*/
688 mode = lu_object_attr(&mo->mot_obj.mo_lu);
690 LASSERT(ma->ma_lmm_size);
691 mdt_dump_lmm(D_INFO, ma->ma_lmm);
692 repbody->eadatasize = ma->ma_lmm_size;
694 repbody->valid |= OBD_MD_FLEASIZE;
695 else if (S_ISDIR(mode))
696 repbody->valid |= OBD_MD_FLDIREA;
701 if (ma->ma_cookie_size && (ma->ma_valid & MA_COOKIE)) {
702 repbody->aclsize = ma->ma_cookie_size;
703 repbody->valid |= OBD_MD_FLCOOKIE;
706 if (info->mti_mdt->mdt_opts.mo_oss_capa &&
707 info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA &&
708 repbody->valid & OBD_MD_FLEASIZE) {
709 struct lustre_capa *capa;
711 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
713 capa->lc_opc = CAPA_OPC_OSS_DESTROY;
714 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0);
718 repbody->valid |= OBD_MD_FLOSSCAPA;
724 static inline unsigned int attr_unpack(__u64 sa_valid) {
725 unsigned int ia_valid = 0;
727 if (sa_valid & MDS_ATTR_MODE)
728 ia_valid |= ATTR_MODE;
729 if (sa_valid & MDS_ATTR_UID)
730 ia_valid |= ATTR_UID;
731 if (sa_valid & MDS_ATTR_GID)
732 ia_valid |= ATTR_GID;
733 if (sa_valid & MDS_ATTR_SIZE)
734 ia_valid |= ATTR_SIZE;
735 if (sa_valid & MDS_ATTR_ATIME)
736 ia_valid |= ATTR_ATIME;
737 if (sa_valid & MDS_ATTR_MTIME)
738 ia_valid |= ATTR_MTIME;
739 if (sa_valid & MDS_ATTR_CTIME)
740 ia_valid |= ATTR_CTIME;
741 if (sa_valid & MDS_ATTR_ATIME_SET)
742 ia_valid |= ATTR_ATIME_SET;
743 if (sa_valid & MDS_ATTR_MTIME_SET)
744 ia_valid |= ATTR_MTIME_SET;
745 if (sa_valid & MDS_ATTR_FORCE)
746 ia_valid |= ATTR_FORCE;
747 if (sa_valid & MDS_ATTR_ATTR_FLAG)
748 ia_valid |= ATTR_ATTR_FLAG;
749 if (sa_valid & MDS_ATTR_KILL_SUID)
750 ia_valid |= ATTR_KILL_SUID;
751 if (sa_valid & MDS_ATTR_KILL_SGID)
752 ia_valid |= ATTR_KILL_SGID;
753 if (sa_valid & MDS_ATTR_CTIME_SET)
754 ia_valid |= ATTR_CTIME_SET;
755 if (sa_valid & MDS_ATTR_FROM_OPEN)
756 ia_valid |= ATTR_FROM_OPEN;
757 if (sa_valid & MDS_ATTR_BLOCKS)
758 ia_valid |= ATTR_BLOCKS;
759 if (sa_valid & MDS_OPEN_OWNEROVERRIDE)
760 ia_valid |= MDS_OPEN_OWNEROVERRIDE;
764 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
778 if (in & ATTR_BLOCKS)
781 if (in & ATTR_FROM_OPEN)
782 rr->rr_flags |= MRF_OPEN_TRUNC;
784 if (in & ATTR_ATIME_SET)
787 if (in & ATTR_CTIME_SET)
790 if (in & ATTR_MTIME_SET)
793 if (in & ATTR_ATTR_FLAG)
796 if (in & ATTR_KILL_SUID)
799 if (in & ATTR_KILL_SGID)
802 if (in & MDS_OPEN_OWNEROVERRIDE)
803 ma->ma_attr_flags |= MDS_OPEN_OWNEROVERRIDE;
806 ma->ma_attr_flags |= MDS_PERM_BYPASS;
808 /*XXX need ATTR_RAW?*/
809 in &= ~(ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_BLOCKS|
810 ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_FROM_OPEN|
811 ATTR_ATIME_SET|ATTR_CTIME_SET|ATTR_MTIME_SET|
812 ATTR_ATTR_FLAG|ATTR_RAW|MDS_OPEN_OWNEROVERRIDE|
813 ATTR_FORCE|ATTR_KILL_SUID|ATTR_KILL_SGID);
815 CERROR("Unknown attr bits: "LPX64"\n", in);
820 static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
822 struct md_ucred *uc = mdt_ucred(info);
823 struct md_attr *ma = &info->mti_attr;
824 struct lu_attr *la = &ma->ma_attr;
825 struct req_capsule *pill = info->mti_pill;
826 struct mdt_reint_record *rr = &info->mti_rr;
827 struct mdt_rec_setattr *rec;
830 CLASSERT(sizeof(struct mdt_rec_setattr)== sizeof(struct mdt_rec_reint));
831 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
835 uc->mu_fsuid = rec->sa_fsuid;
836 uc->mu_fsgid = rec->sa_fsgid;
837 uc->mu_cap = rec->sa_cap;
838 uc->mu_suppgids[0] = rec->sa_suppgid;
839 uc->mu_suppgids[1] = -1;
841 rr->rr_fid1 = &rec->sa_fid;
842 la->la_valid = mdt_attr_valid_xlate(attr_unpack(rec->sa_valid), rr, ma);
843 la->la_mode = rec->sa_mode;
844 la->la_flags = rec->sa_attr_flags;
845 la->la_uid = rec->sa_uid;
846 la->la_gid = rec->sa_gid;
847 la->la_size = rec->sa_size;
848 la->la_blocks = rec->sa_blocks;
849 la->la_ctime = rec->sa_ctime;
850 la->la_atime = rec->sa_atime;
851 la->la_mtime = rec->sa_mtime;
852 ma->ma_valid = MA_INODE;
854 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
855 mdt_set_capainfo(info, 0, rr->rr_fid1,
856 req_capsule_client_get(pill, &RMF_CAPA1));
861 static int mdt_ioepoch_unpack(struct mdt_thread_info *info)
863 struct req_capsule *pill = info->mti_pill;
866 if (req_capsule_get_size(pill, &RMF_MDT_EPOCH, RCL_CLIENT))
868 req_capsule_client_get(pill, &RMF_MDT_EPOCH);
870 info->mti_ioepoch = NULL;
871 RETURN(info->mti_ioepoch == NULL ? -EFAULT : 0);
874 static inline int mdt_dlmreq_unpack(struct mdt_thread_info *info) {
875 struct req_capsule *pill = info->mti_pill;
877 if (req_capsule_get_size(pill, &RMF_DLM_REQ, RCL_CLIENT)) {
878 info->mti_dlm_req = req_capsule_client_get(pill, &RMF_DLM_REQ);
879 if (info->mti_dlm_req == NULL)
886 static int mdt_setattr_unpack(struct mdt_thread_info *info)
888 struct mdt_reint_record *rr = &info->mti_rr;
889 struct md_attr *ma = &info->mti_attr;
890 struct req_capsule *pill = info->mti_pill;
894 rc = mdt_setattr_unpack_rec(info);
898 /* Epoch may be absent */
899 mdt_ioepoch_unpack(info);
901 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
902 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
903 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
905 ma->ma_lmm_size = rr->rr_eadatalen;
906 if (ma->ma_lmm_size > 0) {
907 ma->ma_lmm = (void *)rr->rr_eadata;
908 ma->ma_valid |= MA_LOV;
912 ma->ma_cookie_size = req_capsule_get_size(pill, &RMF_LOGCOOKIES,
914 if (ma->ma_cookie_size) {
915 ma->ma_cookie = req_capsule_client_get(pill, &RMF_LOGCOOKIES);
916 ma->ma_valid |= MA_COOKIE;
919 rc = mdt_dlmreq_unpack(info);
923 int mdt_close_unpack(struct mdt_thread_info *info)
928 rc = mdt_ioepoch_unpack(info);
932 RETURN(mdt_setattr_unpack_rec(info));
935 static int mdt_create_unpack(struct mdt_thread_info *info)
937 struct md_ucred *uc = mdt_ucred(info);
938 struct mdt_rec_create *rec;
939 struct lu_attr *attr = &info->mti_attr.ma_attr;
940 struct mdt_reint_record *rr = &info->mti_rr;
941 struct req_capsule *pill = info->mti_pill;
942 struct md_op_spec *sp = &info->mti_spec;
946 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
947 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
951 uc->mu_fsuid = rec->cr_fsuid;
952 uc->mu_fsgid = rec->cr_fsgid;
953 uc->mu_cap = rec->cr_cap;
954 uc->mu_suppgids[0] = rec->cr_suppgid1;
955 uc->mu_suppgids[1] = -1;
957 rr->rr_fid1 = &rec->cr_fid1;
958 rr->rr_fid2 = &rec->cr_fid2;
959 attr->la_mode = rec->cr_mode;
960 attr->la_rdev = rec->cr_rdev;
961 attr->la_uid = rec->cr_fsuid;
962 attr->la_gid = rec->cr_fsgid;
963 attr->la_ctime = rec->cr_time;
964 attr->la_mtime = rec->cr_time;
965 attr->la_atime = rec->cr_time;
966 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
967 LA_CTIME | LA_MTIME | LA_ATIME;
968 memset(&sp->u, 0, sizeof(sp->u));
969 sp->sp_cr_flags = get_mrc_cr_flags(rec);
970 sp->sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
971 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
973 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
974 mdt_set_capainfo(info, 0, rr->rr_fid1,
975 req_capsule_client_get(pill, &RMF_CAPA1));
976 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
978 if (!info->mti_cross_ref) {
979 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
980 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME,
982 LASSERT(rr->rr_name && rr->rr_namelen > 0);
988 #ifdef CONFIG_FS_POSIX_ACL
989 if (sp->sp_cr_flags & MDS_CREATE_RMT_ACL) {
990 if (S_ISDIR(attr->la_mode))
991 sp->u.sp_pfid = rr->rr_fid1;
992 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
993 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
995 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
996 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
998 sp->u.sp_ea.eadata = rr->rr_eadata;
999 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1000 sp->u.sp_ea.fid = rr->rr_fid1;
1004 if (S_ISDIR(attr->la_mode)) {
1005 /* pass parent fid for cross-ref cases */
1006 sp->u.sp_pfid = rr->rr_fid1;
1007 if (sp->sp_cr_flags & MDS_CREATE_SLAVE_OBJ) {
1008 /* create salve object req, need
1009 * unpack split ea here
1011 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SLAVE);
1012 LASSERT(req_capsule_field_present(pill, &RMF_EADATA,
1014 rr->rr_eadata = req_capsule_client_get(pill,
1016 rr->rr_eadatalen = req_capsule_get_size(pill,
1019 sp->u.sp_ea.eadata = rr->rr_eadata;
1020 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1021 sp->u.sp_ea.fid = rr->rr_fid1;
1024 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
1025 } else if (S_ISLNK(attr->la_mode)) {
1026 const char *tgt = NULL;
1028 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_SYM);
1029 if (req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT)) {
1030 tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1031 sp->u.sp_symname = tgt;
1036 req_capsule_extend(pill, &RQF_MDS_REINT_CREATE_RMT_ACL);
1038 rc = mdt_dlmreq_unpack(info);
1042 static int mdt_link_unpack(struct mdt_thread_info *info)
1044 struct md_ucred *uc = mdt_ucred(info);
1045 struct mdt_rec_link *rec;
1046 struct lu_attr *attr = &info->mti_attr.ma_attr;
1047 struct mdt_reint_record *rr = &info->mti_rr;
1048 struct req_capsule *pill = info->mti_pill;
1052 CLASSERT(sizeof(struct mdt_rec_link) == sizeof(struct mdt_rec_reint));
1053 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1057 uc->mu_fsuid = rec->lk_fsuid;
1058 uc->mu_fsgid = rec->lk_fsgid;
1059 uc->mu_cap = rec->lk_cap;
1060 uc->mu_suppgids[0] = rec->lk_suppgid1;
1061 uc->mu_suppgids[1] = rec->lk_suppgid2;
1063 attr->la_uid = rec->lk_fsuid;
1064 attr->la_gid = rec->lk_fsgid;
1065 rr->rr_fid1 = &rec->lk_fid1;
1066 rr->rr_fid2 = &rec->lk_fid2;
1067 attr->la_ctime = rec->lk_time;
1068 attr->la_mtime = rec->lk_time;
1069 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
1071 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1072 mdt_set_capainfo(info, 0, rr->rr_fid1,
1073 req_capsule_client_get(pill, &RMF_CAPA1));
1074 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1075 mdt_set_capainfo(info, 1, rr->rr_fid2,
1076 req_capsule_client_get(pill, &RMF_CAPA2));
1078 info->mti_spec.sp_ck_split = !!(rec->lk_bias & MDS_CHECK_SPLIT);
1079 info->mti_cross_ref = !!(rec->lk_bias & MDS_CROSS_REF);
1080 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1081 if (rr->rr_name == NULL)
1083 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1084 if (!info->mti_cross_ref)
1085 LASSERT(rr->rr_namelen > 0);
1087 rc = mdt_dlmreq_unpack(info);
1091 static int mdt_unlink_unpack(struct mdt_thread_info *info)
1093 struct md_ucred *uc = mdt_ucred(info);
1094 struct mdt_rec_unlink *rec;
1095 struct md_attr *ma = &info->mti_attr;
1096 struct lu_attr *attr = &info->mti_attr.ma_attr;
1097 struct mdt_reint_record *rr = &info->mti_rr;
1098 struct req_capsule *pill = info->mti_pill;
1102 CLASSERT(sizeof(struct mdt_rec_unlink) == sizeof(struct mdt_rec_reint));
1103 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1107 uc->mu_fsuid = rec->ul_fsuid;
1108 uc->mu_fsgid = rec->ul_fsgid;
1109 uc->mu_cap = rec->ul_cap;
1110 uc->mu_suppgids[0] = rec->ul_suppgid1;
1111 uc->mu_suppgids[1] = -1;
1113 attr->la_uid = rec->ul_fsuid;
1114 attr->la_gid = rec->ul_fsgid;
1115 rr->rr_fid1 = &rec->ul_fid1;
1116 rr->rr_fid2 = &rec->ul_fid2;
1117 attr->la_ctime = rec->ul_time;
1118 attr->la_mtime = rec->ul_time;
1119 attr->la_mode = rec->ul_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));
1126 info->mti_cross_ref = !!(rec->ul_bias & MDS_CROSS_REF);
1127 if (!info->mti_cross_ref) {
1128 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1129 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1130 if (rr->rr_name == NULL || rr->rr_namelen == 0)
1136 info->mti_spec.sp_ck_split = !!(rec->ul_bias & MDS_CHECK_SPLIT);
1137 if (rec->ul_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));
1143 /* last unlink need LOV EA sent back */
1144 rr->rr_eadatalen = info->mti_mdt->mdt_max_mdsize;
1146 rc = mdt_dlmreq_unpack(info);
1150 static int mdt_rename_unpack(struct mdt_thread_info *info)
1152 struct md_ucred *uc = mdt_ucred(info);
1153 struct mdt_rec_rename *rec;
1154 struct md_attr *ma = &info->mti_attr;
1155 struct lu_attr *attr = &info->mti_attr.ma_attr;
1156 struct mdt_reint_record *rr = &info->mti_rr;
1157 struct req_capsule *pill = info->mti_pill;
1161 CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint));
1162 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1166 uc->mu_fsuid = rec->rn_fsuid;
1167 uc->mu_fsgid = rec->rn_fsgid;
1168 uc->mu_cap = rec->rn_cap;
1169 uc->mu_suppgids[0] = rec->rn_suppgid1;
1170 uc->mu_suppgids[1] = rec->rn_suppgid2;
1172 attr->la_uid = rec->rn_fsuid;
1173 attr->la_gid = rec->rn_fsgid;
1174 rr->rr_fid1 = &rec->rn_fid1;
1175 rr->rr_fid2 = &rec->rn_fid2;
1176 attr->la_ctime = rec->rn_time;
1177 attr->la_mtime = rec->rn_time;
1178 /* rename_tgt contains the mode already */
1179 attr->la_mode = rec->rn_mode;
1180 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
1182 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1183 mdt_set_capainfo(info, 0, rr->rr_fid1,
1184 req_capsule_client_get(pill, &RMF_CAPA1));
1185 if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT))
1186 mdt_set_capainfo(info, 1, rr->rr_fid2,
1187 req_capsule_client_get(pill, &RMF_CAPA2));
1189 info->mti_spec.sp_ck_split = !!(rec->rn_bias & MDS_CHECK_SPLIT);
1190 info->mti_cross_ref = !!(rec->rn_bias & MDS_CROSS_REF);
1191 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1192 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
1193 if (rr->rr_name == NULL || rr->rr_tgt == NULL)
1195 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1196 rr->rr_tgtlen = req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT) - 1;
1197 if (!info->mti_cross_ref)
1198 LASSERT(rr->rr_namelen > 0 && rr->rr_tgtlen > 0);
1199 if (rec->rn_bias & MDS_VTX_BYPASS)
1200 ma->ma_attr_flags |= MDS_VTX_BYPASS;
1202 ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
1204 info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info));
1205 /* rename may contain unlink so we might need LOV EA sent back */
1206 rr->rr_eadatalen = info->mti_mdt->mdt_max_mdsize;
1208 rc = mdt_dlmreq_unpack(info);
1212 static int mdt_open_unpack(struct mdt_thread_info *info)
1214 struct md_ucred *uc = mdt_ucred(info);
1215 struct mdt_rec_create *rec;
1216 struct lu_attr *attr = &info->mti_attr.ma_attr;
1217 struct req_capsule *pill = info->mti_pill;
1218 struct mdt_reint_record *rr = &info->mti_rr;
1219 struct ptlrpc_request *req = mdt_info_req(info);
1220 struct md_op_spec *sp = &info->mti_spec;
1223 CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint));
1224 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1228 uc->mu_fsuid = rec->cr_fsuid;
1229 uc->mu_fsgid = rec->cr_fsgid;
1230 uc->mu_cap = rec->cr_cap;
1231 uc->mu_suppgids[0] = rec->cr_suppgid1;
1232 uc->mu_suppgids[1] = rec->cr_suppgid2;
1234 rr->rr_fid1 = &rec->cr_fid1;
1235 rr->rr_fid2 = &rec->cr_fid2;
1236 rr->rr_handle = &rec->cr_old_handle;
1237 attr->la_mode = rec->cr_mode;
1238 attr->la_rdev = rec->cr_rdev;
1239 attr->la_uid = rec->cr_fsuid;
1240 attr->la_gid = rec->cr_fsgid;
1241 attr->la_ctime = rec->cr_time;
1242 attr->la_mtime = rec->cr_time;
1243 attr->la_atime = rec->cr_time;
1244 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
1245 LA_CTIME | LA_MTIME | LA_ATIME;
1246 memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u));
1247 info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec);
1248 /* Do not trigger ASSERTION if client miss to set such flags. */
1249 if (unlikely(info->mti_spec.sp_cr_flags == 0))
1251 info->mti_replayepoch = rec->cr_ioepoch;
1253 info->mti_spec.sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT);
1254 info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF);
1256 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1257 mdt_set_capainfo(info, 0, rr->rr_fid1,
1258 req_capsule_client_get(pill, &RMF_CAPA1));
1259 if (req_is_replay(req) &&
1260 req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) {
1262 mdt_set_capainfo(info, 1, rr->rr_fid2,
1263 req_capsule_client_get(pill, &RMF_CAPA2));
1266 * FIXME: capa in replay open request might have expired,
1267 * bypass capa check. Security hole?
1269 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1270 mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA);
1274 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1275 if (rr->rr_name == NULL)
1277 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1279 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1280 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1282 if (rr->rr_eadatalen > 0) {
1283 rr->rr_eadata = req_capsule_client_get(pill,
1285 sp->u.sp_ea.eadatalen = rr->rr_eadatalen;
1286 sp->u.sp_ea.eadata = rr->rr_eadata;
1287 sp->no_create = !!req_is_replay(req);
1291 * Client default md_size may be 0 right after client start,
1292 * until all osc are connected, set here just some reasonable
1293 * value to prevent misbehavior.
1295 if (rr->rr_eadatalen == 0 &&
1296 !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE))
1297 rr->rr_eadatalen = MIN_MD_SIZE; }
1302 static int mdt_setxattr_unpack(struct mdt_thread_info *info)
1304 struct mdt_reint_record *rr = &info->mti_rr;
1305 struct md_ucred *uc = mdt_ucred(info);
1306 struct lu_attr *attr = &info->mti_attr.ma_attr;
1307 struct req_capsule *pill = info->mti_pill;
1308 struct mdt_rec_setxattr *rec;
1312 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
1313 sizeof(struct mdt_rec_reint));
1315 rec = req_capsule_client_get(pill, &RMF_REC_REINT);
1319 uc->mu_fsuid = rec->sx_fsuid;
1320 uc->mu_fsgid = rec->sx_fsgid;
1321 uc->mu_cap = rec->sx_cap;
1322 uc->mu_suppgids[0] = rec->sx_suppgid1;
1323 uc->mu_suppgids[1] = -1;
1325 rr->rr_opcode = rec->sx_opcode;
1326 rr->rr_fid1 = &rec->sx_fid;
1327 attr->la_valid = rec->sx_valid;
1328 attr->la_ctime = rec->sx_time;
1329 attr->la_size = rec->sx_size;
1330 attr->la_flags = rec->sx_flags;
1332 if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1333 mdt_set_capainfo(info, 0, rr->rr_fid1,
1334 req_capsule_client_get(pill, &RMF_CAPA1));
1336 mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
1338 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
1339 if (rr->rr_name == NULL)
1341 rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1;
1342 LASSERT(rr->rr_namelen > 0);
1344 if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
1345 rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA,
1347 if (rr->rr_eadatalen > 0) {
1348 rr->rr_eadata = req_capsule_client_get(pill,
1350 if (rr->rr_eadata == NULL)
1353 rr->rr_eadata = NULL;
1355 } else if (!(attr->la_valid & OBD_MD_FLXATTRRM)) {
1356 CDEBUG(D_INFO, "no xattr data supplied\n");
1364 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
1366 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
1367 [REINT_SETATTR] = mdt_setattr_unpack,
1368 [REINT_CREATE] = mdt_create_unpack,
1369 [REINT_LINK] = mdt_link_unpack,
1370 [REINT_UNLINK] = mdt_unlink_unpack,
1371 [REINT_RENAME] = mdt_rename_unpack,
1372 [REINT_OPEN] = mdt_open_unpack,
1373 [REINT_SETXATTR] = mdt_setxattr_unpack
1376 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
1381 memset(&info->mti_rr, 0, sizeof(info->mti_rr));
1382 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
1383 info->mti_rr.rr_opcode = op;
1384 rc = mdt_reint_unpackers[op](info);
1386 CERROR("Unexpected opcode %d\n", op);