FUSE工作流程官方文檔

來源:互聯網
上載者:User

                           How Fuse-1.3 Works

[這篇文檔已經有點老了, 不過對於瞭解FUSE工作原理的朋友來講已經夠了.]
[Written by Terje Oseberg]
1. The fuse library.

When your user mode program calls fuse_main() (lib/helper.c), fuse_main() parses the arguments passed to your user mode program, then calls fuse_mount() (lib/mount.c).

fuse_mount() creates a UNIX domain socket pair, then forks and execs fusermount (util/fusermount.c) passing it one end of the socket in the FUSE_COMMFD_ENV environment variable.

實際上, 在新版的fuse library中不是所有的fuse_mount會調用socketpair()來建立socket. 在新版的fuse library中, 如果掛載點是使用者可以訪問的, 則用於和kernel的fuse通訊用的fd實際上為open("/dev/fuse",...)返回的描述符. 如果使用者不可以訪問, 譬如掛載點位於/opt/fuse的話, 會調用socketpair來建立UNIX域的socket.

fusermount (util/fusermount.c) makes sure that the fuse module is loaded. fusermount then open /dev/fuse and send the file handle over a UNIX domain socket back to fuse_mount().

fuse_mount() returns the filehandle for /dev/fuse to fuse_main().fuse_main() calls fuse_new() (lib/fuse.c) which allocates the struct fuse datastructure that stores and maintains a cached image of the filesystem data.

Lastly, fuse_main() calls either fuse_loop() (lib/fuse.c) or fuse_loop_mt() (lib/fuse_mt.c) which both start to read the filesystem system calls from the /dev/fuse, call the usermode functions stored in struct fuse_operations datastructure before calling fuse_main(). The results of those calls are then written back to the /dev/fuse file where they can be forwarded back to the system calls.

2. The kernel module.

The kernel module consists of two parts. First the proc filesystem component in kernel/dev.c -and second the filesystem system calls kernel/file.c, kernel/inode.c, and kernel/dir.c All the system calls in kernel/file.c, kernel/inode.c, and kernel/dir.c make calls to either request_send(), request_send_noreply(), or request_send_nonblock(). Most of the calls (all but 2) are to request_send(). request_send() adds the request to, "list of requests" structure (fc->pending), then waits for a response. request_send_noreply() and request_send_nonblock() are both similar in function to request_send() except that one is non-blocking, and the other does not respond with a reply.
The proc filesystem component in kernel/dev.c responds to file io requests to the file /dev/fuse. fuse_dev_read() handles the file reads and returns commands from the "list of requests" structure to the calling program. fuse_dev_write() handles file writes and takes the data written and places them into the req->out datastructure where they can be returned to the system call through the "list of requests" structure and request_send().

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.