- Timestamp:
- May 23, 2008, 6:56:41 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.0/docs/htmldocs/Samba3-Developers-Guide/vfs.html
r44 r134 1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 10. VFS Modules</title><link rel="stylesheet" href="samba.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.0"><link rel="start" href="index.html" title="SAMBA Developers Guide"><link rel="up" href="pt03.html" title="Part III. Samba Subsystems"><link rel="prev" href="rpc-plugin.html" title="Chapter 9. RPC Pluggable Modules"><link rel="next" href="parsing.html" title="Chapter 11. The smb.conf file"></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">Chapter 10. VFS Modules</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="rpc-plugin.html">Prev</a> </td><th width="60%" align="center">Part III. Samba Subsystems</th><td width="20%" align="right"> <a accesskey="n" href="parsing.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="vfs"></a>Chapter 10. VFS Modules</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Alexander</span> <span class="surname">Bokovoy</span></h3><div class="affiliation"><div class="address"><p><code class="email"><<a href="mailto:ab@samba.org">ab@samba.org</a>></code></p></div></div></div></div><div><div class="author"><h3 class="author"><span class="firstname">Stefan</span> <span class="surname">Metzmacher</span></h3><div class="affiliation"><div class="address"><p><code class="email"><<a href="mailto:metze@samba.org">metze@samba.org</a>></code></p></div></div></div></div><div><p class="pubdate"> 27 May 2003 </p></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="vfs.html#id324691">The Samba (Posix) VFS layer</a></span></dt><dd><dl><dt><span class="sect2"><a href="vfs.html#id324696">The general interface</a></span></dt><dt><span class="sect2"><a href="vfs.html#id324766">Possible VFS operation layers</a></span></dt></dl></dd><dt><span class="sect1"><a href="vfs.html#id324811">The Interaction between the Samba VFS subsystem and the modules</a></span></dt><dd><dl><dt><span class="sect2"><a href="vfs.html#id324817">Initialization and registration</a></span></dt><dt><span class="sect2"><a href="vfs.html#id324954">How the Modules handle per connection data</a></span></dt></dl></dd><dt><span class="sect1"><a href="vfs.html#id325112">Upgrading to the New VFS Interface</a></span></dt><dd><dl><dt><span class="sect2"><a href="vfs.html#id325117">Upgrading from 2.2.* and 3.0aplha modules</a></span></dt></dl></dd><dt><span class="sect1"><a href="vfs.html#id325448">Some Notes</a></span></dt><dd><dl><dt><span class="sect2"><a href="vfs.html#id325454">Implement TRANSPARENT functions</a></span></dt><dt><span class="sect2"><a href="vfs.html#id325472">Implement OPAQUE functions</a></span></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id324691"></a>The Samba (Posix) VFS layer</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id324696"></a>The general interface</h3></div></div></div><p> 2 Each VFS operation has a vfs_op_type, a function pointer and a handle pointer in the 3 struct vfs_ops and tree macros to make it easier to call the operations. 4 (Take a look at <code class="filename">include/vfs.h</code> and <code class="filename">include/vfs_macros.h</code>.) 1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 10. VFS Modules</title><link rel="stylesheet" href="../samba.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="SAMBA Developers Guide"><link rel="up" href="pt03.html" title="Part III. Samba Subsystems"><link rel="prev" href="rpc-plugin.html" title="Chapter 9. RPC Pluggable Modules"><link rel="next" href="parsing.html" title="Chapter 11. The smb.conf file"></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">Chapter 10. VFS Modules</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="rpc-plugin.html">Prev</a> </td><th width="60%" align="center">Part III. Samba Subsystems</th><td width="20%" align="right"> <a accesskey="n" href="parsing.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="vfs"></a>Chapter 10. VFS Modules</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Alexander</span> <span class="surname">Bokovoy</span></h3><div class="affiliation"><div class="address"><p><code class="email"><<a class="email" href="mailto:ab@samba.org">ab@samba.org</a>></code></p></div></div></div></div><div><div class="author"><h3 class="author"><span class="firstname">Stefan</span> <span class="surname">Metzmacher</span></h3><div class="affiliation"><div class="address"><p><code class="email"><<a class="email" href="mailto:metze@samba.org">metze@samba.org</a>></code></p></div></div></div></div><div><p class="pubdate"> 27 May 2003 </p></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="vfs.html#id348426">The Samba (Posix) VFS layer</a></span></dt><dd><dl><dt><span class="sect2"><a href="vfs.html#id348454">The general interface</a></span></dt><dt><span class="sect2"><a href="vfs.html#id348708">Possible VFS operation layers</a></span></dt></dl></dd><dt><span class="sect1"><a href="vfs.html#id348752">The Interaction between the Samba VFS subsystem and the modules</a></span></dt><dd><dl><dt><span class="sect2"><a href="vfs.html#id348758">Initialization and registration</a></span></dt><dt><span class="sect2"><a href="vfs.html#id348885">How the Modules handle per connection data</a></span></dt></dl></dd><dt><span class="sect1"><a href="vfs.html#id349039">Upgrading to the New VFS Interface</a></span></dt><dd><dl><dt><span class="sect2"><a href="vfs.html#id349044">Upgrading from 2.2.* and 3.0aplha modules</a></span></dt></dl></dd><dt><span class="sect1"><a href="vfs.html#id349344">Some Notes</a></span></dt><dd><dl><dt><span class="sect2"><a href="vfs.html#id349350">Implement TRANSPARENT functions</a></span></dt><dt><span class="sect2"><a href="vfs.html#id349366">Implement OPAQUE functions</a></span></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id348426"></a>The Samba (Posix) VFS layer</h2></div></div></div><p>While most of Samba deployments are done using POSIX-compatible 2 operating systems, there is clearly more to a file system than what is 3 required by POSIX when it comes to adopting semantics of NT file 4 system. Since Samba 2.2 all file-system related operations go through 5 an abstraction layer for virtual file system (VFS) that is modelled 6 after both POSIX and additional functions needed to transform NTFS 7 semantics. 8 </p><p> 9 This abstraction layer now provides more features than a regular POSIX 10 file system could fill in. It is not required that all of them should 11 be implemented by your particular file system. However, when those 12 features are available, Samba would advertize them to a CIFS client 13 and they might be used by an application and in case of Windows client 14 that might mean a client expects even more additional functionality 15 when it encounters those features. There is a practical reason to 16 allow handling of this snowfall without modifying the Samba core and 17 it is fulfilled by providing an infrastructure to dynamically load VFS 18 modules at run time. 19 </p><p>Each VFS module could implement a number of VFS operations. The 20 way it does it is irrelevant, only two things actually matter: whether 21 specific implementation wants to cooperate with other modules' 22 implementations or not, and whether module needs to store additional 23 information that is specific to a context it is operating in. Multiple 24 VFS modules could be loaded at the same time and it is even possible 25 to load several instances of the same VFS module with different 26 parameters. 27 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id348454"></a>The general interface</h3></div></div></div><p>A VFS module has three major components: 28 </p><div class="itemizedlist"><ul type="disc"><li><span class="emphasis"><em>An initialization function</em></span> that is 29 called during the module load to register implemented 30 operations.</li><li><span class="emphasis"><em>An operations table</em></span> representing a 31 mapping between statically defined module functions and VFS layer 32 operations.</li><li><span class="emphasis"><em>Module functions</em></span> that do actual 33 work.</li></ul></div><p> 34 </p><p>While this structure has been first applied to the VFS 35 subsystem, it is now commonly used across all Samba 3 subsystems that 36 support loadable modules. In fact, one module could provide a number 37 of interfaces to different subsystems by exposing different 38 <span class="emphasis"><em>operation tables</em></span> through separate 39 <span class="emphasis"><em>initialization functions</em></span>.</p><p><span class="emphasis"><em>An initialization function</em></span> is used to 40 register module with Samba run-time. As Samba internal structures and 41 API are changed over lifetime, each released version has a VFS 42 interface version that is increased as VFS development progresses or 43 any of underlying Samba structures are changed in binary-incompatible 44 way. When VFS module is compiled in, VFS interface version of that 45 Samba environment is embedded into the module's binary object and is 46 checked by the Samba core upon module load. If VFS interface number 47 reported by the module isn't the same Samba core knows about, version 48 conflict is detected and module dropped to avoid any potential memory 49 corruption when accessing (changed) Samba structures. 50 </p><p>Therefore, initialization function passes three parameters to the 51 VFS registration function, <code class="literal">smb_register_vfs()</code> 52 </p><div class="itemizedlist"><ul type="disc"><li><span class="emphasis"><em>interface version number</em></span>, as constant 53 <code class="literal">SMB_VFS_INTERFACE_VERSION</code>, </li><li><span class="emphasis"><em>module name</em></span>, under which Samba core 54 will know it, and</li><li><span class="emphasis"><em>an operations' table</em></span>.</li></ul></div><p> 55 </p><p>The <span class="emphasis"><em>operations' table</em></span> defines which 56 functions in the module would correspond to specific VFS operations 57 and how those functions would co-operate with the rest of VFS 58 subsystem. Each operation could perform in a following ways: 59 </p><div class="itemizedlist"><ul type="disc"><li><span class="emphasis"><em>transparent</em></span>, meaning that while 60 operation is overriden, the module will still call a previous 61 implementation, before or after its own action. This mode is 62 indicated by the constant 63 <code class="literal">SMB_VFS_LAYER_TRANSPARENT</code>; 64 </li><li><span class="emphasis"><em>opaque</em></span>, for the implementations that 65 are terminating sequence of actions. For example, it is used to 66 implement POSIX operation on top of non-POSIX file system or even 67 not a file system at all, like a database for a personal audio 68 collection. Use constant <code class="literal">SMB_VFS_LAYER_OPAQUE</code> for 69 this mode;</li><li><span class="emphasis"><em>splitter</em></span>, a way when some file system 70 activity is done in addition to the transparently calling previous 71 implentation. This usually involves mangling the result of that call 72 before returning it back to the caller. This mode is selected by 73 <code class="literal">SMB_VFS_LAYER_SPLITTER</code> constant;</li><li><span class="emphasis"><em>logger</em></span> does not change anything or 74 performs any additional VFS operations. When 75 <span class="emphasis"><em>logger</em></span> module acts, information about 76 operations is logged somewhere using an external facility (or 77 Samba's own debugging tools) but not the VFS layer. In order to 78 describe this type of activity use constant 79 <code class="literal">SMB_VFS_LAYER_LOGGER</code>; 80 </li><li>On contrary, <span class="emphasis"><em>scanner</em></span> module does call 81 other VFS operations while processing the data that goes through the 82 system. This type of operation is indicated by the 83 <code class="literal">SMB_VFS_LAYER_SCANNER</code> constant.</li></ul></div><p> 84 </p><p>Fundamentally, there are three types: 85 <span class="emphasis"><em>transparent</em></span>, <span class="emphasis"><em>opaque</em></span>, and 86 <span class="emphasis"><em>logger</em></span>. <span class="emphasis"><em>Splitter</em></span> and 87 <span class="emphasis"><em>scanner</em></span> may confuse developers (and indeed they 88 are confused as our experience has shown) but this separation is to 89 better expose the nature of a module's actions. Most of modules 90 developed so far are either one of those three fundamental types with 91 transparent and opaque being prevalent. 92 </p><p> 93 Each VFS operation has a vfs_op_type, a function pointer and a handle 94 pointer in the struct vfs_ops and tree macros to make it easier to 95 call the operations. (Take a look at 96 <code class="filename">include/vfs.h</code> and 97 <code class="filename">include/vfs_macros.h</code>.) 5 98 </p><pre class="programlisting"> 6 99 typedef enum _vfs_op_type { … … 95 188 96 189 ... 97 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id3 24766"></a>Possible VFS operation layers</h3></div></div></div><p>190 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id348708"></a>Possible VFS operation layers</h3></div></div></div><p> 98 191 These values are used by the VFS subsystem when building the conn->vfs 99 192 and conn->vfs_opaque structs for a connection with multiple VFS modules. … … 124 217 /* file activity like logging to files _inside_ samba VFS */ 125 218 } vfs_op_layer; 126 </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id3 24811"></a>The Interaction between the Samba VFS subsystem and the modules</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id324817"></a>Initialization and registration</h3></div></div></div><p>219 </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id348752"></a>The Interaction between the Samba VFS subsystem and the modules</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id348758"></a>Initialization and registration</h3></div></div></div><p> 127 220 As each Samba module a VFS module should have a 128 221 </p><pre class="programlisting">NTSTATUS vfs_example_init(void);</pre><p> function if it's staticly linked to samba or … … 164 257 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "example", example_op_tuples); 165 258 } 166 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id3 24954"></a>How the Modules handle per connection data</h3></div></div></div><p>Each VFS function has as first parameter a pointer to the modules vfs_handle_struct.259 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id348885"></a>How the Modules handle per connection data</h3></div></div></div><p>Each VFS function has as first parameter a pointer to the modules vfs_handle_struct. 167 260 </p><pre class="programlisting"> 168 261 typedef struct vfs_handle_struct { … … 265 358 (tofd), (fsp), (fromfd), (header), (offset), (count))) 266 359 ... 267 </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id3 25112"></a>Upgrading to the New VFS Interface</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id325117"></a>Upgrading from 2.2.* and 3.0aplha modules</h3></div></div></div><div class="orderedlist"><ol type="1"><li><p>360 </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id349039"></a>Upgrading to the New VFS Interface</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id349044"></a>Upgrading from 2.2.* and 3.0aplha modules</h3></div></div></div><div class="orderedlist"><ol type="1"><li><p> 268 361 Add "vfs_handle_struct *handle, " as first parameter to all vfs operation functions. 269 362 e.g. example_connect(connection_struct *conn, const char *service, const char *user); … … 389 482 (Only for 3.0alpha* modules) 390 483 Check if your vfs_done() function contains needed code. 391 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>If NOT you can remove the vfs_done() function.</td></tr><tr><td>If YES decide if you can move the code to the example_disconnect() operation. Otherwise register a SMB_EXIT_EVENT with smb_register_exit_event(); (Described in the <a href="modules.html" title="Chapter 8. Modules">modules section</a>) And then remove vfs_done(). e.g. the freeing of private data should go to example_disconnect().484 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>If NOT you can remove the vfs_done() function.</td></tr><tr><td>If YES decide if you can move the code to the example_disconnect() operation. Otherwise register a SMB_EXIT_EVENT with smb_register_exit_event(); (Described in the <a class="link" href="modules.html" title="Chapter 8. Modules">modules section</a>) And then remove vfs_done(). e.g. the freeing of private data should go to example_disconnect(). 392 485 </td></tr></table><p> 393 486 </p></li><li><p> … … 528 621 Compiling & Testing... 529 622 </p><table class="simplelist" border="0" summary="Simple list"><tr><td><strong class="userinput"><code>./configure <code class="option">--enable-developer</code></code></strong> ...</td></tr><tr><td><strong class="userinput"><code>make</code></strong></td></tr><tr><td>Try to fix all compiler warnings</td></tr><tr><td><strong class="userinput"><code>make</code></strong></td></tr><tr><td>Testing, Testing, Testing ...</td></tr></table><p> 530 </p></li></ol></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id3 25448"></a>Some Notes</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id325454"></a>Implement TRANSPARENT functions</h3></div></div></div><p>623 </p></li></ol></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id349344"></a>Some Notes</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id349350"></a>Implement TRANSPARENT functions</h3></div></div></div><p> 531 624 Avoid writing functions like this: 532 625 … … 539 632 540 633 Overload only the functions you really need to! 541 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id3 25472"></a>Implement OPAQUE functions</h3></div></div></div><p>634 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id349366"></a>Implement OPAQUE functions</h3></div></div></div><p> 542 635 If you want to just implement a better version of a 543 636 default samba opaque function
Note:
See TracChangeset
for help on using the changeset viewer.