Overall structure and process

fuse It is a multi thread concurrency model , each worker All threads are reading /dev/fuse Request in , This ensures synchronization between threads , When a request is read , The thread begins to process the request , But if the listener thread is 0, Then continue to create a new thread to listen , After processing the request , If the number of threads exceeds the limit (10 individual ), Exit the thread . The whole framework is as follows :

 

worker Threads dispatch functions by request fuse_ll_process After dispatch request , according to opcode Forward to specific operation ( as init operation , Then it is do_init{lib/fuse_lowlevel.c}), It's by judging the head , Specific parameters are extracted , If the head is illegal , It is directly to the /dev/fuse Send error message , Otherwise, route the request to fuse_lib_opcode( as init, be fuse_lib_init{lib/fuse.c}), Execution and fuse Related operations , And find the corresponding cache according to the operation , Convert the parameter to a parameter that can be recognized by the user , The user registration function is then called , Wait for the user to return , Write back the results immediately to /dev/fuse In the equipment . After writing back , The thread becomes idle , Determine whether the number of threads exceeds the limit , If the limit is exceeded, the thread exits , Otherwise continue to read the next request .

The specific process is as follows :

Interrupt handling

When the upper application interrupts access fuse File system time , The read thread reads a request to interrupt the operation , Before issuing the request , First determine whether the request is an interrupt , If it's an interruption , Mark the interrupt , The request is removed from the interrupt list , When the interrupt function is executed , Call the interrupt callback function of the corresponding request , In fact, it is to judge whether the request is completed , If not, the thread corresponding to the request will be killed directly . If the thread has completed , Then judge again before sending the request
Is the request interrupted , It also deals with the corresponding interrupt function , If the request does not arrive , Put the request into the interrupt list , To facilitate the next dispatch request , Processing . The processing flow of the whole request is as follows :

  

fuse_prepare_interrupt() The function is mainly used to determine whether the request is interrupted , If in interrupt state , Call the interrupt handling function of the system , That is to kill the thread directly , The kernel interrupts the requested packet to release all the requested information .fuse_finish_interrupt() Function operations are similar to fuse_prepare_interrupt, The difference is one before the request , Unfinished phase (finished=0), The other is after the request , Processing of request completed (finished=1).

Read write device

         Mount the file system to /dev/fuse Shangshi , You need to specify the buffer size for a read request , Among them, the largest is 128K, and fuse Specified as 132K, The read function is read.

         When writing a reply to a device , The size of the write buffer is not specified , Write function as writev, It is generally 2 term : head , Relevant reply . If there is an error, only the head .

Buffer management

In order to reduce the number of lookup request ,fuse Client uses hash The algorithm implements a buffer , When it appears lookup During operation , adopt (ino,name) For the parent index node number hash, And then facilitate the specific sub nodes , Finally found name, Go back , If the search fails , The buffer is sent to the user registered function getattr request , Finally, the obtained data is cached .

The nodes are stored in a tree structure , Each node contains a parent node and a child node , And when you find a file in a folder , We use reverse traversal to get the absolute path of the file .

        There are two main types of buffers :name_hash,id_hash, The first major use (ino,name) Come on hash, And the second is only for ino conduct hash.

   

 

 

 

 

 

Technology