Whamcloud - gitweb
LU-2267 osd-zfs: Use appropriate ZFS flags for file attributes
authorNathaniel Clark <nathaniel.l.clark@intel.com>
Tue, 9 Apr 2013 12:40:42 +0000 (08:40 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 11 Apr 2013 20:46:37 +0000 (16:46 -0400)
Instead of setting arbitrary bits in pflags, convert to use existing
ZFS attributes.  This format is different from previous implementation
and will cause older filesystems with attrs set to not behave
correctly.

Signed-off-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Change-Id: Ia0aac3e12adedd95b215f93ebe538a61abf910fa
Reviewed-on: http://review.whamcloud.com/5988
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
lustre/osd-zfs/osd_internal.h
lustre/osd-zfs/osd_object.c

index 9fee6d5..43cca11 100644 (file)
@@ -52,6 +52,7 @@
 
 #include <sys/nvpair.h>
 
+#include <sys/zfs_znode.h>
 #include "udmu.h"
 
 #define LUSTRE_ROOT_FID_SEQ    0
@@ -476,5 +477,19 @@ osd_xattr_set_internal(const struct lu_env *env, struct osd_object *obj,
        return rc;
 }
 
+static inline uint64_t attrs_fs2zfs(const uint32_t flags)
+{
+       return (((flags & FS_APPEND_FL)         ? ZFS_APPENDONLY        : 0) |
+               ((flags & FS_NODUMP_FL)         ? ZFS_NODUMP            : 0) |
+               ((flags & FS_IMMUTABLE_FL)      ? ZFS_IMMUTABLE         : 0));
+}
+
+static inline uint32_t attrs_zfs2fs(const uint64_t flags)
+{
+       return (((flags & ZFS_APPENDONLY)       ? FS_APPEND_FL          : 0) |
+               ((flags & ZFS_NODUMP)           ? FS_NODUMP_FL          : 0) |
+               ((flags & ZFS_IMMUTABLE)        ? FS_IMMUTABLE_FL       : 0));
+}
+
 #endif
 #endif /* _OSD_INTERNAL_H */
index 1265475..97f954d 100644 (file)
@@ -234,7 +234,7 @@ int __osd_object_attr_get(const struct lu_env *env, udmu_objset_t *uos,
        la->la_uid = osa->uid;
        la->la_gid = osa->gid;
        la->la_nlink = osa->nlink;
-       la->la_flags = osa->flags;
+       la->la_flags = attrs_zfs2fs(osa->flags);
        la->la_size = osa->size;
 
        if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode)) {
@@ -988,7 +988,10 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                                 &osa->rdev, 8);
        }
        if (la->la_valid & LA_FLAGS) {
-               osa->flags = obj->oo_attr.la_flags = la->la_flags;
+               osa->flags = attrs_fs2zfs(la->la_flags);
+               /* many flags are not supported by zfs, so ensure a good cached
+                * copy */
+               obj->oo_attr.la_flags = attrs_zfs2fs(osa->flags);
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(uos), NULL,
                                 &osa->flags, 8);
        }
@@ -1125,7 +1128,7 @@ int __osd_attr_init(const struct lu_env *env, udmu_objset_t *uos, uint64_t oid,
        osa->gid = la->la_gid;
        osa->rdev = la->la_rdev;
        osa->nlink = la->la_nlink;
-       osa->flags = la->la_flags;
+       osa->flags = attrs_fs2zfs(la->la_flags);
        osa->size  = la->la_size;
 
        /* Now add in all of the "SA" attributes */