2 * Copyright (C) 2013 Red Hat Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Red Hat nor the names of its contributors may be
17 * used to endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 /* See nbdkit-plugin(3) for documentation and how to write a plugin. */
36 #ifndef NBDKIT_PLUGIN_H
37 #define NBDKIT_PLUGIN_H
42 #define NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS 0
43 #define NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS 1
44 #define NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS 2
45 #define NBDKIT_THREAD_MODEL_PARALLEL 3
47 struct nbdkit_plugin
{
48 uint64_t _struct_size
;
55 const char *description
;
58 void (*unload
) (void);
60 int (*config
) (const char *key
, const char *value
);
61 int (*config_complete
) (void);
62 const char *config_help
;
64 void * (*open
) (int readonly
);
65 void (*close
) (void *handle
);
67 int64_t (*get_size
) (void *handle
);
69 int (*can_write
) (void *handle
);
70 int (*can_flush
) (void *handle
);
71 int (*is_rotational
) (void *handle
);
72 int (*can_trim
) (void *handle
);
74 int (*pread
) (void *handle
, void *buf
, uint32_t count
, uint64_t offset
);
75 int (*pwrite
) (void *handle
, const void *buf
, uint32_t count
, uint64_t offset
);
76 int (*flush
) (void *handle
);
77 int (*trim
) (void *handle
, uint32_t count
, uint64_t offset
);
79 /* int (*set_exportname) (void *handle, const char *exportname); */
82 extern void nbdkit_error (const char *msg
, ...);
83 extern void nbdkit_debug (const char *msg
, ...);
85 extern char *nbdkit_absolute_path (const char *path
);
86 extern int64_t nbdkit_parse_size (const char *str
);
88 #define NBDKIT_REGISTER_PLUGIN(plugin) \
89 struct nbdkit_plugin * \
92 (plugin)._struct_size = sizeof (plugin); \
93 (plugin)._api_version = 1; \
94 (plugin)._thread_model = THREAD_MODEL; \
98 #endif /* NBDKIT_PLUGIN_H */