Subject: libfuse 3 can't find fusermount

From: Leo Famulari <[email-masked]>
Date: Fri, 21 Jan 2022 02:41:49 -0500

While testing a Borg update (patch attached), I noticed that the
FUSERMOUNT_DIR hack in Fuse 3 doesn't seem to work like it does with
Fuse 2.

The 1.2.0b3 beta of the upcoming Borg release can use either Fuse 2
(with python-llfuse) or Fuse 3 (with python-pyfuse3).

The `borg mount` command works as expected with Fuse 2 / llfuse.

But, with Fuse 3 / pyfuse3, it fails with:

fuse: failed to exec fusermount3: No such file or directory

When I commented out the FUSERMOUNT_DIR [0] substitution in the fuse-3
package and rebuilt Borg, `borg mount` instead gives us this, which is
expected, because this system does not have a setuid fusermount3:

fusermount3: mount failed: Operation not permitted

So, the substitution doesn't seem to help with Fuse 3: it just breaks
the lookup.

You can apply the patch and test it out. And you can also observe the
optimal behaviour if you switch the borg package's fuse implementation
from pyfuse3 to llfuse / Fuse 2.

Should we just remove the substitution in fuse-3?

[0]
https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/linux.scm?id=b09f2aa4dae7e2a2f0f37ba831a2428fee8557d2#n3306
diff --git a/gnu/packages/backup.scm b/gnu/packages/backup.scm
index a8f300f0b8..5bc2a8015f 100644
--- a/gnu/packages/backup.scm
+++ b/gnu/packages/backup.scm
@@ -1,7 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2014, 2015, 2020 Eric Bavier <[email-masked]>
 ;;; Copyright © 2014 Ian Denhardt <[email-masked]>
-;;; Copyright © 2015, 2016, 2017 Leo Famulari <[email-masked]>
+;;; Copyright © 2015, 2016, 2017, 2022 Leo Famulari <[email-masked]>
 ;;; Copyright © 2017–2021 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2017 Thomas Danckaert <[email-masked]>
 ;;; Copyright © 2017, 2021 Arun Isaac <[email-masked]>
