Skip to content

Commit 9037537

Browse files
committed
Adopted FUSE's "rawfi" option set to "True". As a consequence, the file system now (more consistently) opens and
closes files without repoening them for read and write operations.
2 parents c608cbe + 717d924 commit 9037537

File tree

1 file changed

+98
-31
lines changed

1 file changed

+98
-31
lines changed

src/loggedfs/core.py

Lines changed: 98 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ def loggedfs_factory(directory, **kwargs):
7272
**kwargs
7373
),
7474
directory,
75+
raw_fi = True,
7576
nothreads = True,
7677
foreground = bool(kwargs['fuse_foreground_bool']) if 'fuse_foreground_bool' in kwargs.keys() else False,
7778
allow_other = bool(kwargs['fuse_allowother_bool']) if 'fuse_allowother_bool' in kwargs.keys() else False,
7879
default_permissions = bool(kwargs['fuse_allowother_bool']) if 'fuse_allowother_bool' in kwargs.keys() else False,
7980
attr_timeout = 0,
8081
entry_timeout = 0,
8182
negative_timeout = 0,
83+
# sync_read = True,
84+
# max_readahead = 0,
85+
# direct_io = True,
8286
nonempty = True, # common options taken from LoggedFS
8387
use_ino = True # common options taken from LoggedFS
8488
)
@@ -138,10 +142,20 @@ def __get_user_name_from_uid__(uid):
138142

139143
def __log__(
140144
format_pattern = '',
141-
abs_path_fields = [], length_fields = [], uid_fields = [], gid_fields = [],
145+
abs_path_fields = None, length_fields = None,
146+
uid_fields = None, gid_fields = None,
142147
path_filter_field = 0
143148
):
144149

150+
if abs_path_fields is None:
151+
abs_path_fields = []
152+
if length_fields is None:
153+
length_fields = []
154+
if uid_fields is None:
155+
uid_fields = []
156+
if gid_fields is None:
157+
gid_fields = []
158+
145159
def wrapper(func):
146160

147161
@wraps(func)
@@ -281,8 +295,8 @@ class loggedfs(Operations):
281295

