Whamcloud - gitweb
LU-12355 llite: include file linux/selinux.h removed
[fs/lustre-release.git] / lustre / llite / xattr.c
index 97f9725..b8500df 100644 (file)
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/xattr.h>
+#ifdef HAVE_LINUX_SELINUX_IS_ENABLED
 #include <linux/selinux.h>
+#endif
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
 #include <obd_support.h>
 #include <lustre_dlm.h>
 #include <lustre_eacl.h>
+#include <lustre_swab.h>
 
 #include "llite_internal.h"
 
@@ -51,6 +54,17 @@ static inline const char *xattr_prefix(const struct xattr_handler *handler)
 }
 #endif
 
+#ifdef HAVE_LINUX_SELINUX_IS_ENABLED
+# define test_xattr_is_selinux_disabled(handler, name) \
+               ((handler)->flags == XATTR_SECURITY_T && \
+               !selinux_is_enabled() && \
+               strcmp((name), "selinux") == 0)
+#else
+# define test_xattr_is_selinux_disabled(handler, name) \
+               ((handler)->flags == XATTR_SECURITY_T && \
+               strcmp((name), "selinux") == 0)
+#endif
+
 const struct xattr_handler *get_xattr_type(const char *name)
 {
        int i;
@@ -124,11 +138,7 @@ static int ll_xattr_set_common(const struct xattr_handler *handler,
 
        if ((handler->flags == XATTR_ACL_ACCESS_T ||
             handler->flags == XATTR_ACL_DEFAULT_T) &&
-#ifdef HAVE_INODE_OWNER_OR_CAPABLE
            !inode_owner_or_capable(inode))
-#else
-           !is_owner_or_cap(inode))
-#endif
                RETURN(-EPERM);
 
        /* b10667: ignore lustre special xattr for now */
@@ -138,8 +148,7 @@ static int ll_xattr_set_common(const struct xattr_handler *handler,
                RETURN(0);
 
        /* LU-549:  Disable security.selinux when selinux is disabled */
-       if (handler->flags == XATTR_SECURITY_T && !selinux_is_enabled() &&
-           strcmp(name, "selinux") == 0)
+       if (test_xattr_is_selinux_disabled(handler, name))
                RETURN(-EOPNOTSUPP);
 
        /*
@@ -333,6 +342,11 @@ static int ll_xattr_set(const struct xattr_handler *handler,
                return 0;
        }
 
+       if (strncmp(name, "lov.", 4) == 0 &&
+           (__swab32(((struct lov_user_md *)value)->lmm_magic) &
+           le32_to_cpu(LOV_MAGIC_MASK)) == le32_to_cpu(LOV_MAGIC_MAGIC))
+               lustre_swab_lov_user_md((struct lov_user_md *)value);
+
        return ll_xattr_set_common(handler, dentry, inode, name, value, size,
                                   flags);
 }
@@ -395,8 +409,8 @@ getxattr_nocache:
 out_xattr:
        if (rc == -EOPNOTSUPP && type == XATTR_USER_T) {
                LCONSOLE_INFO("%s: disabling user_xattr feature because "
-                               "it is not supported on the server: rc = %d\n",
-                               ll_get_fsname(inode->i_sb, NULL, 0), rc);
+                             "it is not supported on the server: rc = %d\n",
+                             sbi->ll_fsname, rc);
                sbi->ll_flags &= ~LL_SBI_USER_XATTR;
        }
 out:
@@ -422,8 +436,7 @@ static int ll_xattr_get_common(const struct xattr_handler *handler,
                RETURN(rc);
 
        /* LU-549:  Disable security.selinux when selinux is disabled */
-       if (handler->flags == XATTR_SECURITY_T && !selinux_is_enabled() &&
-           !strcmp(name, "selinux"))
+       if (test_xattr_is_selinux_disabled(handler, name))
                RETURN(-EOPNOTSUPP);
 
 #ifdef CONFIG_FS_POSIX_ACL
@@ -472,6 +485,7 @@ static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size)
                };
                struct lu_env *env;
                u16 refcheck;
+               u32 magic;
 
                if (!obj)
                        RETURN(-ENODATA);
@@ -500,10 +514,25 @@ static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size)
                 * recognizing layout gen as stripe offset when the
                 * file is restored. See LU-2809.
                 */
-               if (((struct lov_mds_md *)buf)->lmm_magic == LOV_MAGIC_COMP_V1)
+               magic = ((struct lov_mds_md *)buf)->lmm_magic;
+               if ((magic & __swab32(LOV_MAGIC_MAGIC)) ==
+                   __swab32(LOV_MAGIC_MAGIC))
+                       magic = __swab32(magic);
+
+               switch (magic) {
+               case LOV_MAGIC_V1:
+               case LOV_MAGIC_V3:
+               case LOV_MAGIC_SPECIFIC:
+                       ((struct lov_mds_md *)buf)->lmm_layout_gen = 0;
+                       break;
+               case LOV_MAGIC_COMP_V1:
+               case LOV_MAGIC_FOREIGN:
                        goto out_env;
+               default:
+                       CERROR("Invalid LOV magic %08x\n", magic);
+                       GOTO(out_env, rc = -EINVAL);
+               }
 
-               ((struct lov_mds_md *)buf)->lmm_layout_gen = 0;
 out_env:
                cl_env_put(env, &refcheck);