Whamcloud - gitweb
LU-5150 acl: 'cp -rp' set empty default ACL
[fs/lustre-release.git] / lustre / osd-zfs / osd_xattr.c
index 463ea28..f66f986 100644 (file)
@@ -28,7 +28,7 @@
  * Use is subject to license terms.
  */
 /*
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  * Use is subject to license terms.
  */
 /*
  * Author: Mike Pershin <tappro@whamcloud.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_OSD
 
 #include <lustre_ver.h>
 #include <libcfs/libcfs.h>
-#include <lustre_fsfilt.h>
 #include <obd_support.h>
 #include <lustre_net.h>
 #include <obd.h>
@@ -72,6 +68,7 @@
 #include <sys/sa_impl.h>
 #include <sys/txg.h>
 
+#include <linux/posix_acl_xattr.h>
 
 /*
  * Copy an extended attribute into the buffer provided, or compute the
@@ -249,6 +246,11 @@ int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
        LASSERT(osd_invariant(obj));
        LASSERT(dt_object_exists(dt));
 
+       if (!osd_obj2dev(obj)->od_posix_acl &&
+           (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+            strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
+               RETURN(-EOPNOTSUPP);
+
        down(&obj->oo_guard);
        rc = __osd_xattr_get(env, obj, buf, name, &size);
        up(&obj->oo_guard);
@@ -441,6 +443,20 @@ int __osd_sa_xattr_set(const struct lu_env *env, struct osd_object *obj,
                return rc;
        }
 
+       /* Ensure xattr doesn't exist in ZAP */
+       if (obj->oo_xattr != ZFS_NO_OBJECT) {
+               udmu_objset_t     *uos = &osd_obj2dev(obj)->od_objset;
+               uint64_t           xa_data_obj;
+               rc = -zap_lookup(uos->os, obj->oo_xattr,
+                                name, 8, 1, &xa_data_obj);
+               if (rc == 0) {
+                       rc = __osd_object_free(uos, xa_data_obj, oh->ot_tx);
+                       if (rc == 0)
+                               zap_remove(uos->os, obj->oo_xattr,
+                                          name, oh->ot_tx);
+               }
+       }
+
        rc = -nvlist_add_byte_array(obj->oo_sa_xattr, name,
                                    (uchar_t *)buf->lb_buf, buf->lb_len);
        if (rc)
@@ -579,6 +595,11 @@ int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
        LASSERT(dt_object_exists(dt));
        LASSERT(obj->oo_db);
 
+       if (!osd_obj2dev(obj)->od_posix_acl &&
+           (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+            strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
+               RETURN(-EOPNOTSUPP);
+
        oh = container_of0(handle, struct osd_thandle, ot_super);
 
        down(&obj->oo_guard);
@@ -717,6 +738,11 @@ int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
        oh = container_of0(handle, struct osd_thandle, ot_super);
        LASSERT(oh->ot_tx != NULL);
 
+       if (!osd_obj2dev(obj)->od_posix_acl &&
+           (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+            strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
+               RETURN(-EOPNOTSUPP);
+
        down(&obj->oo_guard);
        rc = __osd_xattr_del(env, obj, name, oh);
        up(&obj->oo_guard);
@@ -741,12 +767,19 @@ osd_sa_xattr_list(const struct lu_env *env, struct osd_object *obj,
        LASSERT(obj->oo_sa_xattr);
 
        while ((nvp = nvlist_next_nvpair(obj->oo_sa_xattr, nvp)) != NULL) {
+               const char *name = nvpair_name(nvp);
+
+               if (!osd_obj2dev(obj)->od_posix_acl &&
+                   (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0 ||
+                    strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0))
+                       continue;
+
                len = strlen(nvpair_name(nvp));
                if (lb->lb_buf != NULL) {
                        if (len + 1 > remain)
                                return -ERANGE;
 
-                       memcpy(lb->lb_buf, nvpair_name(nvp), len);
+                       memcpy(lb->lb_buf, name, len);
                        lb->lb_buf += len;
                        *((char *)lb->lb_buf) = '\0';
                        lb->lb_buf++;
@@ -790,6 +823,13 @@ int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
 
        while ((rc = -udmu_zap_cursor_retrieve_key(env, zc, oti->oti_key,
                                                MAXNAMELEN)) == 0) {
+               if (!osd_obj2dev(obj)->od_posix_acl &&
+                   (strcmp(oti->oti_key, POSIX_ACL_XATTR_ACCESS) == 0 ||
+                    strcmp(oti->oti_key, POSIX_ACL_XATTR_DEFAULT) == 0)) {
+                       zap_cursor_advance(zc);
+                       continue;
+               }
+
                rc = strlen(oti->oti_key);
                if (lb->lb_buf != NULL) {
                        if (rc + 1 > remain)