282296
def __init__(self,
283297
directory,
284-
log_includes = [],
285-
log_excludes = [],
298+
log_includes = None,
299+
log_excludes = None,
286300
log_file = None,
287301
log_syslog = False,
288302
log_enabled = True,
@@ -292,6 +306,11 @@ def __init__(self,
292306
fuse_allowother_bool = None
293307
):
294308

309+
if log_includes is None:
310+
log_includes = []
311+
if log_excludes is None:
312+
log_excludes = []
313+
295314
self._init_logger(log_enabled, log_file, log_syslog, log_printprocessname)
296315

297316
if bool(fuse_foreground_bool):
@@ -443,24 +462,39 @@ def destroy(self, path):
443462

444463

445464
@__log__(format_pattern = '{0}', abs_path_fields = [0])
446-
def getattr(self, path, fh = None):
465+
def getattr(self, path, fip):
447466

448-
try:
467+
if not fip:
468+
try:
469+
st = os.lstat(self._rel_path(path), dir_fd = self.root_path_fd)
470+
except FileNotFoundError:
471+
raise FuseOSError(errno.ENOENT)
472+
else:
473+
st = os.fstat(fip.fh)
449474

450-
st = os.lstat(self._rel_path(path), dir_fd = self.root_path_fd)
451-
ret_dict = {key: getattr(st, key) for key in self.st_fields}
475+
ret_dict = {key: getattr(st, key) for key in self.st_fields}
452476

453-
for key in ['st_atime', 'st_ctime', 'st_mtime']:
454-
if self.flag_nanosecond_int:
455-
ret_dict[key] = ret_dict.pop(key + '_ns')
456-
else:
457-
ret_dict.pop(key + '_ns')
477+
for key in ['st_atime', 'st_ctime', 'st_mtime']:
478+
if self.flag_nanosecond_int:
479+
ret_dict[key] = ret_dict.pop(key + '_ns')
480+
else:
481+
ret_dict.pop(key + '_ns')
482+
483+
return ret_dict
458484

459-
return ret_dict
460485

461-
except FileNotFoundError:
486+
# @__log__(format_pattern = '{0} (fh={1})')
487+
# Ugly HACK, addressing https://github.com/fusepy/fusepy/issues/81 ????????
488+
def flush(self, path, fip):
489+
490+
# os.fsync(fip.fh)
491+
raise FuseOSError(errno.ENOSYS)
462492

463-
raise FuseOSError(errno.ENOENT)
493+
494+
# Ugly HACK, addressing https://github.com/fusepy/fusepy/issues/81 ????????
495+
def fsync(self, path, datasync, fip):
496+
497+
raise FuseOSError(errno.ENOSYS)
464498

465499

466500
@__log__(format_pattern = '{0}')
@@ -469,6 +503,12 @@ def init(self, path):
469503
os.fchdir(self.root_path_fd)
470504

471505

506+
# Ugly HACK, addressing https://github.com/fusepy/fusepy/issues/81 ????????
507+
def ioctl(self, path, cmd, arg, fh, flags, data):
508+
509+
raise FuseOSError(errno.ENOSYS)
510+
511+
472512
@__log__(format_pattern = '{1} to {0}', abs_path_fields = [0, 1])
473513
def link(self, target_path, source_path):
474514

@@ -483,6 +523,12 @@ def link(self, target_path, source_path):
483523
os.lchown(target_rel_path, uid, gid)
484524

485525

526+
# Ugly HACK, addressing https://github.com/fusepy/fusepy/issues/81
527+
def lock(self, path, fh, cmd, lock):
528+
529+
raise FuseOSError(errno.ENOSYS)
530+
531+
486532
@__log__(format_pattern = '{0} {1}', abs_path_fields = [0])
487533
def mkdir(self, path, mode):
488534

@@ -518,22 +564,19 @@ def mknod(self, path, mode, dev):
518564

519565

520566
@__log__(format_pattern = '({1}) {0}', abs_path_fields = [0])
521-
def open(self, path, flags):
567+
def open(self, path, fip):
522568

523-
res = os.open(self._rel_path(path), flags, dir_fd = self.root_path_fd)
524-
os.close(res)
569+
fip.fh = os.open(self._rel_path(path), fip.flags, dir_fd = self.root_path_fd)
525570

526-
return 0 # Must return handle or zero
571+
return 0 # Must return handle or zero # TODO ?
527572

528573

529574
@__log__(format_pattern = '{1} bytes from {0} at offset {2}', abs_path_fields = [0])
530-
def read(self, path, length, offset, fh):
575+
def read(self, path, length, offset, fip):
531576

532577
# ret is a bytestring!
533578

534-
fh_loc = os.open(self._rel_path(path), os.O_RDONLY, dir_fd = self.root_path_fd)
535-
ret = os.pread(fh_loc, length, offset)
536-
os.close(fh_loc)
579+
ret = os.pread(fip.fh, length, offset)
537580

538581
return ret
539582

@@ -563,6 +606,12 @@ def readlink(self, path):
563606
return pathname
564607

565608

609+
# Ugly HACK, addressing https://github.com/fusepy/fusepy/issues/81
610+
def release(self, path, fip):
611+
612+
raise FuseOSError(errno.ENOSYS)
613+
614+
566615
@__log__(format_pattern = '{0} to {1}', abs_path_fields = [0, 1])
567616
def rename(self, old, new):
568617

@@ -600,11 +649,27 @@ def symlink(self, target_path, source_path):
600649

601650

602651
@__log__(format_pattern = '{0} to {1} bytes', abs_path_fields = [0])
603-
def truncate(self, path, length, fh = None):
652+
def truncate(self, path, length, fip = None):
604653

605-
fd = os.open(self._rel_path(path), os.O_WRONLY | os.O_TRUNC, dir_fd = self.root_path_fd)
606-
os.truncate(fd, length)
607-
os.close(fd)
654+
if fip is None:
655+
656+
try:
657+
fh = os.open(
658+
self._rel_path(path),
659+
flags = os.O_WRONLY | os.O_TRUNC,
660+
dir_fd = self.root_path_fd
661+
)
662+
except FileNotFoundError:
663+
raise FuseOSError(errno.ENOENT)
664+
665+
ret = os.ftruncate(fh, length)
666+
os.close(fh)
667+
668+
return ret
669+
670+
else:
671+
672+
return os.ftruncate(fip.fh, length)
608673

609674

610675
@__log__(format_pattern = '{0}', abs_path_fields = [0])
@@ -640,12 +705,14 @@ def _fix_time_(atime, mtime):
640705

641706

642707
@__log__(format_pattern = '{1} bytes to {0} at offset {2}', abs_path_fields = [0], length_fields = [1])
643-
def write(self, path, buf, offset, fh):
708+
def write(self, path, buf, offset, fip):
644709

645710
# buf is a bytestring!
646711

647-
fh_loc = os.open(self._rel_path(path), os.O_WRONLY, dir_fd = self.root_path_fd)
648-
res = os.pwrite(fh_loc, buf, offset)
649-
os.close(fh_loc)
712+
res = os.pwrite(fip.fh, buf, offset)
713+
714+
#os.fdatasync(fip.fh)
715+
#os.fdopen(fip.fh).flush()
716+
#os.fsync(fip.fh)
650717

651718
return res

0 commit comments

Comments
 (0)