<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>vfs_lock_file</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="Linux Filesystems API" /><link rel="up" href="ch01s05.html" title="File Locks" /><link rel="prev" href="re62.html" title="vfs_test_lock" /><link rel="next" href="re64.html" title="posix_unblock_lock" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span>vfs_lock_file</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="re62.html">Prev</a> </td><th width="60%" align="center">File Locks</th><td width="20%" align="right"> <a accesskey="n" href="re64.html">Next</a></td></tr></table><hr /></div><div class="refentry" title="vfs_lock_file"><a id="API-vfs-lock-file"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>vfs_lock_file — file byte range lock </p></div><div class="refsynopsisdiv" title="Synopsis"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><tr><td><code class="funcdef">int <b class="fsfunc">vfs_lock_file </b>(</code></td><td>struct file * <var class="pdparam">filp</var>, </td></tr><tr><td> </td><td>unsigned int <var class="pdparam">cmd</var>, </td></tr><tr><td> </td><td>struct file_lock * <var class="pdparam">fl</var>, </td></tr><tr><td> </td><td>struct file_lock * <var class="pdparam">conf</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1" title="Arguments"><a id="id3105543"></a><h2>Arguments</h2><div class="variablelist"><dl><dt><span class="term"><em class="parameter"><code>filp</code></em></span></dt><dd><p> The file to apply the lock to </p></dd><dt><span class="term"><em class="parameter"><code>cmd</code></em></span></dt><dd><p> type of locking operation (F_SETLK, F_GETLK, etc.) </p></dd><dt><span class="term"><em class="parameter"><code>fl</code></em></span></dt><dd><p> The lock to be applied </p></dd><dt><span class="term"><em class="parameter"><code>conf</code></em></span></dt><dd><p> Place to return a copy of the conflicting lock, if found. </p></dd></dl></div></div><div class="refsect1" title="Description"><a id="id3105620"></a><h2>Description</h2><p> A caller that doesn't care about the conflicting lock may pass NULL as the final argument. </p><p> If the filesystem defines a private -><code class="function">lock</code> method, then <em class="parameter"><code>conf</code></em> will be left unchanged; so a caller that cares should initialize it to some acceptable default. </p><p> To avoid blocking kernel daemons, such as lockd, that need to acquire POSIX locks, the -><code class="function">lock</code> interface may return asynchronously, before the lock has been granted or denied by the underlying filesystem, if (and only if) fl_grant is set. Callers expecting -><code class="function">lock</code> to return asynchronously will only use F_SETLK, not F_SETLKW; they will set FL_SLEEP if (and only if) the request is for a blocking lock. When -><code class="function">lock</code> does return asynchronously, it must return FILE_LOCK_DEFERRED, and call -><code class="function">fl_grant</code> when the lock request completes. If the request is for non-blocking lock the file system should return FILE_LOCK_DEFERRED then try to get the lock and call the callback routine with the result. If the request timed out the callback routine will return a nonzero return code and the file system should release the lock. The file system is also responsible to keep a corresponding posix lock when it grants a lock so the VFS can find out which locks are locally held and do the correct lock cleanup when required. The underlying filesystem must not drop the kernel lock or call -><code class="function">fl_grant</code> before returning to the caller with a FILE_LOCK_DEFERRED return code. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="re62.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch01s05.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="re64.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span>vfs_test_lock</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span>posix_unblock_lock</span></td></tr></table></div></body></html>