mirror_zfs/module/os/freebsd/zfs
Ryan Moeller 5c0061345b
Cross-platform xattr user namespace compatibility
ZFS on Linux originally implemented xattr namespaces in a way that is
incompatible with other operating systems.  On illumos, xattrs do not
have namespaces.  Every xattr name is visible.  FreeBSD has two
universally defined namespaces: EXTATTR_NAMESPACE_USER and
EXTATTR_NAMESPACE_SYSTEM.  The system namespace is used for protected
FreeBSD-specific attributes such as MAC labels and pnfs state.  These
attributes have the namespace string "freebsd:system:" prefixed to the
name in the encoding scheme used by ZFS.  The user namespace is used
for general purpose user attributes and obeys normal access control
mechanisms.  These attributes have no namespace string prefixed, so
xattrs written on illumos are accessible in the user namespace on
FreeBSD, and xattrs written to the user namespace on FreeBSD are
accessible by the same name on illumos.

Linux has several xattr namespaces.  On Linux, ZFS encodes the
namespace in the xattr name for every namespace, including the user
namespace.  As a consequence, an xattr in the user namespace with the
name "foo" is stored by ZFS with the name "user.foo" and therefore
appears on FreeBSD and illumos to have the name "user.foo" rather than
"foo".  Conversely, none of the xattrs written on FreeBSD or illumos
are accessible on Linux unless the name happens to be prefixed with one
of the Linux xattr namespaces, in which case the namespace is stripped
from the name.  This makes xattrs entirely incompatible between Linux
and other platforms.

We want to make the encoding of user namespace xattrs compatible across
platforms.  A critical requirement of this compatibility is for xattrs
from existing pools from FreeBSD and illumos to be accessible by the
same names in the user namespace on Linux.  It is also necessary that
existing pools with xattrs written by Linux retain access to those
xattrs by the same names on Linux.  Making user namespace xattrs from
Linux accessible by the correct names on other platforms is important.
The handling of other namespaces is not required to be consistent.

Add a fallback mechanism for listing and getting xattrs to treat xattrs
as being in the user namespace if they do not match a known prefix.

Do not allow setting or getting xattrs with a name that is prefixed
with one of the namespace names used by ZFS on supported platforms.

Allow choosing between legacy illumos and FreeBSD compatibility and
legacy Linux compatibility with a new tunable.  This facilitates
replication and migration of pools between hosts with different
compatibility needs.

The tunable controls whether or not to prefix the namespace to the
name.  If the xattr is already present with the alternate prefix,
remove it so only the new version persists.  By default the platform's
existing convention is used.

Reviewed-by: Christian Schwarz <christian.schwarz@nutanix.com>
Reviewed-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #11919
2022-02-15 16:35:30 -08:00
..
abd_os.c module/*.ko: prune .data, global .rodata 2022-01-14 15:37:55 -08:00
arc_os.c Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
crypto_os.c module: icp: fold away all key formats except CRYPTO_KEY_RAW 2022-02-15 16:25:07 -08:00
dmu_os.c Remove FreeBSD's local copy of the dmu_buf_hold_array() function 2021-10-13 11:01:01 -07:00
hkdf.c module: icp: fold away all key formats except CRYPTO_KEY_RAW 2022-02-15 16:25:07 -08:00
kmod_core.c zfs: add missed dependency of zfs module on zlib 2021-08-13 13:42:45 -07:00
spa_os.c Add spa _os() hooks 2022-02-15 15:54:25 -08:00
sysctl_os.c Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
vdev_file.c module/*.ko: prune .data, global .rodata 2022-01-14 15:37:55 -08:00
vdev_geom.c Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
vdev_label_os.c FreeBSD: Clean up ASSERT/VERIFY use in module 2021-04-30 16:36:10 -07:00
zfs_acl.c Rename fallthrough to zfs_fallthrough 2022-02-15 08:58:59 -08:00
zfs_ctldir.c Replace *CTASSERT() with _Static_assert() 2022-01-26 11:38:52 -08:00
zfs_debug.c Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
zfs_dir.c Clean up use of zfs_log_create in zfs_dir 2021-05-07 15:13:10 -07:00
zfs_file_os.c FreeBSD: Catch up with recent VFS changes 2021-10-25 09:46:28 -07:00
zfs_ioctl_compat.c FreeBSD: Fix legacy compat for platform IOCs 2020-09-30 13:25:50 -07:00
zfs_ioctl_os.c libzfs: On FreeBSD, use MNT_NOWAIT with getfsstat 2021-06-08 07:36:43 -06:00
zfs_racct.c module: zfs: fix unused, remove argsused 2021-12-23 09:42:47 -08:00
zfs_vfsops.c Replace *CTASSERT() with _Static_assert() 2022-01-26 11:38:52 -08:00
zfs_vnops_os.c Cross-platform xattr user namespace compatibility 2022-02-15 16:35:30 -08:00
zfs_znode.c FreeBSD: remove unused variable 2022-01-06 12:46:49 -08:00
zio_crypt.c module: icp: fold away all key formats except CRYPTO_KEY_RAW 2022-02-15 16:25:07 -08:00
zvol_os.c zvol: make calls to platform ops static 2022-02-07 10:24:38 -08:00