Tutorial 7: FUSE Pass through
os代写 | 代写quiz | IT代写 – 这是利用fuse系统进行训练的代写, 对os方面fuse的二次开发的流程进行训练解析, 是比较典型的操作系统等代写方向, 这是值得参考的quiz代写的题目
The purpose of this tutorial is to gain some familiarity with FUSE before you start working on your file system assignment. FUSE allows you to implement a file system in user space by implementing the callback functions that the libfuse library will call. The starter code for the tutorial is a very simple pass through file system. Runningpassthroughwill mount a file system at the directory you specify, and then every operation you perform on files and directories in that mount point will be passed through to the real file system. In other words, operations pass through our code.
Before beginning this tutorial, make sure you have downloaded the starter files and read through the Installing FUSE and Using FUSE sections.
1 Installing FUSE
There are two recommended ways to work with FUSE for the tutorial (and the assignment). Both of them will require some facility with the command-line file system operations. To be able to use FUSE, IT must be running in your kernel, so this means that it is not feasible to run the code for this tutorial on your directly on Mac OS or Windows.
1.1 Working locally with a virtual machine
You can run FUSE using an Ubuntu virtual machine. Here are our recommendations for the setup with VirtualBox:
- VirtualBox is a free open-source hypervisor that allows you to run a guest OS on top of your machine.
- Now install Ubuntu 18.04 as a VM in VirtualBox. You can use an image from osboxes.org, but you may find others. And you can find tutorials that explain the process.
NOTE: your VM must be 64-bit.
- Make sure your FUSE version is 2.9.* (i.e., runfusermount –version).
- Install additional packages:
sudo apt-get install libfuse-dev pkg-config
- To attach gdb to a running process you will need to change a security setting on Linux. You can do that using the following commands:
sudo bash
echo 0 > /proc/sys/kernel/yama/ptrace_scope
- You may want to increase the screen resolution for the VM. You can do this by selecting the Show Applications button in the bottom left corner and then going to Settings-Devices-Displays and changing the resolution.
If you use Windows, then Windows Subsystem for Linux 2 (WSL2) can replace VirtualBox. It is also now available in the Microsoft Store. Search for Windows Subsystem for Linux on the Microsoft Store and install it. Then you can search for Ubuntu 20.04 (also available: 18.04 and 22.04) and install that as well. Once installed, you can continue from Step 3 above.
Working on teach.cs 3
1.2 Working on teach.cs
Our system administrators are currently setting up a server just for CSC369 with FUSE installed.An announcement will be made when it is ready.But the instructions to login will require twosshs. That is, you must first log into teach.cs.toronto.edu, and from there ssh into csc369.teach.cs.toronto.edu.
For example, from a terminal on my machine, I run:
Then in that terminal, run
ssh csc369.teach.cs.toronto.edu
to log into the csc369 server. You still have access to all of your files on the teach.cs machines, so you can clone your repository for this exercise.
2 Using FUSE
FUSE allows you to implement a file system in user space by implementing the callback functions that thelibfuselibrary will call. For example, suppose you created a directory with some files inside of it:
Terminal 1
wolf$ mkdir my_root
wolf$ touch my_root/afile
wolf$ mkdir my_root/adir
A userspace file system would include an executable that can mount the directory my_rootto a specific location. Suppose that executable was called passthroughand is in our current working directory. Then, we could mountmy_rootto atmp/USERID(whereUSERIDis your teach.cs username) directory like so:
Terminal 1 (continued)
wolf$ mkdir /tmp/USERID
wolf$ ./passthrough -d ./my_root /tmp/USERID
FUSE library version: 2.9.
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
unique: 2, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0
INIT: 7.
flags=0x33fffffb
max_readahead=0x
INIT: 7.
flags=0x
max_readahead=0x
max_write=0x
max_background=
congestion_threshold=
unique: 2, success, outsize: 40
The-dflag is important because it prints debugging information that would be very useful. A less verbose flag is-f. You should use either of these flags when running your FUSE-based userspace filesystem.
In asecond terminal, you can now perform routine file system operations in the mounted directory. Some example operations could be:
- ls /tmp/USERID
- touch /tmp/USERID/afile
- echo a new file>/tmp/USERID/bfile
Working on teach.cs 5
- cd /tmp/USERID
- echo some text>afile
- cat afile
- cat bfile
- mkdir dir
- mv bfile dir
Figure 2.1 shows how the FUSE kernel module receives file system calls in the kernel and passes them to your file system program. In the top right it shows thatpassthroughhas been executed to mount your file system at/tmp/USERID. Now when you runls -l /tmp/USERIDthelsprogram will execute the system calls to list the contents of the directory. These system calls are executed in the kernel which recognizes that they need to be handled by the FUSE file system.
Figure 2.1: Thelsoperation using FUSE to call the corresponding function inpassthrough
FUSE executes the callbacks that are specified in thepassthroughcode. Forls, this will include passthrough_getattrandpassthrough_readdir. For example, on the second terminal:
Terminal 2
wolf$ ls /tmp/mnt/
adir afile
Would produce debug output from the first terminal that looks like (i.e., after you have finished this tutorial):
Terminal 1 (continued)
unique: 4, opcode: GETATTR (3), nodeid: 1, insize: 56, pid: 21417
getattr /
getattr(/, 0x7f82d6cd2c10)
unique: 4, success, outsize: 120
unique: 6, opcode: OPENDIR (27), nodeid: 1, insize: 48, pid: 21417
unique: 6, success, outsize: 32
unique: 8, opcode: READDIR (28), nodeid: 1, insize: 80, pid: 21417
readdir[0] from 0
readdir(/, 0x7f82d0000e20)
unique: 8, success, outsize: 144
unique: 10, opcode: LOOKUP (1), nodeid: 1, insize: 46, pid: 21417
LOOKUP /afile
getattr /afile
getattr(/afile, 0x7f82d74f5c40)
LOOKUP /adir
getattr /adir
- Working on teach.cs – NODEID: – unique: 10, success, outsize:
- unique: 12, opcode: LOOKUP (1), nodeid: 1, insize: 45, pid:
- NODEID: getattr(/adir, 0x7f82d6cd2c40)
- unique: 12, success, outsize:
- unique: 14, opcode: READDIR (28), nodeid: 1, insize: 80, pid:
- unique: 14, success, outsize:
- unique: 16, opcode: RELEASEDIR (29), nodeid: 1, insize: 64, pid:
- unique: 16, success, outsize:
- unique: 12, opcode: LOOKUP (1), nodeid: 1, insize: 45, pid:
3 The passthrough file system
Your task is simply to add a print statement to each of the FUSE callback functions, and see which file
system operations trigger which callbacks. It will take longer to read the prerequisite documents and
run the program initially than to write the code.
Specifically, for each function mentioned inpassthrough_optsstruct, go to that function and add a
print statement. For example, inpassthrough_getattr, you should add:
1 /** 2 * Get file or directory attributes. 3 / 4 static int 5 passthrough_getattr(const char path, struct stat* st) 6 { 7 char abs_path[PATH_MAX]; 8 if (!get_path(abs_path, sizeof(abs_path), path)) 9 return -ENAMETOOLONG; 10 11 // ADD LINE BELOW 12 fprintf(stderr, "getattr(%s, %p)\n", path, (void*)st); 13 14 // … 15 }
Listing 1: An example of adding a print statement to a callback function.
When writing your print statements, note:
- Print to stderr.
- Print the name of the function withoutpassthrough_.
- Print the parentheses, and put a comma between each argument.
- Print the arguments in the order that they appear in the function parameter list.
- Ignore parameters of typefuse_fill_dir_tand structfuse_file_info
- If an argument is of type char *, then print the string unless the argument is a buffer (e.g., char *bufinpassthrough_read). For buffer arguments, print the address of the buffer.
- If an argument is a pointer to a struct, print the address (see getattr example).
- If an argument is a number then print the number. The typeoff_tuses the format"%ld"; the typesize_tis unsigned and uses the format"%lu".
Working on teach.cs 8
- If an argument is of typemode_tuse the format"%04o"(modes are traditionally displayed in octal).
- Ensure there is a newline at the end of the print statement.
When you have completed the above modifications, try the Quercus quiz. The quiz asks you to run your code and answer questions. The questions should help your understanding of which operations result in which function calls in FUSE.