From dd577bf4acac9d4d33043b729449ad7ff44e77ee Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 27 Oct 2015 22:37:36 +0100 Subject: [PATCH] fuse mount: fix unlocking of repository at umount time, fixes #331 there were 2 issues: lock used another pid and tid than release because daemonize() made it different processes/threads. solved by just determining PID only once and not using TID any more. the other issue was that the repo needed and explicit closing. --- borg/archiver.py | 25 ++++++++++++++----------- borg/locking.py | 13 ++++++++----- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 4dcf38670..634a0c5bf 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -348,18 +348,21 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") return self.exit_code repository = self.open_repository(args.src) - manifest, key = Manifest.load(repository) - if args.src.archive: - archive = Archive(repository, key, manifest, args.src.archive) - else: - archive = None - operations = FuseOperations(key, repository, manifest, archive) - self.print_verbose("Mounting filesystem") try: - operations.mount(args.mountpoint, args.options, args.foreground) - except RuntimeError: - # Relevant error message already printed to stderr by fuse - self.exit_code = EXIT_ERROR + manifest, key = Manifest.load(repository) + if args.src.archive: + archive = Archive(repository, key, manifest, args.src.archive) + else: + archive = None + operations = FuseOperations(key, repository, manifest, archive) + self.print_verbose("Mounting filesystem") + try: + operations.mount(args.mountpoint, args.options, args.foreground) + except RuntimeError: + # Relevant error message already printed to stderr by fuse + self.exit_code = EXIT_ERROR + finally: + repository.close() return self.exit_code def do_list(self, args): diff --git a/borg/locking.py b/borg/locking.py index b2beac345..aff3c5fcd 100644 --- a/borg/locking.py +++ b/borg/locking.py @@ -2,7 +2,6 @@ import errno import json import os import socket -import threading import time from borg.helpers import Error @@ -10,13 +9,17 @@ from borg.helpers import Error ADD, REMOVE = 'add', 'remove' SHARED, EXCLUSIVE = 'shared', 'exclusive' +# only determine the PID and hostname once. +# for FUSE mounts, we fork a child process that needs to release +# the lock made by the parent, so it needs to use the same PID for that. +_pid = os.getpid() +_hostname = socket.gethostname() + def get_id(): """Get identification tuple for 'us'""" - hostname = socket.gethostname() - pid = os.getpid() - tid = threading.current_thread().ident & 0xffffffff - return hostname, pid, tid + thread_id = 0 + return _hostname, _pid, thread_id class TimeoutTimer: