X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdd%2Fmdd_permission.c;h=cd758613b1c9788f32fee1488e716b64ac4c09d4;hb=e2af7fb3c91dfb13d34d8e1b2f2df8c09621f768;hp=1dad3ebbb07be2d4ed7d784bd735855b6bfb4580;hpb=3192e52a89946f12fd36d28a686c169d01d36e64;p=fs%2Flustre-release.git diff --git a/lustre/mdd/mdd_permission.c b/lustre/mdd/mdd_permission.c index 1dad3eb..cd75861 100644 --- a/lustre/mdd/mdd_permission.c +++ b/lustre/mdd/mdd_permission.c @@ -1,44 +1,63 @@ -/* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * mdd/mdd_handler.c - * Lustre Metadata Server (mdd) routines + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. * - * Copyright (C) 2006 Cluster File Systems, Inc. - * Author: fangyong@clusterfs.com - * lsy@clusterfs.com - * This file is part of the Lustre file system, http://www.lustre.org - * Lustre is a trademark of Cluster File Systems, Inc. + * This program 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 version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). * - * 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. + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * - * 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. + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. * - * 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. + * GPL HEADER END */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif +/* + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * lustre/mdd/mdd_permission.c + * + * Lustre Metadata Server (mdd) routines + * + * Author: fangyong@clusterfs.com + * Author: lsy@clusterfs.com + */ + #define DEBUG_SUBSYSTEM S_MDS #include +#ifdef HAVE_EXT4_LDISKFS +#include +#else #include +#endif #include #include #include #include #include +#ifdef HAVE_EXT4_LDISKFS +#include +#else #include +#endif #include #include @@ -50,7 +69,7 @@ * Get default acl EA only. * Hold read_lock for mdd_obj. */ -int mdd_acl_def_get(const struct lu_env *env, struct mdd_object *mdd_obj, +int mdd_def_acl_get(const struct lu_env *env, struct mdd_object *mdd_obj, struct md_attr *ma) { struct lu_buf *buf; @@ -59,7 +78,7 @@ int mdd_acl_def_get(const struct lu_env *env, struct mdd_object *mdd_obj, if (ma->ma_valid & MA_ACL_DEF) RETURN(0); - + buf = mdd_buf_get(env, ma->ma_acl, ma->ma_acl_size); rc = mdo_xattr_get(env, mdd_obj, buf, XATTR_NAME_ACL_DEFAULT, BYPASS_CAPA); @@ -76,7 +95,7 @@ int mdd_acl_def_get(const struct lu_env *env, struct mdd_object *mdd_obj, /* * Hold write_lock for o. */ -int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode, +int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode, struct thandle *handle) { struct lu_buf *buf; @@ -87,9 +106,9 @@ int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode, ENTRY; - buf = mdd_buf_get(env, mdd_env_info(env)->mti_xattr_buf, + buf = mdd_buf_get(env, mdd_env_info(env)->mti_xattr_buf, sizeof(mdd_env_info(env)->mti_xattr_buf)); - + rc = mdo_xattr_get(env, o, buf, XATTR_NAME_ACL_ACCESS, BYPASS_CAPA); if ((rc == -EOPNOTSUPP) || (rc == -ENODATA)) RETURN(0); @@ -103,7 +122,7 @@ int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode, sizeof(posix_acl_xattr_entry); if (entry_count <= 0) RETURN(0); - + rc = lustre_posix_acl_chmod_masq(entry, mode, entry_count); if (rc) RETURN(rc); @@ -132,13 +151,13 @@ int __mdd_acl_init(const struct lu_env *env, struct mdd_object *obj, sizeof(posix_acl_xattr_entry); if (entry_count <= 0) RETURN(0); - - if (S_ISDIR(*mode)) { - rc = mdo_xattr_set(env, obj, buf, XATTR_NAME_ACL_DEFAULT, 0, + + if (S_ISDIR(*mode)) { + rc = mdo_xattr_set(env, obj, buf, XATTR_NAME_ACL_DEFAULT, 0, handle, BYPASS_CAPA); if (rc) RETURN(rc); - } + } rc = lustre_posix_acl_create_masq(entry, mode, entry_count); if (rc <= 0) @@ -148,33 +167,6 @@ int __mdd_acl_init(const struct lu_env *env, struct mdd_object *obj, BYPASS_CAPA); RETURN(rc); } - -/* - * Hold read_lock for pobj. - * Hold write_lock for cobj. - */ -int mdd_acl_init(const struct lu_env *env, struct mdd_object *pobj, - struct mdd_object *cobj, __u32 *mode, struct thandle *handle) -{ - struct lu_buf *buf; - int rc; - ENTRY; - - if (S_ISLNK(*mode)) - RETURN(0); - - buf = mdd_buf_get(env, mdd_env_info(env)->mti_xattr_buf, - sizeof(mdd_env_info(env)->mti_xattr_buf)); - rc = mdo_xattr_get(env, pobj, buf, XATTR_NAME_ACL_DEFAULT, BYPASS_CAPA); - if ((rc == -EOPNOTSUPP) || (rc == -ENODATA)) - RETURN(0); - else if (rc <= 0) - RETURN(rc); - - buf->lb_len = rc; - rc = __mdd_acl_init(env, cobj, buf, mode, handle); - RETURN(rc); -} #endif /* @@ -192,7 +184,7 @@ static int mdd_check_acl(const struct lu_env *env, struct mdd_object *obj, int rc; ENTRY; - buf = mdd_buf_get(env, mdd_env_info(env)->mti_xattr_buf, + buf = mdd_buf_get(env, mdd_env_info(env)->mti_xattr_buf, sizeof(mdd_env_info(env)->mti_xattr_buf)); rc = mdo_xattr_get(env, obj, buf, XATTR_NAME_ACL_ACCESS, mdd_object_capa(env, obj)); @@ -214,7 +206,7 @@ static int mdd_check_acl(const struct lu_env *env, struct mdd_object *obj, } int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj, - struct lu_attr *la, int mask, int needlock) + struct lu_attr *la, int mask, int role) { struct md_ucred *uc = md_ucred(env); __u32 mode; @@ -250,10 +242,10 @@ int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj, mode >>= 6; } else { if (mode & S_IRWXG) { - if (needlock) - mdd_read_lock(env, obj); + if (role != -1) + mdd_read_lock(env, obj, role); rc = mdd_check_acl(env, obj, la, mask); - if (needlock) + if (role != -1) mdd_read_unlock(env, obj); if (rc == -EACCES) goto check_capabilities; @@ -271,18 +263,18 @@ int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj, check_capabilities: if (!(mask & MAY_EXEC) || (la->la_mode & S_IXUGO) || S_ISDIR(la->la_mode)) - if (mdd_capable(uc, CAP_DAC_OVERRIDE)) + if (mdd_capable(uc, CFS_CAP_DAC_OVERRIDE)) RETURN(0); if ((mask == MAY_READ) || (S_ISDIR(la->la_mode) && !(mask & MAY_WRITE))) - if (mdd_capable(uc, CAP_DAC_READ_SEARCH)) + if (mdd_capable(uc, CFS_CAP_DAC_READ_SEARCH)) RETURN(0); RETURN(-EACCES); } -int mdd_permission(const struct lu_env *env, +int mdd_permission(const struct lu_env *env, struct md_object *pobj, struct md_object *cobj, struct md_attr *ma, int mask) { @@ -327,7 +319,8 @@ int mdd_permission(const struct lu_env *env, MAY_VTX_PART | MAY_VTX_FULL | MAY_RGETFACL); - rc = mdd_permission_internal_locked(env, mdd_cobj, NULL, mask); + rc = mdd_permission_internal_locked(env, mdd_cobj, NULL, mask, + MOR_TGT_CHILD); if (!rc && (check_create || check_link)) rc = mdd_may_create(env, mdd_cobj, NULL, 1, check_link); @@ -377,7 +370,8 @@ int mdd_permission(const struct lu_env *env, RETURN(rc); } - if (la->la_uid != uc->mu_fsuid && !mdd_capable(uc, CAP_FOWNER)) + if (la->la_uid != uc->mu_fsuid && + !mdd_capable(uc, CFS_CAP_FOWNER)) rc = -EPERM; } @@ -396,7 +390,7 @@ int mdd_capa_get(const struct lu_env *env, struct md_object *obj, capa->lc_opc); if (IS_ERR(oc)) { rc = PTR_ERR(oc); - } else { + } else if (likely(oc != NULL)) { capa_cpy(capa, oc); capa_put(oc); }