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 3 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
2 changes: 1 addition & 1 deletion src/_pyfuse3.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Operations:
enable_writeback_cache: bool = False
enable_acl: bool = False

def init(self) -> None:
def init(self, conn_info) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a type annotation for the second argument

'''Initialize operations.

This method will be called just before the file system starts handling
Nikratio marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
10 changes: 7 additions & 3 deletions src/handlers.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ 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()
cdef ConnInfo conn_obj
conn_obj = ConnInfo.__new__(ConnInfo)
string.memcpy(&conn_obj.conn, conn, sizeof(fuse_conn_info))
# Blocking rather than async, to let the init hander modify `conn`.
operations.init(conn_obj)
string.memcpy(conn, &conn_obj.conn, sizeof(fuse_conn_info))


cdef void fuse_lookup (fuse_req_t req, fuse_ino_t parent,
const_char *name):
Expand Down
9 changes: 9 additions & 0 deletions src/pyfuse3.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class FileInfo:
def __cinit__(self, fh: FileHandleT, direct_io: bool, keep_cache: bool, nonseekable: bool) -> None: ...
# def _copy_to_fuse(self, fuse_file_info *out) -> None: ...


class ConnInfo:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why both this and the cdef clas in pyfuse3.pyx? Isn't one sufficient?

max_read: int

def __cinit__(self) -> None: ...
def __getstate__(self) -> StatDict: ...
def __setstate__(self, state: StatDict) -> None: ...


class StatvfsData:
f_bsize: int
f_frsize: int
Expand Down
31 changes: 31 additions & 0 deletions src/pyfuse3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,37 @@ cdef class FileInfo:
out.nonseekable = 0


@cython.freelist(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed for something that's used once

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

cdef fuse_conn_info conn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of keeping a copy of the whole struct around, if all you care about is the max_read parameter?


def __cinit__(self):
string.memset(&self.conn, 0, sizeof(fuse_conn_info))

@property
def max_read(self):
return self.conn.max_read
@max_read.setter
def max_read(self, val):
self.conn.max_read = val

# Pickling and copy support
def __getstate__(self):
state = dict()
for k in ('max_read',):
state[k] = getattr(self, k)
return state

def __setstate__(self, state):
for (k,v) in state.items():
setattr(self, k, v)


@cython.freelist(1)
cdef class StatvfsData:
'''
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