Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: -current tar(1) breakage



This might, or might not, be related. There is another bug in
tar. It hangs when reading files on FUSE-mounted filesystems:

$ sudo fuse-ext2 -o ro -o direct -o uid=$(id -u) -o gid=$(id -g) /dev/dk5 /mnt
$ tar -C /mnt/work -cvf /dev/null .
a .
a ./dmesg.txt^C		<-- HANGS HERE
$

However, this works:
$ tar -cvf /dev/null /mnt/work
tar: Removing leading '/' from member names
a mnt/work
a mnt/work/dmesg.txt
a mnt/work/alc.txt
...
$

This bug is caused by {,f}statvfs() in setup_current_filesystem()
returning 0 sizes on FUSE-mounted FSes; and then setup_suitable_read_buffer()
only doing a if (var < 0) check in various places.

$ cat fssize.c
#include <sys/types.h>
#include <sys/statvfs.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char* argv[])
{
        struct statvfs sfs;
        char* file;
        int rc = EXIT_FAILURE;

        if (argc != 2)
                errx(rc, "no args. given");
        file = argv[1];
        if (statvfs(file, &sfs) == -1)
                err(rc, "%s: statvfs failed", file);

#define PR(v) printf("%s: %ld\n", #v, v)

        PR(sfs.f_frsize);
        PR(sfs.f_iosize);
        PR(sfs.f_bsize);

        return 0;
}
$ cc -Wall fssize.c
$ ./a.out /mnt/work/dmesg.txt
sfs.f_frsize: 0
sfs.f_iosize: 0
sfs.f_bsize: 0
$

Run the code on your NFS-mounted FS and check what FS sizes are
reported. If they are all 0, then it is the same bug (probably).

The patch below fixes my issue for me (on NetBSD--similar changes
may be needed on other OSes supported by libarchive)

---START PATCH---
diff -urN a/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c b/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c
--- a/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c	2019-07-24 13:50:23.000000000 +0000
+++ b/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c	2021-03-28 06:35:01.828041075 +0000
@@ -1690,14 +1690,14 @@
 	} else if (xr == 1) {
 		/* Usually come here unless NetBSD supports _PC_REC_XFER_ALIGN
 		 * for pathconf() function. */
-		t->current_filesystem->xfer_align = sfs.f_frsize;
+		t->current_filesystem->xfer_align = (sfs.f_frsize == 0) ? -1 : (long)sfs.f_frsize;
 		t->current_filesystem->max_xfer_size = -1;
 #if defined(HAVE_STRUCT_STATVFS_F_IOSIZE)
-		t->current_filesystem->min_xfer_size = sfs.f_iosize;
-		t->current_filesystem->incr_xfer_size = sfs.f_iosize;
+		t->current_filesystem->min_xfer_size = (sfs.f_iosize == 0) ? -1 : (long)sfs.f_iosize;
+		t->current_filesystem->incr_xfer_size = (sfs.f_iosize == 0) ? -1 : (long)sfs.f_iosize;
 #else
-		t->current_filesystem->min_xfer_size = sfs.f_bsize;
-		t->current_filesystem->incr_xfer_size = sfs.f_bsize;
+		t->current_filesystem->min_xfer_size = (sfs.f_bsize == 0) ? -1 : (long)sfs.f_bsize;
+		t->current_filesystem->incr_xfer_size = (sfs.f_bsize == 0) ? -1 : (long)sfs.f_bsize;
 #endif
 	}
 	if (sfs.f_flag & ST_LOCAL)
---END PATCH---

-RVP


Home | Main Index | Thread Index | Old Index