From: Darrick J. Wong <djwong@xxxxxxxxxx> XXX see the comment for why we have to do this bellicosely stupid thing. Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx> --- misc/fuse2fs.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index 82b59c1ac89774..e281b5fc589d82 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -261,6 +261,7 @@ struct fuse2fs { uint8_t dirsync; uint8_t unmount_in_destroy; uint8_t noblkdev; + uint8_t can_hardlink; enum fuse2fs_opstate opstate; int blocklog; @@ -1382,9 +1383,31 @@ static void *op_init(struct fuse_conn_info *conn /* * If we're mounting in iomap mode, we need to unmount in op_destroy * so that the block device will be released before umount(2) returns. + * + * XXX: It turns out that fuse2fs creates internal node ids that have + * nothing to do with the ext2_ino_t that we give it. These internal + * node ids are what actually gets igetted in the kernel, which means + * that there can be multiple fuse_inode objects for the same fuse2fs + * inode. + * + * What this means, horrifyingly, is that on a fuse filesystem that + * supports hard links, the in-kernel i_rwsem does not protect against + * concurrent writes between files that point to the same inode. That + * in turn means that the file mode and size can get desynchronized + * between the multiple fuse_inode objects. This also means that we + * cannot cache iomaps in the kernel AT ALL because the caches will + * get out of sync, leading to WARN_ONs from the iomap zeroing code and + * probably data corruption after that. + * + * So for now we just disable hardlinking on iomap to see if the weird + * fstests failures (particularly g/476) go away. Long term it means + * we probably have to find a way around this, like porting fuse2fs + * to be a low level fuse driver. */ - if (fuse2fs_iomap_enabled(ff)) + if (fuse2fs_iomap_enabled(ff)) { ff->unmount_in_destroy = 1; + ff->can_hardlink = 0; + } /* Clear the valid flag so that an unclean shutdown forces a fsck */ if (ff->opstate == F2OP_WRITABLE) { @@ -2751,6 +2774,10 @@ static int op_link(const char *src, const char *dest) int ret = 0; FUSE2FS_CHECK_CONTEXT(ff); + + if (!ff->can_hardlink) + return -ENOSYS; + dbg_printf(ff, "%s: src=%s dest=%s\n", __func__, src, dest); temp_path = strdup(dest); if (!temp_path) { @@ -6380,6 +6407,7 @@ int main(int argc, char *argv[]) .iomap_state = IOMAP_UNKNOWN, .iomap_dev = FUSE_IOMAP_DEV_NULL, #endif + .can_hardlink = 1, }; errcode_t err; FILE *orig_stderr = stderr;