This application is the result of a didactic project for the Operating Systems 2 course of the Master of Science of Engineering in Computer Science at Sapienza University of Rome. The author of this project is Davide Leoni
This project is aimed at the introduction of a session semantics for files into the the Linux Kernel, by mean of a dedicated module.
According to the session semantics, when a file session is opened by a process, all the modifications made to the original file are not visible by any other process until the session is closed by the process itself. As a consequence, the visible content of the file is always the result of the last closed file session.
In order to implement this new semantics, when a process calls the open system call requesting for a file session, the content of the file is entirely copied into a dynamically allocated memory buffer and all subsequent I/O operations possibly requested by the process on the file will affect only the buffer, not the original file itself. When the process closes the file, actually it closes the file session, so the content of the buffer is written into the original file, thus overriding all the previuous modifications possibly made by other processes.
In order to ensure that during a session a process can work on its "personal copy" of the the opened file without any interference by other processes, it's necessary to avoid using the buffer cache.
No limit is imposed on the number of file sessions that can be opened at any time nor on the size of the file that can be opened using the session semantics, except for the obvious limit imposed by the available memory. It is also possible to add content to the file beyond its original filesize: in fact, as the buffer initially allocated to the session gets full, new pages are dynamically allocated to it in order to
satisfy the write request.
When a new session is opened, the module usage counter is incremented, and when the session is closed the counter is decremented. This guarantees that the module won't be removed from the system while there's an active file session.
As the module is installed into the Linux Kernel, the session semantics can be requested by using the usual system call open and OR-ing any flag with the flag SESSION_OPEN (given in the header session.h): in fact the underlying code replaces the open system call with a custom implementation that adds the chance of requesting the session semantics; the original version of the system call is obviously restored when the module is removed.
The module can be compiled and installed as any other module for the Linux Kernel.
The module was tested on Linux Kernel 2.6.34, with full preemption and SMP support, on x86 machine
The folder UseCases features some examples of usage of the module.
NOTE: every time a C user program ends, the close system call is implicitely invoked on the opened files of the current process by the
exit system call: as a consequence, if a file was opened adopting the session semantics, the content of the session will be flushed into the original file as the program finishes.