Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose API for modifying fuse_conn_info.max_read #50

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/_pyfuse3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
the terms of the GNU LGPL.
'''

from dataclasses import dataclass
import errno
import functools
import logging
Expand Down Expand Up @@ -44,6 +45,15 @@ async def wrapper(*args, **kwargs): # type: ignore
return wrapper


@dataclass
class ConnInfo:
'''
Instances of this class store information about the fuse connection.
The attributes correspond to the elements of the ``fuse_conn_info`` struct.
'''
max_read: int


class Operations:
'''
This class defines the request handler methods that an pyfuse3 file system
Expand All @@ -65,12 +75,17 @@ class Operations:
enable_writeback_cache: bool = False
enable_acl: bool = False

def init(self) -> None:
def init(self, conn_info: ConnInfo) -> None:
'''Initialize operations.

This method will be called just before the file system starts handling
Nikratio marked this conversation as resolved.
Show resolved Hide resolved
requests. It must not raise any exceptions (not even `FUSEError`), since
it is not handling a particular client request.

*conn_info* will be an instance of `ConnInfo`, containing fuse connection information.
Handler may modify some of its members in place. After the handler finishes
values stored will be read by libfuse. See `fuse_conn_info` struct reference.
Currently only `max_read` is supported.
'''

pass
Expand Down
7 changes: 4 additions & 3 deletions src/handlers.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ cdef void fuse_init (void *userdata, fuse_conn_info *conn):
conn.capable & FUSE_CAP_POSIX_ACL):
conn.want |= FUSE_CAP_POSIX_ACL

# Blocking rather than async, in case we decide to let the
# init hander modify `conn` in the future.
operations.init()
conn_obj = ConnInfo(max_read=conn.max_read)
operations.init(conn_obj)
conn.max_read = conn_obj.max_read


cdef void fuse_lookup (fuse_req_t req, fuse_ino_t parent,
const_char *name):
Expand Down
2 changes: 1 addition & 1 deletion src/pyfuse3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import typing
import _pyfuse3
_pyfuse3.FUSEError = FUSEError

from _pyfuse3 import Operations, async_wrapper
from _pyfuse3 import Operations, async_wrapper, ConnInfo

if typing.TYPE_CHECKING:
from _pyfuse3 import FileHandleT, FileNameT, FlagT, InodeT, ModeT
Expand Down
4 changes: 4 additions & 0 deletions test/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ def __init__(self, cross_process):
self.status.entry_timeout = 99999
self.status.attr_timeout = 99999

def init(self, conn_info):
conn_info.max_read = 4096

async def getattr(self, inode, ctx=None):
entry = pyfuse3.EntryAttributes()
if inode == pyfuse3.ROOT_INODE:
Expand Down Expand Up @@ -268,6 +271,7 @@ def run_fs(mountpoint, cross_process):
testfs = Fs(cross_process)
fuse_options = set(pyfuse3.default_options)
fuse_options.add('fsname=pyfuse3_testfs')
fuse_options.add('max_read=4096')
Nikratio marked this conversation as resolved.
Show resolved Hide resolved
pyfuse3.init(testfs, mountpoint, fuse_options)
try:
trio.run(pyfuse3.main)
Expand Down