Update Red Hat Copyright Notices
[nbdkit.git] / plugins / file / nbdkit-file-plugin.pod
blob857ad21e6999477482da76f4dfe8327ebe5d14be
1 =head1 NAME
3 nbdkit-file-plugin - nbdkit file plugin
5 =head1 SYNOPSIS
7  nbdkit file [file=]FILENAME
8              [cache=default|none] [fadvise=normal|random|sequential]
10 =for paragraph
12  nbdkit file dir=DIRECTORY
14 =for paragraph
16  nbdkit file fd=FILE_DESCRIPTOR
18 =for paragraph
20  nbdkit file dirfd=FILE_DESCRIPTOR
22 =head1 DESCRIPTION
24 C<nbdkit-file-plugin> is a file serving plugin for L<nbdkit(1)>.
26 It serves the named C<FILENAME> over NBD.  Local block devices
27 (eg. F</dev/sda>) may also be served.
29 If you use the C<dir> parameter the plugin works in a different mode
30 where it serves files from the given C<DIRECTORY>, chosen by the
31 client using the NBD export name.
33 If you use the C<fd> or C<dirfd> parameter then you can pass the file
34 descriptor of a single disk or a directory to the plugin, inherited
35 from the parent process.  This can be useful where special permissions
36 or capabilities are needed to open the file descriptor, or you want to
37 run nbdkit in a sandboxed environment.
39 =head1 PARAMETERS
41 Exactly one of B<file>, B<dir>, B<fd> or B<dirfd> must be given.  This
42 controls the mode of the plugin, either serving a single file, the
43 files in a directory, a single file descriptor, or the files in the
44 directory of the file descriptor.
46 =over 4
48 =item B<cache=default>
50 =item B<cache=none>
52 (nbdkit E<ge> 1.22, not Windows)
54 Using C<cache=none> tries to prevent the kernel from keeping parts of
55 the file that have already been read or written in the page cache.
57 =item B<dir=>DIRECTORY
59 (nbdkit E<ge> 1.22, not Windows)
61 Serve all regular files and block devices located directly inside the
62 directory named C<DIRECTORY>, including those found by following
63 symbolic links.  Other special files in the directory (such as
64 subdirectories, pipes, or Unix sockets) are ignored.
66 When this mode is used, the file to be served is chosen by the export
67 name passed by the client, where the client can request a list of
68 available exports using NBD_OPT_LIST.  A client that requests the
69 default export (C<"">) will be rejected.  However, you can use
70 L<nbdkit-exportname-filter(1)> to adjust what export names the client
71 sees or uses as a default.  For security, when using directory mode,
72 this plugin will not accept export names containing slash (C</>).
74 =item B<dirfd=>FILE_DESCRIPTOR
76 (nbdkit E<ge> 1.34, not Windows)
78 This is like the I<dir> option, but instead of specifying the
79 directory by name, the parent process should open the directory and
80 pass this file descriptor by inheritance to nbdkit.
82 =item B<fadvise=normal>
84 =item B<fadvise=random>
86 =item B<fadvise=sequential>
88 (nbdkit E<ge> 1.22, not Windows)
90 This optional flag hints to the kernel that you will access the file
91 normally, or in a random order, or sequentially.  The exact behaviour
92 depends on your operating system, but for Linux using C<normal> causes
93 the kernel to read-ahead, C<sequential> causes the kernel to
94 read-ahead twice as much as C<normal>, and C<random> turns off
95 read-ahead.  See also L<posix_fadvise(2)>.
97 The default is C<normal>.
99 =item B<fd=>FILE_DESCRIPTOR
101 (nbdkit E<ge> 1.34, not Windows)
103 The parameter is the number of a file descriptor.  Serve the file or
104 device already open on this file descriptor.  The file descriptor is
105 usually inherited from the parent process.
107 =item [B<file=>]FILENAME
109 Serve the file named C<FILENAME>.  A local block device name can also
110 be used here.  When this mode is used, the export name requested by
111 the client is ignored.
113 C<file=> is a magic config key and may be omitted in most cases.
114 See L<nbdkit(1)/Magic parameters>.
116 =item [B<file=>]B<\\.\>CB<:>
118 =item [B<file=>]B<\\.\>Volume
120 =item [B<file=>]B<\\.\PhysicalDisk>I<N>
122 =item [B<file=>]B<\\.\CdRom>I<N>
124 (Windows only)
126 Serve the Windows volume specified by the device name.  See:
127 L<https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-device-namespaces>.
129 =back
131 =head1 NOTES
133 =head2 Optimizing for random or sequential access
135 If you know in advance that the NBD client will access the file
136 randomly or only sequentially then you can hint that to the kernel
137 using:
139  nbdkit file disk.img fadvise=random
140  nbdkit file disk.img fadvise=sequential
142 As described in the L</PARAMETERS> section above, on Linux this
143 disables or increases the amount of read-ahead that the kernel does.
145 =head2 Reducing evictions from the page cache
147 If the file is very large and you know the client will only read/write
148 the file sequentially one time (eg for making a single copy or backup)
149 then this will stop other processes from being evicted from the page
150 cache:
152  nbdkit file disk.img fadvise=sequential cache=none
154 Only use fadvise=sequential if reading, and the reads are mainly
155 sequential.
157 =head2 Files on tmpfs
159 If you want to expose a file that resides on a file system known to
160 have poor C<lseek(2)> performance when searching for holes (C<tmpfs>
161 is known to be one such file system), you can use
162 L<nbdkit-noextents-filter(1)> to avoid the penalty of probing for
163 holes.
165 =head2 Plugin I<--dump-plugin> output
167 You can obtain extra information about how the file plugin was
168 compiled by doing:
170  nbdkit file --dump-plugin
172 Some of the fields which may appear are listed below.  Note these are
173 for information only and may be changed or removed at any time in the
174 future.
176 =over 4
178 =item C<file_blksszget=yes>
180 =item C<file_blkzeroout=yes>
182 If both set, the plugin may be able to efficiently zero ranges of
183 block devices, where the driver and block device itself supports this.
185 =item C<file_extents=yes>
187 If set, the plugin can read file extents.
189 =item C<file_falloc_fl_punch_hole=yes>
191 If set, the plugin may be able to punch holes (make sparse) files and
192 block devices.
194 =item C<file_falloc_fl_zero_range=yes>
196 If set, the plugin may be able to efficiently zero ranges of files and
197 block devices.
199 =item C<winfile=yes>
201 If present, this is the Windows version of the file plugin with
202 reduced functionality and some special Windows-only features, as noted
203 in this manual.
205 =back
207 =head2 Windows sparse files
209 This plugin supports sparse files on Windows (with hole punching).
210 However for this to work the files must already have the sparse
211 property, the plugin will not make existing files sparse.  Use the
212 S<C<fsutil sparse>> command to control the sparseness property of
213 files.
215 =head2 Old C<rdelay> and C<wdelay> parameters.
217 Before nbdkit supported filters (E<lt> 1.2) this plugin had extra
218 parameters C<rdelay> and C<wdelay> to insert delays.  These parameters
219 have been moved to L<nbdkit-delay-filter(1)>.  Modify the command line
220 to add I<--filter=delay> in order to use these parameters.
222 =head2 Concatenating files
224 To concatenate and export multiple files, use
225 L<nbdkit-split-plugin(1)>.
227 =head1 DEBUG FLAG
229 =over 4
231 =item B<-D file.zero=1>
233 This enables very verbose debugging of the NBD zero request.  This can
234 be used to tell if the file plugin is able to zero ranges in the file
235 or block device efficiently or not.
237 =back
239 =head1 FILES
241 =over 4
243 =item F<$plugindir/nbdkit-file-plugin.so>
245 The plugin.
247 Use C<nbdkit --dump-config> to find the location of C<$plugindir>.
249 =back
251 =head1 VERSION
253 C<nbdkit-file-plugin> first appeared in nbdkit 1.0.
255 =head1 SEE ALSO
257 L<nbdkit(1)>,
258 L<nbdkit-plugin(3)>,
259 L<nbdkit-split-plugin(1)>,
260 L<nbdkit-partitioning-plugin(1)>,
261 L<nbdkit-tmpdisk-plugin(1)>,
262 L<nbdkit-exportname-filter(1)>,
263 L<nbdkit-fua-filter(1)>,
264 L<nbdkit-luks-filter(1)>,
265 L<nbdkit-noextents-filter(1)>.
267 =head1 AUTHORS
269 Eric Blake
271 Nir Soffer
273 Richard W.M. Jones
275 =head1 COPYRIGHT
277 Copyright Red Hat