1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
=head1 NAME
nbdkit-file-plugin - nbdkit file plugin
=head1 SYNOPSIS
nbdkit file [file=]FILENAME
[cache=default|none] [fadvise=normal|random|sequential]
=for paragraph
nbdkit file dir=DIRECTORY
=for paragraph
nbdkit file fd=FILE_DESCRIPTOR
=for paragraph
nbdkit file dirfd=FILE_DESCRIPTOR
=head1 DESCRIPTION
C<nbdkit-file-plugin> is a file serving plugin for L<nbdkit(1)>.
It serves the named C<FILENAME> over NBD. Local block devices
(eg. F</dev/sda>) may also be served.
If you use the C<dir> parameter the plugin works in a different mode
where it serves files from the given C<DIRECTORY>, chosen by the
client using the NBD export name.
If you use the C<fd> or C<dirfd> parameter then you can pass the file
descriptor of a single disk or a directory to the plugin, inherited
from the parent process. This can be useful where special permissions
or capabilities are needed to open the file descriptor, or you want to
run nbdkit in a sandboxed environment.
The file is writable unless either the I<-r> command line option, or
L<nbdkit-readonly-filter(1)> is used.
=head1 PARAMETERS
Exactly one of B<file>, B<dir>, B<fd> or B<dirfd> must be given. This
controls the mode of the plugin, either serving a single file, the
files in a directory, a single file descriptor, or the files in the
directory of the file descriptor.
=over 4
=item B<cache=default>
=item B<cache=none>
(nbdkit E<ge> 1.22, not Windows)
If the file is very large and the plugin will read or write the whole
file, this can cause the file to be cached in memory (in the page
cache on Linux), causing other files and processes to be evicted,
leading to overall slow system performance. If you know that the file
will only be read/written once and will not be needed afterwards so
caching it is pointless, use C<cache=none>. This causes reads and
writes to minimize use of the page cache. The default is to use the
kernel's default page cache strategy.
See also C<fadvise> below which can be used to hint the access
pattern.
=item B<dir=>DIRECTORY
(nbdkit E<ge> 1.22, not Windows)
Serve all regular files and block devices located directly inside the
directory named C<DIRECTORY>, including those found by following
symbolic links. Other special files in the directory (such as
subdirectories, pipes, or Unix sockets) are ignored.
See L</Serving multiple files and block devices> below.
=item B<dirfd=>FILE_DESCRIPTOR
(nbdkit E<ge> 1.34, not Windows)
This is like the C<dir=> option, but instead of specifying the
directory by name, the parent process should open the directory and
pass this file descriptor by inheritance to nbdkit.
See L</Serving multiple files and block devices> below.
=item B<fadvise=normal>
=item B<fadvise=random>
=item B<fadvise=sequential>
(nbdkit E<ge> 1.22, not Windows)
This optional flag hints to the kernel that you will access the file
normally, or in a random order, or sequentially. The exact behaviour
depends on your operating system, but for Linux using C<normal> causes
the kernel to read-ahead, C<sequential> causes the kernel to
read-ahead twice as much as C<normal>, and C<random> turns off
read-ahead. See also L<posix_fadvise(2)>.
The default is C<normal>.
=item B<fd=>FILE_DESCRIPTOR
(nbdkit E<ge> 1.34, not Windows)
The parameter is the number of a file descriptor. Serve the file or
device already open on this file descriptor. The file descriptor is
usually inherited from the parent process.
=item [B<file=>]FILENAME
Serve the file named C<FILENAME>. A local block device name can also
be used here. When this mode is used, the export name requested by
the client is ignored.
C<file=> __IS_MAGIC__
=item [B<file=>]B<\\.\>CB<:>
=item [B<file=>]B<\\.\>Volume
=item [B<file=>]B<\\.\PhysicalDisk>I<N>
=item [B<file=>]B<\\.\CdRom>I<N>
(Windows only)
Serve the Windows volume specified by the device name. See:
L<https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-device-namespaces>.
=back
=head1 NOTES
=head2 Serving multiple files and block devices
Using C<dir=DIRECTORY> (or C<dirfd=DIRFD>) you can serve all regular
files and block devices located directly inside the directory named
C<DIRECTORY>, including those found by following symbolic links.
Other special files in the directory (such as subdirectories, pipes,
or Unix sockets) are ignored.
When this mode is used, the file to be served is chosen by the export
name passed by the client. For security, when using directory mode,
this plugin will not accept export names containing slash (C</>).
For example:
$ ls -l /var/tmp/exports
total 0
-rw-r--r--. 1 rjones rjones 1048576 Dec 14 15:34 disk1
-rw-r--r--. 1 rjones rjones 2097152 Dec 14 15:34 disk2
lrwxrwxrwx. 1 rjones rjones 9 Dec 14 15:35 sda1 -> /dev/sda1
$ nbdkit file dir=/var/tmp/exports
will serve three exports called C<"disk1">, C<"disk2"> and C<"sda1">.
The first two are regular files and the last is a block device. You
can add or remove files or symbolic links from the directory while
nbdkit is running.
To list exports, use L<nbdinfo(1)> I<--list> option, for example:
$ nbdinfo --list nbd://localhost
protocol: newstyle-fixed without TLS, using structured packets
export="disk1":
export-size: 1048576 (1M)
uri: nbd://localhost:10809/disk1
[etc]
An NBD client can request a list of available exports using
C<NBD_OPT_LIST>. For libnbd clients see nbd_opt_list(3).
A client that requests the default export (C<"">) will be rejected.
However, you can use L<nbdkit-exportname-filter(1)> to adjust the
default export as well as other transformations of export names. For
example to make F</var/tmp/exports/disk1> be the default export:
nbdkit file dir=/var/tmp/exports \
--filter=exportname default-export=disk1
=head2 Optimizing for random or sequential access
If you know in advance that the NBD client will access the file
randomly or only sequentially then you can hint that to the kernel
using:
nbdkit file disk.img fadvise=random
nbdkit file disk.img fadvise=sequential
As described in the L</PARAMETERS> section above, on Linux this
disables or increases the amount of read-ahead that the kernel does.
=head2 Files on tmpfs
If you want to expose a file that resides on a file system known to
have poor C<lseek(2)> performance when searching for holes (C<tmpfs>
is known to be one such file system), you can use
L<nbdkit-noextents-filter(1)> to avoid the penalty of probing for
holes.
=head2 Plugin I<--dump-plugin> output
You can obtain extra information about how the file plugin was
compiled by doing:
nbdkit file --dump-plugin
Some of the fields which may appear are listed below. Note these are
for information only and may be changed or removed at any time in the
future.
=over 4
=item C<file_block_size=yes>
If set, the plugin has support for getting the minimum and preferred
I/O size of block devices.
=item C<file_blkrotational=yes>
If set, the plugin has support for getting the rotational property of
block devices.
=item C<file_blksszget=yes>
=item C<file_blkzeroout=yes>
If both set, the plugin may be able to efficiently zero ranges of
block devices, where the driver and block device itself supports this.
=item C<file_blkdiscard=yes>
If set, the plugin may be able to efficiently trim ranges of block
devices, where the driver and block device itself supports this.
=item C<file_extents=yes>
If set, the plugin can read file extents.
=item C<file_falloc_fl_punch_hole=yes>
If set, the plugin may be able to punch holes (make sparse) files and
block devices.
=item C<file_falloc_fl_zero_range=yes>
If set, the plugin may be able to efficiently zero ranges of files and
block devices.
=item C<winfile=yes>
If present, this is the Windows version of the file plugin with
reduced functionality and some special Windows-only features, as noted
in this manual.
=back
=head2 Windows sparse files
This plugin supports sparse files on Windows (with hole punching).
However for this to work the files must already have the sparse
property, the plugin will not make existing files sparse. Use the
S<C<fsutil sparse>> command to control the sparseness property of
files.
=head2 Old C<rdelay> and C<wdelay> parameters.
Before nbdkit supported filters (E<lt> 1.2) this plugin had extra
parameters C<rdelay> and C<wdelay> to insert delays. These parameters
have been moved to L<nbdkit-delay-filter(1)>. Modify the command line
to add I<--filter=delay> in order to use these parameters.
=head2 Concatenating files
To concatenate and export multiple files, use
L<nbdkit-split-plugin(1)>.
=head1 DEBUG FLAG
=over 4
=item B<-D file.zero=1>
This enables very verbose debugging of the NBD zero request. This can
be used to tell if the file plugin is able to zero ranges in the file
or block device efficiently or not.
=back
=head1 FILES
=over 4
=item F<$plugindir/nbdkit-file-plugin.so>
The plugin.
Use C<nbdkit --dump-config> to find the location of C<$plugindir>.
=back
=head1 VERSION
C<nbdkit-file-plugin> first appeared in nbdkit 1.0.
=head1 SEE ALSO
L<nbdkit(1)>,
L<nbdkit-plugin(3)>,
L<nbdkit-split-plugin(1)>,
L<nbdkit-partitioning-plugin(1)>,
L<nbdkit-tmpdisk-plugin(1)>,
L<nbdkit-exportname-filter(1)>,
L<nbdkit-fua-filter(1)>,
L<nbdkit-luks-filter(1)>,
L<nbdkit-noextents-filter(1)>,
L<nbdkit-readonly-filter(1)>,
L<nbdinfo(1)>.
=head1 AUTHORS
Eric Blake
Nir Soffer
Richard W.M. Jones
=head1 COPYRIGHT
Copyright Red Hat
|