Giter Club home page Giter Club logo

Comments (4)

Nikratio avatar Nikratio commented on July 30, 2024

Having looked into this a bit more, the situation is this:

From the API, it may appear as if every fuse session (struct fuse_session) is associated with a single fuse channel (struct fuse_chan) that is created by fuse_mount() and assigned to the session in fuse_session_add_chan(). Therefore, one may wonder why there are two separate structs in the first place, and why the channel structure has a reference counter and mutex.

The answer is that when using the multi-threaded session loop with the clone_fd option enabled, there are actually multiple channel objects per session. The session only holds a reference to the first one, and the additional channel objects don't actually hold references to the session object -- but they still exist. The additional channels are created by duplicating the fd (in fuse_clone_chan(), called by fuse_loop_start_thread). When processing a request, fuse_session_process_buf() records the active channel in the request object (struct fuse_req) so that it can be retrieved by e.g. the fuse_reply_* functions. Since the request object can potentially live longer than the worker thread that created it, we need to keep a reference count for the channel.

The reason for not having references to the session object from the extra channels is not clear, but with the current implementation this would not work because fuse_session_remove_chan always attempts to remove the channel from the session.

from libfuse.

Nikratio avatar Nikratio commented on July 30, 2024

So in other words, although the implementation makes sense, it is rather confusing. I think it would be better to merge struct fuse_chan into struct fuse_session (because there is always exactly one channel object associated with one session object with pointers in both directions), and then use a reduced struct fuse_chan only for the additional channels created by fuse_loop_mt (in particular, remove the session reference which is always null anyway).

This would also allow us to remove the fuse_session_add_chan and fuse_session_remove_chan functions which are rather pointless, since there is only ever one channel per session - so we may just as well create and destroy the channel together with the session.

from libfuse.

Nikratio avatar Nikratio commented on July 30, 2024

Another thought:

At the moment, the only channel that's accessible to the user application is the "master" channel that's stored in struct fuse_session. The per-worker channels are stored in the worker array and the struct fuse_req objects (so that they can be used by the fuse_reply_* functions), but there is no public API for them. So even though libfuse currently has several API functions that take struct fuse_chan parameters (notably all the fuse_lowlevel_notify_* functions), all these parameters can be replaced by struct fuse_session - because the channel that's embedded in there is the only one that the client application could pass anyway.

from libfuse.

Nikratio avatar Nikratio commented on July 30, 2024

This has been fixed in commit 5698ee0.

from libfuse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.