X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fmds%2Fmds_lib.c;h=83203dedac0e36438753efdcb1df7e3f289de756;hp=2fe77d26661b617bad035e0ba78a3549fa5e0d4a;hb=b0cd8cd9ffb2f067319d2069fe4652e987b59265;hpb=c79f7a9cdeeef1e421e47cc853482b247d8bd969 diff --git a/lustre/mds/mds_lib.c b/lustre/mds/mds_lib.c index 2fe77d2..83203de 100644 --- a/lustre/mds/mds_lib.c +++ b/lustre/mds/mds_lib.c @@ -3,25 +3,30 @@ * * Copyright (c) 2003 Cluster File Systems, Inc. * - * This file is part of Lustre, http://www.lustre.org. + * This file is part of the Lustre file system, http://www.lustre.org + * Lustre is a trademark of Cluster File Systems, Inc. * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * You may have signed or agreed to another license before downloading + * this software. If so, you are bound by the terms and conditions + * of that agreement, and the following does not apply to you. See the + * LICENSE file included with this distribution for more information. * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * If you did not agree to a different license, then this copy of Lustre + * is open source software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * In either case, Lustre is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * license text for more details. */ #define DEBUG_SUBSYSTEM S_MDS +#ifndef AUTOCONF_INCLUDED #include +#endif #include #include #include @@ -45,40 +50,19 @@ #include #include -#include -#include -#include - -#include -#include - -void mds_pack_dentry2fid(struct ll_fid *fid, struct dentry *dentry) -{ - fid->id = dentry->d_inum; - fid->generation = dentry->d_generation; - fid->mds = dentry->d_mdsnum; -} +#include +#include +#include "mds_internal.h" -void mds_pack_dentry2body(struct mds_body *b, struct dentry *dentry) -{ - b->valid |= OBD_MD_FLID | OBD_MD_FLGENER; - b->ino = dentry->d_inum; - b->generation = dentry->d_generation; - b->mds = dentry->d_mdsnum; -} - -void mds_pack_inode2fid(struct obd_device *obd, struct ll_fid *fid, - struct inode *inode) +void mds_pack_inode2fid(struct ll_fid *fid, struct inode *inode) { fid->id = inode->i_ino; fid->generation = inode->i_generation; fid->f_type = (S_IFMT & inode->i_mode); - fid->mds = obd->u.mds.mds_num; } /* Note that we can copy all of the fields, just some will not be "valid" */ -void mds_pack_inode2body(struct obd_device *obd, struct mds_body *b, - struct inode *inode) +void mds_pack_inode2body(struct mds_body *b, struct inode *inode) { b->valid |= OBD_MD_FLID | OBD_MD_FLCTIME | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLFLAGS | OBD_MD_FLTYPE | @@ -94,23 +78,16 @@ void mds_pack_inode2body(struct obd_device *obd, struct mds_body *b, b->mtime = LTIME_S(inode->i_mtime); b->ctime = LTIME_S(inode->i_ctime); b->mode = inode->i_mode; - b->size = inode->i_size; + b->size = i_size_read(inode); b->blocks = inode->i_blocks; b->uid = inode->i_uid; b->gid = inode->i_gid; - b->flags = inode->i_flags; + b->flags = ll_inode_to_ext_flags(b->flags, inode->i_flags); b->rdev = inode->i_rdev; /* Return the correct link count for orphan inodes */ - if (mds_inode_is_orphan(inode)) { - b->nlink = 0; - } else if (S_ISDIR(inode->i_mode)) { - b->nlink = 1; - } else { - b->nlink = inode->i_nlink; - } + b->nlink = mds_inode_is_orphan(inode) ? 0 : inode->i_nlink; b->generation = inode->i_generation; b->suppgid = -1; - b->mds = obd->u.mds.mds_num; } /* unpacking */ @@ -126,11 +103,13 @@ static int mds_setattr_unpack(struct ptlrpc_request *req, int offset, if (rec == NULL) RETURN (-EFAULT); - r->_ur_fsuid = rec->sa_fsuid; - r->_ur_fsgid = rec->sa_fsgid; - r->_ur_cap = rec->sa_cap; - r->_ur_suppgid1 = rec->sa_suppgid; - r->_ur_suppgid2 = -1; + r->ur_uc.luc_fsuid = rec->sa_fsuid; + r->ur_uc.luc_fsgid = rec->sa_fsgid; + r->ur_uc.luc_cap = rec->sa_cap; +#if 0 + r->ur_uc.luc_suppgid1 = rec->sa_suppgid; + r->ur_uc.luc_suppgid2 = -1; +#endif r->ur_fid1 = &rec->sa_fid; attr->ia_valid = rec->sa_valid; attr->ia_mode = rec->sa_mode; @@ -140,25 +119,28 @@ static int mds_setattr_unpack(struct ptlrpc_request *req, int offset, LTIME_S(attr->ia_atime) = rec->sa_atime; LTIME_S(attr->ia_mtime) = rec->sa_mtime; LTIME_S(attr->ia_ctime) = rec->sa_ctime; - attr->ia_attr_flags = rec->sa_attr_flags; + r->ur_flags = rec->sa_attr_flags; LASSERT_REQSWAB (req, offset + 1); - if (req->rq_reqmsg->bufcount > offset + 1) { - r->ur_eadata = lustre_msg_buf (req->rq_reqmsg, - offset + 1, 0); + r->ur_eadatalen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); + if (r->ur_eadatalen) { + r->ur_eadata = lustre_msg_buf(req->rq_reqmsg, offset + 1, 0); if (r->ur_eadata == NULL) - RETURN (-EFAULT); - r->ur_eadatalen = req->rq_reqmsg->buflens[offset + 1]; + RETURN(-EFAULT); } - - if (req->rq_reqmsg->bufcount > offset + 2) { + r->ur_cookielen = lustre_msg_buflen(req->rq_reqmsg, offset + 2); + if (r->ur_cookielen) { r->ur_logcookies = lustre_msg_buf(req->rq_reqmsg, offset + 2,0); if (r->ur_eadata == NULL) RETURN (-EFAULT); - - r->ur_cookielen = req->rq_reqmsg->buflens[offset + 2]; } - + if (lustre_msg_buflen(req->rq_reqmsg, offset + 3)) { + r->ur_dlm = lustre_swab_reqbuf(req, offset + 3, + sizeof(*r->ur_dlm), + lustre_swab_ldlm_request); + if (r->ur_dlm == NULL) + RETURN (-EFAULT); + } RETURN(0); } @@ -168,52 +150,51 @@ static int mds_create_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_create *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_create); + rec = lustre_swab_reqbuf(req, offset, sizeof (*rec), + lustre_swab_mds_rec_create); if (rec == NULL) RETURN (-EFAULT); - r->_ur_fsuid = rec->cr_fsuid; - r->_ur_fsgid = rec->cr_fsgid; - r->_ur_cap = rec->cr_cap; + r->ur_uc.luc_fsuid = rec->cr_fsuid; + r->ur_uc.luc_fsgid = rec->cr_fsgid; + r->ur_uc.luc_cap = rec->cr_cap; +#if 0 + r->ur_uc.luc_suppgid1 = rec->cr_suppgid; + r->ur_uc.luc_suppgid2 = -1; +#endif r->ur_fid1 = &rec->cr_fid; r->ur_fid2 = &rec->cr_replayfid; r->ur_mode = rec->cr_mode; r->ur_rdev = rec->cr_rdev; r->ur_time = rec->cr_time; r->ur_flags = rec->cr_flags; - r->_ur_suppgid1 = rec->cr_suppgid; - r->_ur_suppgid2 = -1; - LASSERT_REQSWAB (req, offset + 1); - r->ur_name = lustre_msg_string (req->rq_reqmsg, offset + 1, 0); + LASSERT_REQSWAB(req, offset + 1); + r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) RETURN (-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; - - LASSERT_REQSWAB (req, offset + 2); - if (req->rq_reqmsg->bufcount > offset + 2) { - if (S_ISLNK(r->ur_mode)) { - r->ur_tgt = lustre_msg_string(req->rq_reqmsg, - offset + 2, 0); - if (r->ur_tgt == NULL) - RETURN (-EFAULT); - r->ur_tgtlen = req->rq_reqmsg->buflens[offset + 2]; - } else if (S_ISDIR(r->ur_mode)) { - /* Stripe info for mkdir - just a 16bit integer */ - if (req->rq_reqmsg->buflens[offset + 2] != 2) { - CERROR("mkdir stripe info does not match " - "expected size %d vs 2\n", - req->rq_reqmsg->buflens[offset + 2]); - RETURN (-EINVAL); - } - r->ur_eadata = lustre_swab_buf (req->rq_reqmsg, - offset + 2, 2, __swab16s); - r->ur_eadatalen = req->rq_reqmsg->buflens[offset + 2]; - } else { - /* Hm, no other users so far? */ - LBUG(); - } + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); + + LASSERT_REQSWAB(req, offset + 2); + r->ur_tgtlen = lustre_msg_buflen(req->rq_reqmsg, offset + 2); + if (r->ur_tgtlen) { + /* NB for now, we only seem to pass NULL terminated symlink + * target strings here. If this ever changes, we'll have + * to stop checking for a buffer filled completely with a + * NULL terminated string here, and make the callers check + * depending on what they expect. We should probably stash + * it in r->ur_eadata in that case, so it's obvious... -eeb + */ + r->ur_tgt = lustre_msg_string(req->rq_reqmsg, offset + 2, 0); + if (r->ur_tgt == NULL) + RETURN (-EFAULT); + } + if (lustre_msg_buflen(req->rq_reqmsg, offset + 3)) { + r->ur_dlm = lustre_swab_reqbuf(req, offset + 3, + sizeof(*r->ur_dlm), + lustre_swab_ldlm_request); + if (r->ur_dlm == NULL) + RETURN (-EFAULT); } RETURN(0); } @@ -224,25 +205,34 @@ static int mds_link_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_link *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_link); + rec = lustre_swab_reqbuf(req, offset, sizeof (*rec), + lustre_swab_mds_rec_link); if (rec == NULL) RETURN (-EFAULT); - r->_ur_fsuid = rec->lk_fsuid; - r->_ur_fsgid = rec->lk_fsgid; - r->_ur_cap = rec->lk_cap; - r->_ur_suppgid1 = rec->lk_suppgid1; - r->_ur_suppgid2 = rec->lk_suppgid2; + r->ur_uc.luc_fsuid = rec->lk_fsuid; + r->ur_uc.luc_fsgid = rec->lk_fsgid; + r->ur_uc.luc_cap = rec->lk_cap; +#if 0 + r->ur_uc.luc_suppgid1 = rec->lk_suppgid1; + r->ur_uc.luc_suppgid2 = rec->lk_suppgid2; +#endif r->ur_fid1 = &rec->lk_fid1; r->ur_fid2 = &rec->lk_fid2; r->ur_time = rec->lk_time; - LASSERT_REQSWAB (req, offset + 1); - r->ur_name = lustre_msg_string (req->rq_reqmsg, offset + 1, 0); + LASSERT_REQSWAB(req, offset + 1); + r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) RETURN (-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); + if (lustre_msg_buflen(req->rq_reqmsg, offset + 2)) { + r->ur_dlm = lustre_swab_reqbuf(req, offset + 2, + sizeof(*r->ur_dlm), + lustre_swab_ldlm_request); + if (r->ur_dlm == NULL) + RETURN (-EFAULT); + } RETURN(0); } @@ -252,26 +242,36 @@ static int mds_unlink_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_unlink *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_unlink); + rec = lustre_swab_reqbuf(req, offset, sizeof (*rec), + lustre_swab_mds_rec_unlink); if (rec == NULL) RETURN(-EFAULT); - r->_ur_fsuid = rec->ul_fsuid; - r->_ur_fsgid = rec->ul_fsgid; - r->_ur_cap = rec->ul_cap; + r->ur_uc.luc_fsuid = rec->ul_fsuid; + r->ur_uc.luc_fsgid = rec->ul_fsgid; + r->ur_uc.luc_cap = rec->ul_cap; +#if 0 + r->ur_uc.luc_suppgid1 = rec->ul_suppgid; + r->ur_uc.luc_suppgid2 = -1; +#endif r->ur_mode = rec->ul_mode; - r->_ur_suppgid1 = rec->ul_suppgid; - r->_ur_suppgid2 = -1; r->ur_fid1 = &rec->ul_fid1; r->ur_fid2 = &rec->ul_fid2; r->ur_time = rec->ul_time; - LASSERT_REQSWAB (req, offset + 1); + LASSERT_REQSWAB(req, offset + 1); r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) RETURN(-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); + + if (lustre_msg_buflen(req->rq_reqmsg, offset + 2)) { + r->ur_dlm = lustre_swab_reqbuf(req, offset + 2, + sizeof(*r->ur_dlm), + lustre_swab_ldlm_request); + if (r->ur_dlm == NULL) + RETURN (-EFAULT); + } RETURN(0); } @@ -281,16 +281,18 @@ static int mds_rename_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_rename *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_unlink); + rec = lustre_swab_reqbuf(req, offset, sizeof (*rec), + lustre_swab_mds_rec_rename); if (rec == NULL) RETURN(-EFAULT); - r->_ur_fsuid = rec->rn_fsuid; - r->_ur_fsgid = rec->rn_fsgid; - r->_ur_cap = rec->rn_cap; - r->_ur_suppgid1 = rec->rn_suppgid1; - r->_ur_suppgid2 = rec->rn_suppgid2; + r->ur_uc.luc_fsuid = rec->rn_fsuid; + r->ur_uc.luc_fsgid = rec->rn_fsgid; + r->ur_uc.luc_cap = rec->rn_cap; +#if 0 + r->ur_uc.luc_suppgid1 = rec->rn_suppgid1; + r->ur_uc.luc_suppgid2 = rec->rn_suppgid2; +#endif r->ur_fid1 = &rec->rn_fid1; r->ur_fid2 = &rec->rn_fid2; r->ur_time = rec->rn_time; @@ -299,13 +301,20 @@ static int mds_rename_unpack(struct ptlrpc_request *req, int offset, r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) RETURN(-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); LASSERT_REQSWAB (req, offset + 2); r->ur_tgt = lustre_msg_string(req->rq_reqmsg, offset + 2, 0); if (r->ur_tgt == NULL) RETURN(-EFAULT); - r->ur_tgtlen = req->rq_reqmsg->buflens[offset + 2]; + r->ur_tgtlen = lustre_msg_buflen(req->rq_reqmsg, offset + 2); + if (lustre_msg_buflen(req->rq_reqmsg, offset + 3)) { + r->ur_dlm = lustre_swab_reqbuf(req, offset + 3, + sizeof(*r->ur_dlm), + lustre_swab_ldlm_request); + if (r->ur_dlm == NULL) + RETURN (-EFAULT); + } RETURN(0); } @@ -315,35 +324,37 @@ static int mds_open_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_create *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_create); + rec = lustre_swab_reqbuf(req, offset, sizeof(*rec), + lustre_swab_mds_rec_create); if (rec == NULL) - RETURN (-EFAULT); + RETURN(-EFAULT); - r->_ur_fsuid = rec->cr_fsuid; - r->_ur_fsgid = rec->cr_fsgid; - r->_ur_cap = rec->cr_cap; + r->ur_uc.luc_fsuid = rec->cr_fsuid; + r->ur_uc.luc_fsgid = rec->cr_fsgid; + r->ur_uc.luc_cap = rec->cr_cap; +#if 0 + r->ur_uc.luc_suppgid1 = rec->cr_suppgid; + r->ur_uc.luc_suppgid2 = -1; +#endif r->ur_fid1 = &rec->cr_fid; r->ur_fid2 = &rec->cr_replayfid; r->ur_mode = rec->cr_mode; r->ur_rdev = rec->cr_rdev; r->ur_time = rec->cr_time; r->ur_flags = rec->cr_flags; - r->_ur_suppgid1 = rec->cr_suppgid; - r->_ur_suppgid2 = -1; - LASSERT_REQSWAB (req, offset + 1); - r->ur_name = lustre_msg_string (req->rq_reqmsg, offset + 1, 0); + LASSERT_REQSWAB(req, offset + 1); + r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) - RETURN (-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + RETURN(-EFAULT); + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); - LASSERT_REQSWAB (req, offset + 2); - if (req->rq_reqmsg->bufcount > offset + 2) { + LASSERT_REQSWAB(req, offset + 2); + r->ur_eadatalen = lustre_msg_buflen(req->rq_reqmsg, offset + 2); + if (r->ur_eadatalen) { r->ur_eadata = lustre_msg_buf(req->rq_reqmsg, offset + 2, 0); if (r->ur_eadata == NULL) RETURN (-EFAULT); - r->ur_eadatalen = req->rq_reqmsg->buflens[offset + 2]; } RETURN(0); } @@ -351,7 +362,7 @@ static int mds_open_unpack(struct ptlrpc_request *req, int offset, typedef int (*update_unpacker)(struct ptlrpc_request *req, int offset, struct mds_update_record *r); -static update_unpacker mds_unpackers[REINT_MAX + 1] = { +static update_unpacker mds_unpackers[REINT_MAX] = { [REINT_SETATTR] mds_setattr_unpack, [REINT_CREATE] mds_create_unpack, [REINT_LINK] mds_link_unpack, @@ -363,29 +374,80 @@ static update_unpacker mds_unpackers[REINT_MAX + 1] = { int mds_update_unpack(struct ptlrpc_request *req, int offset, struct mds_update_record *rec) { - __u32 *opcodep; - __u32 opcode; + mds_reint_t opcode, *opcodep; int rc; ENTRY; /* NB don't lustre_swab_reqbuf() here. We're just taking a peek * and we want to leave it to the specific unpacker once we've * identified the message type */ - opcodep = lustre_msg_buf (req->rq_reqmsg, offset, sizeof (*opcodep)); + opcodep = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*opcodep)); if (opcodep == NULL) RETURN(-EFAULT); opcode = *opcodep; - if (lustre_msg_swabbed (req->rq_reqmsg)) - __swab32s (&opcode); + if (lustre_msg_swabbed(req->rq_reqmsg)) + __swab32s(&opcode); - if (opcode > REINT_MAX || - mds_unpackers[opcode] == NULL) { - CERROR ("Unexpected opcode %d\n", opcode); + if (opcode >= REINT_MAX || mds_unpackers[opcode] == NULL) { + CERROR("Unexpected opcode %d\n", opcode); RETURN(-EFAULT); } rec->ur_opcode = opcode; rc = mds_unpackers[opcode](req, offset, rec); + RETURN(rc); } + +int mds_init_ucred(struct lvfs_ucred *ucred, struct ptlrpc_request *req, + int offset) +{ + struct mds_body *body = lustre_msg_buf(req->rq_reqmsg, offset, + sizeof(*body)); +#if 0 + struct mds_obd *mds = mds_req2mds(req); + int rc; +#endif + + LASSERT(body != NULL); /* previously verified & swabbed by caller */ + +#ifdef CRAY_XT3 + if (req->rq_uid != LNET_UID_ANY) { + /* Non-root local cluster client */ + LASSERT (req->rq_uid != 0); + ucred->luc_fsuid = req->rq_uid; + } else +#endif + { + ucred->luc_fsuid = body->fsuid; + ucred->luc_fsgid = body->fsgid; + ucred->luc_cap = body->capability; + } + +#if 0 + ucred->luc_uce = upcall_cache_get_entry(mds->mds_group_hash, + ucred->luc_fsuid, + ucred->luc_fsgid, 1, + &body->suppgid); + if (IS_ERR(ucred->luc_uce)) { + rc = PTR_ERR(ucred->luc_uce); + ucred->luc_uce = NULL; + return rc; + } + +#ifdef CRAY_XT3 + if (ucred->luc_uce) + ucred->luc_fsgid = ucred->luc_uce->ue_primary; +#endif +#endif + + return 0; +} + +void mds_exit_ucred(struct lvfs_ucred *ucred, struct mds_obd *mds) +{ +#if 0 + upcall_cache_put_entry(mds->mds_group_hash, ucred->luc_uce); +#endif +}