On Wed, May 17, 2023 at 11:06:58AM +0100, Richard W.M. Jones wrote:
Returns a fully allocated disk containing all 0xff (all ones), or
another byte of your choice.
---
plugins/data/nbdkit-data-plugin.pod | 1 +
plugins/full/nbdkit-full-plugin.pod | 1 +
plugins/null/nbdkit-null-plugin.pod | 1 +
plugins/ones/nbdkit-ones-plugin.pod | 77 +++++++
plugins/pattern/nbdkit-pattern-plugin.pod | 4 +-
plugins/random/nbdkit-random-plugin.pod | 1 +
.../nbdkit-sparse-random-plugin.pod | 1 +
plugins/zero/nbdkit-zero-plugin.pod | 1 +
configure.ac | 2 +
plugins/ones/Makefile.am | 70 +++++++
tests/Makefile.am | 4 +
plugins/ones/ones.c | 191 ++++++++++++++++++
tests/test-ones.sh | 53 +++++
13 files changed, 406 insertions(+), 1 deletion(-)
+++ b/plugins/ones/ones.c
@@ -0,0 +1,191 @@
+
+/* Write zeroes. */
+static int
+ones_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
+{
+ /* nothing */
+ return 0;
+}
Since writing zeroes is a no-op...
+static struct nbdkit_plugin plugin = {
+ .name = "ones",
+ .version = PACKAGE_VERSION,
+ .config = ones_config,
+ .config_help = ones_config_help,
+ .magic_config_key = "size",
+ .open = ones_open,
+ .get_size = ones_get_size,
+ .can_multi_conn = ones_can_multi_conn,
+ .can_cache = ones_can_cache,
+ .pread = ones_pread,
+ .pwrite = ones_pwrite,
+ .zero = ones_zero,
+ .trim = ones_trim,
+ .can_fua = ones_can_fua,
+ .flush = ones_flush,
+ .extents = ones_extents,
+ /* In this plugin, errno is preserved properly along error return
+ * paths from failed system calls.
+ */
+ .errno_is_preserved = 1,
+};
...we probably also want to supply .can_fast_zero with a function that
returns true.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization:
qemu.org |
libvirt.org