Skip to content

Commit

Permalink
added locking at the FUSE level, and the option --single-threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
terencehonles committed Apr 23, 2012
1 parent 8cab1fe commit 2502365
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fuse
import os
import stat
import threading
import time

from argparse import ArgumentParser
Expand Down Expand Up @@ -89,6 +90,7 @@ def __init__(self, base='.', depth=0):
self.__exploded_info = {}
self.__handles = {}
self.__fh = 0
self.__fh_lock = threading.Lock()

def _exploded_info(self, path):
if path in self.__exploded_info: return self.__exploded_info[path]
Expand Down Expand Up @@ -220,19 +222,21 @@ def link(self, target, source):
mknod = _not_supported

def open(self, path, flags):
raw = File(path, flags, self._exploded_info(path), fh=self.__fh,
base=self.base, depth=self.depth)
with self.__fh_lock:
raw = File(path, flags, self._exploded_info(path), fh=self.__fh,
base=self.base, depth=self.depth)

self.__handles[self.__fh] = BufferedReader(raw)
self.__handles[self.__fh] = threading.Lock(), BufferedReader(raw)

self.__fh += 1
return raw.fh
self.__fh += 1
return raw.fh

def read(self, path, size, offset, fh):
reader = self.__handles[fh]
lock, reader = self.__handles[fh]

reader.seek(offset)
return reader.read(size)
with lock:
reader.seek(offset)
return reader.read(size)

def readdir(self, path, fh):
if path != '/':
Expand Down Expand Up @@ -437,6 +441,7 @@ def __init__(self, path, flags, info, fh=None, base='.', depth=0):

# init
self._load_stream_item()
self.lock = threading.Lock()

def _load_stream_item(self):
if self.data:
Expand Down Expand Up @@ -693,10 +698,13 @@ def writeable(self):
help='data subdirectory depth')

parser.add_argument('-D', '--debug', action='store_true', default=False,
help='Enable FUSE debugging mode')
help='enable FUSE debugging mode')

parser.add_argument('-b', '--background', action='store_true', default=False,
help='Do not exit until the file system is unmounted')
help='do not exit until the file system is unmounted')

parser.add_argument('-s', '--single-threaded', action='store_true',
default=False, help='do not run in multi-threaded mode')

parser.add_argument('mount', help='mount point')

Expand All @@ -705,4 +713,4 @@ def writeable(self):

fuse = FUSE(ExplodedZip(base=args.directory, depth=args.depth),
args.mount, foreground=not args.background, ro=True,
debug=args.debug)
debug=args.debug, nothreads=args.single_threaded)

0 comments on commit 2502365

Please sign in to comment.