MAP_MFT_RECORD

Section: ()
Updated: 06 October 2005
Index Return to Main Contents

 

NAME

map_mft_record - map, pin and lock an mft record  

SYNOPSIS

"SYNOPSIS"

MFT_RECORD * map_mft_record (ntfs_inode * ni);  

ARGUMENTS

ni
ntfs inode whose MFT record to map
 

DESCRIPTION

First, take the mrec_lock semaphore. We might now be sleeping, while waiting for the semaphore if it was already locked by someone else.

The page of the record is mapped using map_mft_record_page before being returned to the caller.

This in turn uses ntfs_map_page to get the page containing the wanted mft record (it in turn calls read_cache_page which reads it in from disk if necessary, increments the use count on the page so that it cannot disappear under us and returns a reference to the page cache page).

If read_cache_page invokes ntfs_readpage to load the page from disk, it sets PG_locked and clears PG_uptodate on the page. Once I/O has completed and the post-read mst fixups on each mft record in the page have been performed, the page gets PG_uptodate set and PG_locked cleared (this is done in our asynchronous I/O completion handler end_buffer_read_mft_async). ntfs_map_page waits for PG_locked to become clear and checks if PG_uptodate is set and returns an error code if not. This provides sufficient protection against races when reading/using the page.

However there is the write mapping to think about. Doing the above described checking here will be fine, because when initiating the write we will set PG_locked and clear PG_uptodate making sure nobody is touching the page contents. Doing the locking this way means that the commit to disk code in the page cache code paths is automatically sufficiently locked with us as we will not touch a page that has been locked or is not uptodate. The only locking problem then is them locking the page while we are accessing it.

So that code will end up having to own the mrec_lock of all mft records/inodes present in the page before I/O can proceed. In that case we wouldn't need to bother with PG_locked and PG_uptodate as nobody will be accessing anything without owning the mrec_lock semaphore. But we do need to use them because of the read_cache_page invocation and the code becomes so much simpler this way that it is well worth it.

The mft record is now ours and we return a pointer to it. You need to check the returned pointer with IS_ERR and if that is true, PTR_ERR will return the error code.  

NOTE

Caller is responsible for setting the mft record dirty before calling unmap_mft_record. This is obviously only necessary if the caller really modified the mft record...  

Q

Do we want to recycle one of the VFS inode state bits instead?  

A

No, the inode ones mean we want to change the mft record, not we want to write it out.


 

Index

NAME
SYNOPSIS
ARGUMENTS
DESCRIPTION
NOTE
Q
A

This document was created by man2html, using the manual pages.
Time: 05:30:45 GMT, October 06, 2005