maint: Slightly improve git.orderfile
[nbdkit/ericb.git] / docs / nbdkit-filter.pod
blob6e2bea61f9db036b88066a06f5bf10622645cc3e
1 =head1 NAME
3 nbdkit-filter - how to write nbdkit filters
5 =head1 SYNOPSIS
7  #include <nbdkit-filter.h>
8  
9  static int
10  myfilter_config (nbdkit_next_config *next, void *nxdata,
11                   const char *key, const char *value)
12  {
13    if (strcmp (key, "myparameter") == 0) {
14      // ...
15      return 0;
16    }
17    else {
18      // pass through to next filter or plugin
19      return next (nxdata, key, value);
20    }
21  }
23  static struct nbdkit_filter filter = {
24    .name              = "filter",
25    .config            = myfilter_config,
26    /* etc */
27  };
29  NBDKIT_REGISTER_FILTER(filter)
31 When this has been compiled to a shared library, do:
33  nbdkit [--args ...] --filter=./myfilter.so plugin [key=value ...]
35 When debugging, use the I<-fv> options:
37  nbdkit -fv --filter=./myfilter.so plugin [key=value ...]
39 =head1 DESCRIPTION
41 One or more nbdkit filters can be placed in front of an nbdkit plugin
42 to modify the behaviour of the plugin.  This manual page describes how
43 to create an nbdkit filter.
45 Filters can be used for example to limit requests to an offset/limit,
46 add copy-on-write support, or inject delays or errors (for testing).
48 Different filters can be stacked:
50      NBD     ┌─────────┐    ┌─────────┐          ┌────────┐
51   client ───▶│ filter1 │───▶│ filter2 │── ─ ─ ──▶│ plugin │
52  request     └─────────┘    └─────────┘          └────────┘
54 Each filter intercepts plugin functions (see L<nbdkit-plugin(3)>) and
55 can call the next filter or plugin in the chain, modifying parameters,
56 calling before the filter function, in the middle or after.  Filters
57 may even short-cut the chain.  As an example, to process its own
58 parameters the filter can intercept the C<.config> method:
60  static int
61  myfilter_config (nbdkit_next_config *next, void *nxdata,
62                   const char *key, const char *value)
63  {
64    if (strcmp (key, "myparameter") == 0) {
65      // ...
66      // here you would handle this key, value
67      // ...
68      return 0;
69    }
70    else {
71      // pass through to next filter or plugin
72      return next (nxdata, key, value);
73    }
74  }
76  static struct nbdkit_filter filter = {
77    // ...
78    .config            = myfilter_config,
79    // ...
80  };
82 The call to C<next (nxdata, ...)> calls the C<.config> method of the
83 next filter or plugin in the chain.  In the example above any
84 instances of C<myparameter=...> on the command line would not be seen
85 by the plugin.
87 To see example filters:
88 L<https://github.com/libguestfs/nbdkit/tree/master/filters>
90 Filters must be written in C.
92 Unlike plugins, where we provide a stable ABI guarantee that permits
93 operation across version differences, filters can only be run with the
94 same version of nbdkit that they were compiled with.  The reason for
95 this is two-fold: the filter API includes access to struct
96 nbdkit_next_ops that is likely to change if new callbacks are added
97 (old nbdkit cannot safely run new filters that access new methods);
98 and if we added new methods then an old filter would not see them and
99 so they would be passed unmodified through the filter, and in some
100 cases that leads to data corruption (new nbdkit cannot safely run old
101 filters unaware of new methods).  Therefore, unlike plugins, you
102 should not expect to distribute filters separately from nbdkit.
104 =head1 C<#include E<lt>nbdkit-filter.hE<gt>>
106 All filters should start by including this header file.
108 =head1 C<struct nbdkit_filter>
110 All filters must define and register one C<struct nbdkit_filter>,
111 which contains the name of the filter and pointers to plugin methods
112 that the filter wants to intercept.
114  static struct nbdkit_filter filter = {
115    .name              = "filter",
116    .longname          = "My Filter",
117    .description       = "This is my great filter for nbdkit",
118    .config            = myfilter_config,
119    /* etc */
120  };
122  NBDKIT_REGISTER_FILTER(filter)
124 The C<.name> field is the name of the filter.  This is the only field
125 which is required.
127 =head1 NEXT PLUGIN
129 F<nbdkit-filter.h> defines three function types
130 (C<nbdkit_next_config>, C<nbdkit_next_config_complete>,
131 C<nbdkit_next_open>) and a structure called C<struct nbdkit_next_ops>.
132 These abstract the next plugin or filter in the chain.  There is also
133 an opaque pointer C<nxdata> which must be passed along when calling
134 these functions.
136 The filter’s C<.config>, C<.config_complete> and C<.open> methods may
137 only call the next C<.config>, C<.config_complete> and C<.open> method
138 in the chain (optionally for C<.config>).
140 The filter’s C<.close> method is called when an old connection closed,
141 and this has no C<next> parameter because it cannot be
142 short-circuited.
144 The filter’s other methods like C<.prepare>, C<.get_size>, C<.pread>
145 etc ― always called in the context of a connection ― are passed a
146 pointer to C<struct nbdkit_next_ops> which contains a comparable set
147 of accessors to plugin methods that can be called during a connection.
148 It is possible for a filter to issue (for example) extra read calls in
149 response to a single C<.pwrite> call.  Note that the semantics of the
150 functions in C<struct nbdkit_next_ops> are slightly different from
151 what a plugin implements: for example, when a plugin's C<.pread>
152 returns -1 on error, the error value to advertise to the client is
153 implicit (via the plugin calling C<nbdkit_set_error> or setting
154 C<errno>), whereas C<next_ops-E<gt>pread> exposes this via an explicit
155 parameter, allowing a filter to learn or modify this error if desired.
157 You can modify parameters when you call the C<next> function.  However
158 be careful when modifying strings because for some methods
159 (eg. C<.config>) the plugin may save the string pointer that you pass
160 along.  So you may have to ensure that the string is not freed for the
161 lifetime of the server.
163 Note that if your filter registers a callback but in that callback it
164 doesn't call the C<next> function then the corresponding method in the
165 plugin will never be called.  In particular, your C<.open> method, if
166 you have one, B<must> call the C<.next> method.
168 =head1 CALLBACKS
170 C<struct nbdkit_filter> has some static fields describing the filter
171 and optional callback functions which can be used to intercept plugin
172 methods.
174 =head2 C<.name>
176  const char *name;
178 This field (a string) is required, and B<must> contain only ASCII
179 alphanumeric characters and be unique amongst all filters.
181 =head2 C<.version>
183  const char *version;
185 Filters may optionally set a version string which is displayed in help
186 and debugging output.
188 =head2 C<.longname>
190  const char *longname;
192 An optional free text name of the filter.  This field is used in error
193 messages.
195 =head2 C<.description>
197  const char *description;
199 An optional multi-line description of the filter.
201 =head2 C<.load>
203  void load (void);
205 This is called once just after the filter is loaded into memory.  You
206 can use this to perform any global initialization needed by the
207 filter.
209 =head2 C<.unload>
211  void unload (void);
213 This may be called once just before the filter is unloaded from
214 memory.  Note that it's not guaranteed that C<.unload> will always be
215 called (eg. the server might be killed or segfault), so you should try
216 to make the filter as robust as possible by not requiring cleanup.
217 See also L<nbdkit-plugin(3)/SHUTDOWN>.
219 =head2 C<.config>
221  int (*config) (nbdkit_next_config *next, void *nxdata,
222                 const char *key, const char *value);
224 This intercepts the plugin C<.config> method and can be used by the
225 filter to parse its own command line parameters.  You should try to
226 make sure that command line parameter keys that the filter uses do not
227 conflict with ones that could be used by a plugin.
229 If there is an error, C<.config> should call C<nbdkit_error> with an
230 error message and return C<-1>.
232 =head2 C<.config_complete>
234  int (*config_complete) (nbdkit_next_config_complete *next, void *nxdata);
236 This intercepts the plugin C<.config_complete> method and can be used
237 to ensure that all parameters needed by the filter were supplied on
238 the command line.
240 If there is an error, C<.config_complete> should call C<nbdkit_error>
241 with an error message and return C<-1>.
243 =head2 C<.config_help>
245  const char *config_help;
247 This optional multi-line help message should summarize any
248 C<key=value> parameters that it takes.  It does I<not> need to repeat
249 what already appears in C<.description>.
251 If the filter doesn't take any config parameters you should probably
252 omit this.
254 =head2 C<.thread_model>
256  int (*thread_model) (void);
258 Filters may tighten (but not relax) the thread model of the plugin, by
259 defining this callback.  Note that while plugins use a compile-time
260 definition of C<THREAD_MODEL>, filters do not need to declare a model
261 at compile time; instead, this callback is called after
262 C<.config_complete> and before any connections are created.  See
263 L<nbdkit-plugin(3)/THREADS> for a discussion of thread models.
265 The final thread model used by nbdkit is the smallest (ie. most
266 serialized) out of all the filters and the plugin, and applies for all
267 connections.  Requests for a model larger than permitted by the plugin
268 are silently ignored. It is acceptable for decisions made during
269 C<.config> and C<.config_complete> to determine which model to
270 request.
272 This callback is optional; if it is not present, the filter must be
273 written to handle fully parallel requests, including when multiple
274 requests are issued in parallel on the same connection, similar to a
275 plugin requesting C<NBDKIT_THREAD_MODEL_PARALLEL>.  This ensures the
276 filter doesn't slow down other filters or plugins.
278 If there is an error, C<.thread_model> should call C<nbdkit_error>
279 with an error message and return C<-1>.
281 =head2 C<.open>
283  void * (*open) (nbdkit_next_open *next, void *nxdata,
284                  int readonly);
286 This is called when a new client connection is opened and can be used
287 to allocate any per-connection data structures needed by the filter.
288 The handle (which is not the same as the plugin handle) is passed back
289 to other filter callbacks and could be freed in the C<.close>
290 callback.
292 Note that the handle is completely opaque to nbdkit, but it must not
293 be NULL.  If you don't need to use a handle, return
294 C<NBDKIT_HANDLE_NOT_NEEDED> which is a static non-NULL pointer.
296 If there is an error, C<.open> should call C<nbdkit_error> with an
297 error message and return C<NULL>.
299 =head2 C<.close>
301  void (*close) (void *handle);
303 This is called when the client closes the connection.  It should clean
304 up any per-connection resources used by the filter.
306 =head2 C<.prepare>
308 =head2 C<.finalize>
310   int (*prepare) (struct nbdkit_next_ops *next_ops, void *nxdata,
311                   void *handle);
312   int (*finalize) (struct nbdkit_next_ops *next_ops, void *nxdata,
313                    void *handle);
315 These two methods can be used to perform any necessary operations just
316 after opening the connection (C<.prepare>) or just before closing the
317 connection (C<.finalize>).
319 For example if you need to scan the underlying disk to check for a
320 partition table, you could do it in your C<.prepare> method (calling
321 the plugin's C<.pread> method via C<next_ops>).  Or if you need to
322 cleanly update superblock data in the image on close you can do it in
323 your C<.finalize> method (calling the plugin's C<.pwrite> method).
324 Doing these things in the filter's C<.open> or C<.close> method is not
325 possible.
327 There is no C<next_ops-E<gt>prepare> or C<next_ops-E<gt>finalize>.
328 Unlike other filter methods, prepare and finalize are not chained
329 through the C<next_ops> structure.  Instead the core nbdkit server
330 calls the prepare and finalize methods of all filters.  Prepare
331 methods are called starting with the filter closest to the plugin and
332 proceeding outwards.  Finalize methods are called in the reverse order
333 of prepare methods.
335 If there is an error, both callbacks should call C<nbdkit_error> with
336 an error message and return C<-1>.
338 =head2 C<.get_size>
340  int64_t (*get_size) (struct nbdkit_next_ops *next_ops, void *nxdata,
341                       void *handle);
343 This intercepts the plugin C<.get_size> method and can be used to read
344 or modify the apparent size of the block device that the NBD client
345 will see.
347 The returned size must be E<ge> 0.  If there is an error, C<.get_size>
348 should call C<nbdkit_error> with an error message and return C<-1>.
349 If this function is called more than once for the same connection, it
350 should return the same value; similarly, the filter may cache
351 C<next_ops-E<gt>get_size> for a given connection rather than repeating
352 calls.
354 =head2 C<.can_write>
356 =head2 C<.can_flush>
358 =head2 C<.is_rotational>
360 =head2 C<.can_trim>
362 =head2 C<.can_zero>
364 =head2 C<.can_extents>
366 =head2 C<.can_fua>
368 =head2 C<.can_multi_conn>
370 =head2 C<.can_cache>
372  int (*can_write) (struct nbdkit_next_ops *next_ops, void *nxdata,
373                    void *handle);
374  int (*can_flush) (struct nbdkit_next_ops *next_ops, void *nxdata,
375                    void *handle);
376  int (*is_rotational) (struct nbdkit_next_ops *next_ops,
377                        void *nxdata,
378                        void *handle);
379  int (*can_trim) (struct nbdkit_next_ops *next_ops, void *nxdata,
380                   void *handle);
381  int (*can_zero) (struct nbdkit_next_ops *next_ops, void *nxdata,
382                   void *handle);
383  int (*can_extents) (struct nbdkit_next_ops *next_ops, void *nxdata,
384                      void *handle);
385  int (*can_fua) (struct nbdkit_next_ops *next_ops, void *nxdata,
386                  void *handle);
387  int (*can_multi_conn) (struct nbdkit_next_ops *next_ops, void *nxdata,
388                         void *handle);
389  int (*can_cache) (struct nbdkit_next_ops *next_ops, void *nxdata,
390                    void *handle);
392 These intercept the corresponding plugin methods, and control feature
393 bits advertised to the client.
395 Of note, the C<.can_zero> callback in the filter controls whether the
396 server advertises zero support to the client, which is slightly
397 different semantics than the plugin; that is,
398 C<next_ops-E<gt>can_zero> always returns true for a plugin, even when
399 the plugin's own C<.can_zero> callback returned false, because nbdkit
400 implements a fallback to C<.pwrite> at the plugin layer.
402 Remember that most of the feature check functions return merely a
403 boolean success value, while C<.can_fua> and C<.can_cache> have three
404 success values.
406 The difference between C<.can_fua> values may affect choices made in
407 the filter: when splitting a write request that requested FUA from the
408 client, if C<next_ops-E<gt>can_fua> returns C<NBDKIT_FUA_NATIVE>, then
409 the filter should pass the FUA flag on to each sub-request; while if
410 it is known that FUA is emulated by a flush because of a return of
411 C<NBDKIT_FUA_EMULATE>, it is more efficient to only flush once after
412 all sub-requests have completed (often by passing C<NBDKIT_FLAG_FUA>
413 on to only the final sub-request, or by dropping the flag and ending
414 with a direct call to C<next_ops-E<gt>flush>).
416 If there is an error, the callback should call C<nbdkit_error> with an
417 error message and return C<-1>.  If these functions are called more
418 than once for the same connection, they should return the same value;
419 similarly, the filter may cache the results of each counterpart in
420 C<next_ops> for a given connection rather than repeating calls.
422 =head2 C<.pread>
424  int (*pread) (struct nbdkit_next_ops *next_ops, void *nxdata,
425                void *handle, void *buf, uint32_t count, uint64_t offset,
426                uint32_t flags, int *err);
428 This intercepts the plugin C<.pread> method and can be used to read or
429 modify data read by the plugin.
431 The parameter C<flags> exists in case of future NBD protocol
432 extensions; at this time, it will be 0 on input, and the filter should
433 not pass any flags to C<next_ops-E<gt>pread>.
435 If there is an error (including a short read which couldn't be
436 recovered from), C<.pread> should call C<nbdkit_error> with an error
437 message B<and> return -1 with C<err> set to the positive errno value
438 to return to the client.
440 =head2 C<.pwrite>
442  int (*pwrite) (struct nbdkit_next_ops *next_ops, void *nxdata,
443                 void *handle,
444                 const void *buf, uint32_t count, uint64_t offset,
445                 uint32_t flags, int *err);
447 This intercepts the plugin C<.pwrite> method and can be used to modify
448 data written by the plugin.
450 This function will not be called if C<.can_write> returned false; in
451 turn, the filter should not call C<next_ops-E<gt>pwrite> if
452 C<next_ops-E<gt>can_write> did not return true.
454 The parameter C<flags> may include C<NBDKIT_FLAG_FUA> on input based
455 on the result of C<.can_fua>.  In turn, the filter should only pass
456 C<NBDKIT_FLAG_FUA> on to C<next_ops-E<gt>pwrite> if
457 C<next_ops-E<gt>can_fua> returned a positive value.
459 If there is an error (including a short write which couldn't be
460 recovered from), C<.pwrite> should call C<nbdkit_error> with an error
461 message B<and> return -1 with C<err> set to the positive errno value
462 to return to the client.
464 =head2 C<.flush>
466  int (*flush) (struct nbdkit_next_ops *next_ops, void *nxdata,
467                void *handle, uint32_t flags, int *err);
469 This intercepts the plugin C<.flush> method and can be used to modify
470 flush requests.
472 This function will not be called if C<.can_flush> returned false; in
473 turn, the filter should not call C<next_ops-E<gt>flush> if
474 C<next_ops-E<gt>can_flush> did not return true.
476 The parameter C<flags> exists in case of future NBD protocol
477 extensions; at this time, it will be 0 on input, and the filter should
478 not pass any flags to C<next_ops-E<gt>flush>.
480 If there is an error, C<.flush> should call C<nbdkit_error> with an
481 error message B<and> return -1 with C<err> set to the positive errno
482 value to return to the client.
484 =head2 C<.trim>
486  int (*trim) (struct nbdkit_next_ops *next_ops, void *nxdata,
487               void *handle, uint32_t count, uint64_t offset,
488               uint32_t flags, int *err);
490 This intercepts the plugin C<.trim> method and can be used to modify
491 trim requests.
493 This function will not be called if C<.can_trim> returned false; in
494 turn, the filter should not call C<next_ops-E<gt>trim> if
495 C<next_ops-E<gt>can_trim> did not return true.
497 The parameter C<flags> may include C<NBDKIT_FLAG_FUA> on input based
498 on the result of C<.can_fua>.  In turn, the filter should only pass
499 C<NBDKIT_FLAG_FUA> on to C<next_ops-E<gt>trim> if
500 C<next_ops-E<gt>can_fua> returned a positive value.
502 If there is an error, C<.trim> should call C<nbdkit_error> with an
503 error message B<and> return -1 with C<err> set to the positive errno
504 value to return to the client.
506 =head2 C<.zero>
508  int (*zero) (struct nbdkit_next_ops *next_ops, void *nxdata,
509               void *handle, uint32_t count, uint64_t offset, uint32_t flags,
510               int *err);
512 This intercepts the plugin C<.zero> method and can be used to modify
513 zero requests.
515 This function will not be called if C<.can_zero> returned false; in
516 turn, the filter should not call C<next_ops-E<gt>zero> if
517 C<next_ops-E<gt>can_zero> did not return true.
519 On input, the parameter C<flags> may include C<NBDKIT_FLAG_MAY_TRIM>
520 unconditionally, and C<NBDKIT_FLAG_FUA> based on the result of
521 C<.can_fua>.  In turn, the filter may pass C<NBDKIT_FLAG_MAY_TRIM>
522 unconditionally, but should only pass C<NBDKIT_FLAG_FUA> on to
523 C<next_ops-E<gt>zero> if C<next_ops-E<gt>can_fua> returned a positive
524 value.
526 Note that unlike the plugin C<.zero> which is permitted to fail with
527 C<ENOTSUP> or C<EOPNOTSUPP> to force a fallback to C<.pwrite>, the
528 function C<next_ops-E<gt>zero> will never fail with C<err> set to
529 C<ENOTSUP> or C<EOPNOTSUPP> because the fallback has already taken
530 place.
532 If there is an error, C<.zero> should call C<nbdkit_error> with an
533 error message B<and> return -1 with C<err> set to the positive errno
534 value to return to the client.  The filter should never fail with
535 C<ENOTSUP> or C<EOPNOTSUPP> (while plugins have automatic fallback to
536 C<.pwrite>, filters do not).
538 =head2 C<.extents>
540  int (*extents) (struct nbdkit_next_ops *next_ops, void *nxdata,
541                  void *handle, uint32_t count, uint64_t offset, uint32_t flags,
542                  struct nbdkit_extents *extents,
543                  int *err);
545 This intercepts the plugin C<.extents> method and can be used to
546 modify extent requests.
548 This function will not be called if C<.can_extents> returned false; in
549 turn, the filter should not call C<next_ops-E<gt>extents> if
550 C<next_ops-E<gt>can_extents> did not return true.
552 It is possible for filters to transform the extents list received back
553 from the layer below.  Without error checking it would look like this:
555  myfilter_extents (..., uint32_t count, uint64_t offset, ...)
557    size_t i;
558    struct nbdkit_extents *extents2;
559    struct nbdkit_extent e;
560    int64_t size;
562    size = next_ops->get_size (nxdata);
563    extents2 = nbdkit_extents_new (offset + shift, size - shift);
564    next_ops->extents (nxdata, count, offset + shift, flags, extents2, err);
565    for (i = 0; i < nbdkit_extents_count (extents2); ++i) {
566      e = nbdkit_get_extent (extents2, i);
567      e.offset -= shift;
568      nbdkit_add_extent (extents, e.offset, e.length, e.type);
569    }
570    nbdkit_extents_free (extents2);
573 If there is an error, C<.extents> should call C<nbdkit_error> with an
574 error message B<and> return -1 with C<err> set to the positive errno
575 value to return to the client.
577 =head3 Allocating and freeing nbdkit_extents list
579 Two functions are provided to filters only for allocating and freeing
580 the map:
582  struct nbdkit_extents *nbdkit_extents_new (uint64_t start, uint64_t end);
584 Allocates and returns a new, empty extents list.  The C<start>
585 parameter is the start of the range described in the list, and the
586 C<end> parameter is the offset of the byte beyond the end.  Normally
587 you would pass in C<offset> as the start and the size of the plugin as
588 the end, but for filters which adjust offsets, they should pass in the
589 adjusted offset.
591 On error this function can return C<NULL>.  In this case it calls
592 C<nbdkit_error> and/or C<nbdkit_set_error> as required.  C<errno> will
593 be set to a suitable value.
595  void nbdkit_extents_free (struct nbdkit_extents *);
597 Frees an existing extents list.
599 =head3 Iterating over nbdkit_extents list
601 Two functions are provided to filters only to iterate over the extents
602 in order:
604  size_t nbdkit_extents_count (const struct nbdkit_extents *);
606 Returns the number of extents in the list.
608  struct nbdkit_extent {
609    uint64_t offset;
610    uint64_t length;
611    uint32_t type;
612  };
613  struct nbdkit_extent nbdkit_get_extent (const struct nbdkit_extents *,
614                                          size_t i);
616 Returns a copy of the C<i>'th extent.
618 =head2 C<.cache>
620  int (*cache) (struct nbdkit_next_ops *next_ops, void *nxdata,
621                void *handle, uint32_t count, uint64_t offset,
622                uint32_t flags, int *err);
624 This intercepts the plugin C<.cache> method and can be used to modify
625 cache requests.
627 This function will not be called if C<.can_cache> returned
628 C<NBDKIT_CACHE_NONE> or C<NBDKIT_CACHE_EMULATE>; in turn, the filter
629 should not call C<next_ops-E<gt>cache> unless
630 C<next_ops-E<gt>can_cache> returned C<NBDKIT_CACHE_NATIVE>.
632 The parameter C<flags> exists in case of future NBD protocol
633 extensions; at this time, it will be 0 on input, and the filter should
634 not pass any flags to C<next_ops-E<gt>cache>.
636 If there is an error, C<.cache> should call C<nbdkit_error> with an
637 error message B<and> return -1 with C<err> set to the positive errno
638 value to return to the client.
640 =head1 ERROR HANDLING
642 If there is an error in the filter itself, the filter should call
643 C<nbdkit_error> to report an error message.  If the callback is
644 involved in serving data, the explicit C<err> parameter determines the
645 error code that will be sent to the client; other callbacks should
646 return the appropriate error indication, eg. C<NULL> or C<-1>.
648 C<nbdkit_error> has the following prototype and works like
649 L<printf(3)>:
651  void nbdkit_error (const char *fs, ...);
652  void nbdkit_verror (const char *fs, va_list args);
654 For convenience, C<nbdkit_error> preserves the value of C<errno>, and
655 also supports the glibc extension of a single C<%m> in a format string
656 expanding to C<strerror(errno)>, even on platforms that don't support
657 that natively.
659 =head1 DEBUGGING
661 Run the server with I<-f> and I<-v> options so it doesn't fork and you
662 can see debugging information:
664  nbdkit -fv --filter=./myfilter.so plugin [key=value [key=value [...]]]
666 To print debugging information from within the filter, call
667 C<nbdkit_debug>, which has the following prototype and works like
668 L<printf(3)>:
670  void nbdkit_debug (const char *fs, ...);
671  void nbdkit_vdebug (const char *fs, va_list args);
673 For convenience, C<nbdkit_debug> preserves the value of C<errno>, and
674 also supports the glibc extension of a single C<%m> in a format string
675 expanding to C<strerror(errno)>, even on platforms that don't support
676 that natively.  Note that C<nbdkit_debug> only prints things when the
677 server is in verbose mode (I<-v> option).
679 =head2 Debug Flags
681 Debug Flags in filters work exactly the same way as plugins.  See
682 L<nbdkit-plugin(3)/Debug Flags>.
684 =head1 INSTALLING THE FILTER
686 The filter is a C<*.so> file and possibly a manual page.  You can of
687 course install the filter C<*.so> file wherever you want, and users
688 will be able to use it by running:
690  nbdkit --filter=/path/to/filter.so plugin [args]
692 However B<if> the shared library has a name of the form
693 C<nbdkit-I<name>-filter.so> B<and if> the library is installed in the
694 C<$filterdir> directory, then users can be run it by only typing:
696  nbdkit --filter=name plugin [args]
698 The location of the C<$filterdir> directory is set when nbdkit is
699 compiled and can be found by doing:
701  nbdkit --dump-config
703 If using the pkg-config/pkgconf system then you can also find the
704 filter directory at compile time by doing:
706  pkgconf nbdkit --variable=filterdir
708 =head1 PKG-CONFIG/PKGCONF
710 nbdkit provides a pkg-config/pkgconf file called C<nbdkit.pc> which
711 should be installed on the correct path when the nbdkit development
712 environment is installed.  You can use this in autoconf
713 F<configure.ac> scripts to test for the development environment:
715  PKG_CHECK_MODULES([NBDKIT], [nbdkit >= 1.2.3])
717 The above will fail unless nbdkit E<ge> 1.2.3 and the header file is
718 installed, and will set C<NBDKIT_CFLAGS> and C<NBDKIT_LIBS>
719 appropriately for compiling filters.
721 You can also run pkg-config/pkgconf directly, for example:
723  if ! pkgconf nbdkit --exists; then
724    echo "you must install the nbdkit development environment"
725    exit 1
726  fi
728 You can also substitute the filterdir variable by doing:
730  PKG_CHECK_VAR([NBDKIT_FILTERDIR], [nbdkit], [filterdir])
732 which defines C<$(NBDKIT_FILTERDIR)> in automake-generated Makefiles.
734 =head1 SEE ALSO
736 L<nbdkit(1)>,
737 L<nbdkit-plugin(3)>.
739 Standard filters provided by nbdkit:
741 __FILTER_LINKS__.
743 =head1 AUTHORS
745 Eric Blake
747 Richard W.M. Jones
749 =head1 COPYRIGHT
751 Copyright (C) 2013-2019 Red Hat Inc.