@@ -57,6 +57,7 @@ (define-module (gnu packages backup)
   #:use-module (gnu packages crypto)
   #:use-module (gnu packages databases)
   #:use-module (gnu packages datastructures)
+  #:use-module (gnu packages digest)
   #:use-module (gnu packages dbm)
   #:use-module (gnu packages dejagnu)
   #:use-module (gnu packages ftp)
@@ -83,6 +84,7 @@ (define-module (gnu packages backup)
   #:use-module (gnu packages rsync)
   #:use-module (gnu packages serialization)
   #:use-module (gnu packages ssh)
+  #:use-module (gnu packages time)
   #:use-module (gnu packages tls)
   #:use-module (gnu packages valgrind)
   #:use-module (gnu packages xml))
@@ -619,13 +621,13 @@ (define-public libchop
 (define-public borg
   (package
     (name "borg")
-    (version "1.1.17")
+    (version "1.2.0b3")
     (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "borgbackup" version))
        (sha256
-        (base32 "0x0ncy0b0bmf586hbdgrif3gjmkdw760vfnfxndr493v07y29fbs"))
+        (base32 "0gnx4i1pbzym9mb93w4bijaq189a9319ry0gzcm15rk41mq5lcag"))
        (modules '((guix build utils)))
        (snippet
         '(begin
@@ -635,8 +637,6 @@ (define-public borg
            ;; generate the wrong list.
            (for-each delete-file
                      '("src/borg/algorithms/checksums.c"
-                       "src/borg/algorithms/msgpack/_packer.cpp"
-                       "src/borg/algorithms/msgpack/_unpacker.cpp"
                        "src/borg/chunker.c"
                        "src/borg/compress.c"
                        "src/borg/crypto/low_level.c"
@@ -646,15 +646,17 @@ (define-public borg
                        "src/borg/platform/freebsd.c"
                        "src/borg/platform/linux.c"
                        "src/borg/platform/posix.c"
-                       "src/borg/platform/syncfilerange.c"))
+                       "src/borg/platform/syncfilerange.c"
+                       "src/borg/platform/windows.c"))
            ;; Remove bundled shared libraries.
            (with-directory-excursion "src/borg/algorithms"
              (for-each delete-file-recursively
-                       (list "blake2" "lz4" "zstd")))
+                       (list "lz4" "xxh64" "zstd")))
            #t))))
     (build-system python-build-system)
     (arguments
-     `(#:modules ((srfi srfi-26)        ; for cut
+     `(#:tests? #f ; The tests pass. Skip them all while debugging FUSE 3
+       #:modules ((srfi srfi-26)        ; for cut
                   (guix build utils)
                   (guix build python-build-system))
        #:phases
@@ -662,12 +664,12 @@ (define-public borg
          (add-after 'unpack 'set-env
            (lambda* (#:key inputs #:allow-other-keys)
              (let ((openssl (assoc-ref inputs "openssl"))
-                   (libb2 (assoc-ref inputs "libb2"))
                    (lz4 (assoc-ref inputs "lz4"))
+                   (xxhash (assoc-ref inputs "xxhash"))
                    (zstd (assoc-ref inputs "zstd")))
                (setenv "BORG_OPENSSL_PREFIX" openssl)
-               (setenv "BORG_LIBB2_PREFIX" libb2)
                (setenv "BORG_LIBLZ4_PREFIX" lz4)
+               (setenv "BORG_LIBXXHASH_PREFIX" xxhash)
                (setenv "BORG_LIBZSTD_PREFIX" zstd)
                (setenv "PYTHON_EGG_CACHE" "/tmp")
                ;; The test 'test_return_codes[python]' fails when
@@ -677,32 +679,37 @@ (define-public borg
          ;; The tests need to be run after Borg is installed.
          (delete 'check)
          (add-after 'install 'check
-           (lambda* (#:key inputs outputs #:allow-other-keys)
-             ;; Make the installed package available for the test suite.
-             (add-installed-pythonpath inputs outputs)
-             ;; The tests should be run in an empty directory.
-             (mkdir-p "tests")
-             (with-directory-excursion "tests"
-               (invoke "py.test" "-v" "--pyargs" "borg.testsuite" "-k"
-                       (string-append
-                        ;; These tests need to write to '/var'.
-                        "not test_get_cache_dir "
-                        "and not test_get_config_dir "
-                        "and not test_get_keys_dir "
-                        "and not test_get_security_dir "
-                        ;; These tests assume there is a root user in
-                        ;; '/etc/passwd'.
-                        "and not test_access_acl "
-                        "and not test_default_acl "
-                        "and not test_non_ascii_acl "
-                        "and not test_create_stdin "
-                        ;; This test needs the unpackaged pytest-benchmark.
-                        "and not benchmark "
-                        ;; These tests assume the kernel supports FUSE.
-                        "and not test_fuse "
-                        "and not test_fuse_allow_damaged_files "
-                        "and not test_mount_hardlinks "
-                        "and not test_readonly_mount ")))))
+           (lambda* (#:key inputs outputs tests? #:allow-other-keys)
+             (when tests?
+              ;; Make the installed package available for the test suite.
+              (add-installed-pythonpath inputs outputs)
+              ;; The tests should be run in an empty directory.
+              (mkdir-p "tests")
+              (with-directory-excursion "tests"
+                (invoke "py.test" "-v" "--pyargs" "borg.testsuite" "-k"
+                        (string-append
+                         ;; These tests need to write to '/var'.
+                         "not test_get_cache_dir "
+                         "and not test_get_config_dir "
+                         "and not test_get_keys_dir "
+                         "and not test_get_security_dir "
+                         ;; These tests assume there is a root user in '/etc/passwd'.
+                         "and not test_access_acl "
+                         "and not test_default_acl "
+                         "and not test_get_item_uid_gid "
+                         "and not test_non_ascii_acl "
+                         "and not test_create_content_from_command "
+                         "and not test_create_content_from_command_with_failed_command "
+                         "and not test_create_stdin "
+                         ;; We don't need to run benchmarks
+                         "and not benchmark "
+                         ;; These tests assume the kernel supports FUSE.
+                         "and not test_fuse "
+                         "and not test_fuse_allow_damaged_files "
+                         "and not test_mount_hardlinks "
+                         "and not test_readonly_mount "
+                         "and not test_fuse_versions_view "
+                         "and not test_migrate_lock_alive"))))))
          (add-after 'install 'install-doc
            (lambda* (#:key inputs outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out"))
@@ -710,10 +717,10 @@ (define-public borg
                     (misc (string-append out "/share/borg/misc")))
                (for-each (cut install-file <> misc)
                          '("docs/misc/create_chunker-params.txt"
+                           "docs/misc/borg-data-flow.png"
                            "docs/misc/internals-picture.txt"
                            "docs/misc/prune-example.txt"))
-               (copy-recursively "docs/man" man)
-               #t)))
+               (copy-recursively "docs/man" man))))
          (add-after 'install-docs 'install-shell-completions
            (lambda* (#:key outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out"))
@@ -725,24 +732,26 @@ (define-public borg
                  (install-file "zsh/_borg"
                                (string-append share "/zsh/site-functions"))
                  (install-file "fish/borg.fish"
-                               (string-append share "/fish/vendor_completions.d")))
-               #t))))))
+                               (string-append share "/fish/vendor_completions.d")))))))))
     (native-inputs
-     (list python-cython python-setuptools-scm python-pytest))
+     (list python-cython python-dateutil python-setuptools-scm python-pytest))
     (inputs
      (list acl
-           libb2
            lz4
            openssl
-           python-llfuse
-           `(,zstd "lib")))
+           ;; This is the latest version of msgpack accepted by 'setup.py'.
+           python-msgpack-1.0.2
+;           python-llfuse
+           python-pyfuse3
+           `(,zstd "lib")
+           xxhash))
     (synopsis "Deduplicated, encrypted, authenticated and compressed backups")
     (description "Borg is a deduplicating backup program.  Optionally, it
 supports compression and authenticated encryption.  The main goal of Borg is to
 provide an efficient and secure way to backup data.  The data deduplication
 technique used makes Borg suitable for daily backups since only changes are
-stored.  The authenticated encryption technique makes it suitable for backups
-to not fully trusted targets.  Borg is a fork of Attic.")
+stored.  The authenticated encryption technique makes it suitable for storing
+backups on untrusted computers.")
     (home-page "https://www.borgbackup.org/")
     (license license:bsd-3)))
 
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index eff1c4259b..c75ea42088 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -11,7 +11,7 @@
 ;;; Copyright © 2015, 2016, 2020 Christine Lemmer-Webber <[email-masked]>
 ;;; Copyright © 2015 Eric Dvorsak <[email-masked]>
 ;;; Copyright © 2015, 2016 David Thompson <[email-masked]>
-;;; Copyright © 2015, 2016, 2017, 2019 Leo Famulari <[email-masked]>
+;;; Copyright © 2015, 2016, 2017, 2019, 2022 Leo Famulari <[email-masked]>
 ;;; Copyright © 2015, 2017 Ben Woodcroft <[email-masked]>
 ;;; Copyright © 2015, 2016 Erik Edrosa <[email-masked]>
 ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020, 2021 Efraim Flashner <[email-masked]>
@@ -11135,6 +11135,17 @@ (define-public python-msgpack
     (home-page "https://pypi.org/project/msgpack/")
     (license license:asl2.0)))
 
+(define-public python-msgpack-1.0.2
+  (package
+    (inherit python-msgpack)
+    (version "1.0.2")
+    (source (origin
+              (method url-fetch)
+              (uri (pypi-uri "msgpack" version))
+              (sha256
+               (base32
+                "1109s2yynrahwi64ikax68hx0mbclz8p35afmpphw5dwynb49q7s"))))))
+
 ;; This msgpack library's name changed from "python-msgpack" to "msgpack" with
 ;; release 0.5. Some packages like borg still call it by the old name for now.
 ;; <https://bugs.gnu.org/30662>
@@ -28678,3 +28689,22 @@ (define-public python-reedsolo
 but not binary streams.")
     (license license:public-domain)))
 
+(define-public python-pyfuse3
+  (package
+    (name "python-pyfuse3")
+    (version "3.2.1")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (pypi-uri "pyfuse3" version))
+        (sha256
+          (base32 "0cvybynv9igssfa4l13q09gb6m7afmwk34wsbq8jk14sqpd4dl92"))))
+    (build-system python-build-system)
+    (native-inputs (list pkg-config))
+    (inputs (list fuse-3))
+    (propagated-inputs (list python-pytest-trio))
+    (home-page "https://github.com/libfuse/pyfuse3")
+    (synopsis "Python bindings FUSE 3")
+    (description "This package provides Python 3 bindings for libfuse 3 with
+async I/O support.")
+    (license license:gpl2+)))