Since I can not figure out how to make it work, so I met with Sarah again. This time with Sarah's help, I made big progress. Sarah suggested me to do a little in Kconfig to add one more item and then add one line in Makefile to make dm-statistic a independent module because that's what she did for her true-erase project. I followed her steps and it worked. Now the dmsetup can fully work with my new modules.
I created a /proc file called statistic and fill the buf with some information about the bio just came in. It worked and I can see those content in the /proc/statistic file, however I didn't consider a important thing. It will create a new /proc/statistic file every time it maps a bio. So I had a lot of /proc/statistic files in procfs and each contains the information about one bio which is not we wanted. What we want is to have only one file and it contains all the bio information.
I used a really dumped approach to slove this problem. After I create an entry, I filled the buffer, then I remove the entry. This time because it was so fast that I can not see any /proc/statistic file. I solved this problem in next week.
Week 4
This week is the most important week for me and for this project. I met Sarah again. This time I download a newest kernel version which is linux 3.8.7 and start do all the thing in this kernel. I first removed all the unnecessary modules and compiled the kernel. So the kernel is really fast, however the cost is I even didn't have the wireless network module. It compiles and load/reload modules really fast. I put the .config file in the dowload page.
I made too major progress in the project. First I solved the multiple /proc/statistic files and non /proc/statistic files problem. Actually it was really easy. You can create the file only once, outside the map function, and it map function, just do fill. And I remove the entry when the exit() function was called. However when I test it, there was another problem. When I had too many bios, it can not be read properly in /proc/statistic. After I searched the internet, I found out that it was because procfs can only handle no more than one page size. Normal the page size is 4MB, so if the content you want to store in procfs file is more than 4MB, the read operation can not work correctly.
The second major progress is that I sloved the page size limitation problem above. In this kind of situation, the right way to do it using seq_file interface. I searched online and there are very good tutorals and examples. I followed those materials and solved the problem in some level.
Week 5
Actually I came up with a different idea to do controling. Instead of doing this work in file system, can we do it in some other ways. The first idea is to use /proc/sys so the kernel module can get some configuration from some file and those values actually controls the behavior of the device mapper layer. However Sarach still suggeted me to do the work in file system. She gave me a very good guide so I wan't be so confuesed when tracing the data flow from file system to jbd2. I tried but I failed to do it.
Then I thought about other alternatives and I really got a very good idea. Since we are writing a new module in device mapper, why can't we do the controling work in the same module. Then I try to add this function just in my dm-statistic module. luckily it worked and i think it is easier than do the controling work in any other place. I showed this approach to Sarah and she also thinks this is a good try because it simplify all the things a lot. Even though I bypass the most difficult part, however I still achieve the goal.
I also improved my seq_file part to avoid a memory leak. Because in previous implementation I forgot to add clean function for the list structure. I also re-formatiing the bio information in /proc/statistic file.
Another work is I wrote a user program to get the count of bio from /proc/statistic, so that user can use this program to check the amount of each type of bio in a peraiod of time. I provided to checking ways, one is to check during last x second and the other is to check from x second to y second.
Week 6
This is the demo week and I did the demo on Tuesday. Sarah suggested me to add some extra functionalities like reset time, export functions to the global kernel and more descriptive information about bio. Those are not very difficult work. Only one thing is when I do reset time, it also cleaned all the bio structure that already in the list. Because it makes no sence that some bio even exsist before start time.