zfsonfreebsd / ZoF

ZFS on FreeBSD - the official out of tree OpenZFS implementation for FreeBSD
https://freebsd.org
Other
100 stars 8 forks source link

zfs project returns inappropriate ioctl for device #138

Open anodos325 opened 4 years ago

anodos325 commented 4 years ago

tn12test# zfs project -p 10 /mnt/dozer/SMB/testfile failed to get xattr for /mnt/dozer/SMB/testfile: Inappropriate ioctl for device

ghost commented 4 years ago

(projects/zfsbsd)

ghost commented 4 years ago

Label maybe wasn't entirely accurate,. This only applies to ZoF, it can't succeed on old ZFS.

mattmacy commented 4 years ago

We need to translate Linux extattr usage to FreeBSD

#ifdef FS_IOC_FSGETXATTR
typedef struct fsxattr zfsxattr_t;

#define ZFS_IOC_FSGETXATTR  FS_IOC_FSGETXATTR
#define ZFS_IOC_FSSETXATTR  FS_IOC_FSSETXATTR
#else
struct zfsxattr {
    uint32_t    fsx_xflags; /* xflags field value (get/set) */
    uint32_t    fsx_extsize;    /* extsize field value (get/set) */
    uint32_t    fsx_nextents;   /* nextents field value (get)   */
    uint32_t    fsx_projid; /* project identifier (get/set) */
    uint32_t    fsx_cowextsize;
    unsigned char   fsx_pad[8];
};
typedef struct zfsxattr zfsxattr_t;

#define ZFS_IOC_FSGETXATTR  _IOR('X', 31, zfsxattr_t)
#define ZFS_IOC_FSSETXATTR  _IOW('X', 32, zfsxattr_t)
#endif

static int
zfs_project_load_projid(const char *name, zfs_project_control_t *zpc)
{
    zfsxattr_t fsx;
    int ret, fd;

    fd = open(name, O_RDONLY | O_NOCTTY);
    if (fd < 0) {
        (void) fprintf(stderr, gettext("failed to open %s: %s\n"),
            name, strerror(errno));
        return (fd);
    }

    ret = ioctl(fd, ZFS_IOC_FSGETXATTR, &fsx);
    if (ret)
        (void) fprintf(stderr,
            gettext("failed to get xattr for %s: %s\n"),
            name, strerror(errno));
    else
        zpc->zpc_expected_projid = fsx.fsx_projid;

    close(fd);
    return (ret);
}
dspindler commented 3 years ago

I notice the exact same issue when applied to directories with symlinks on RedHat 8 zfs release 0.8.5. Unsure if this is part of this issue or a separate issue.

root@storage2]# zfs project -p 1 -rs /zpool39/projects/users/david failed to get xattr for /zpool39/projects/users/david/.cache: Inappropriate ioctl for device [root@storage2 ]# ls -l /zpool39/projects/users/david/.cache lrwxrwxrwx 1 root prj123 22 Nov 25 12:29 /zpool39/projects/users/david/.cache -> /home/geocache/davidscache

Thanks,

--D

ghost commented 3 years ago

@dspindler This issue is cause by FreeBSD not having projects or the fsxattr ioctl interface supported in the kernel. Your Linux kernel from RedHat 8 may also lack this feature for some reason, but it would be their issue not ours.