1<html><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.78.1"><link rel="home" href="index.html" title="Linux Filesystems API"><link rel="up" href="file_locks.html" title="File Locks"><link rel="prev" href="API-vfs-test-lock.html" title="vfs_test_lock"><link rel="next" href="API-posix-unblock-lock.html" title="posix_unblock_lock"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">vfs_lock_file</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-vfs-test-lock.html">Prev</a> </td><th width="60%" align="center">File Locks</th><td width="20%" align="right"> <a accesskey="n" href="API-posix-unblock-lock.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-vfs-lock-file"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>vfs_lock_file — 2 file byte range lock 3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><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"><a name="idp1102039356"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>filp</code></em></span></dt><dd><p> 4 The file to apply the lock to 5 </p></dd><dt><span class="term"><em class="parameter"><code>cmd</code></em></span></dt><dd><p> 6 type of locking operation (F_SETLK, F_GETLK, etc.) 7 </p></dd><dt><span class="term"><em class="parameter"><code>fl</code></em></span></dt><dd><p> 8 The lock to be applied 9 </p></dd><dt><span class="term"><em class="parameter"><code>conf</code></em></span></dt><dd><p> 10 Place to return a copy of the conflicting lock, if found. 11 </p></dd></dl></div></div><div class="refsect1"><a name="idp1102043980"></a><h2>Description</h2><p> 12 A caller that doesn't care about the conflicting lock may pass NULL 13 as the final argument. 14 </p><p> 15 16 If the filesystem defines a private -><code class="function">lock</code> method, then <em class="parameter"><code>conf</code></em> will 17 be left unchanged; so a caller that cares should initialize it to 18 some acceptable default. 19 </p><p> 20 21 To avoid blocking kernel daemons, such as lockd, that need to acquire POSIX 22 locks, the -><code class="function">lock</code> interface may return asynchronously, before the lock has 23 been granted or denied by the underlying filesystem, if (and only if) 24 lm_grant is set. Callers expecting -><code class="function">lock</code> to return asynchronously 25 will only use F_SETLK, not F_SETLKW; they will set FL_SLEEP if (and only if) 26 the request is for a blocking lock. When -><code class="function">lock</code> does return asynchronously, 27 it must return FILE_LOCK_DEFERRED, and call -><code class="function">lm_grant</code> when the lock 28 request completes. 29 If the request is for non-blocking lock the file system should return 30 FILE_LOCK_DEFERRED then try to get the lock and call the callback routine 31 with the result. If the request timed out the callback routine will return a 32 nonzero return code and the file system should release the lock. The file 33 system is also responsible to keep a corresponding posix lock when it 34 grants a lock so the VFS can find out which locks are locally held and do 35 the correct lock cleanup when required. 36 The underlying filesystem must not drop the kernel lock or call 37 -><code class="function">lm_grant</code> before returning to the caller with a FILE_LOCK_DEFERRED 38 return code. 39</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-vfs-test-lock.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="file_locks.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-posix-unblock-lock.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">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 class="phrase">posix_unblock_lock</span></td></tr></table></div></body></html> 40