[PATCH nbdkit] cc: Handle missing callbacks.
by Richard W.M. Jones
If can_write is defined by the subplugin and returns true, but pwrite
is missing, then the plugin would crash. nbdkit itself handles these
kinds of cases in different ways, and this commit replicates that
handling. Except for .zero where the fallback is complex.
Thanks: Eric Blake
---
plugins/cc/cc.c | 50 +++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 44 insertions(+), 6 deletions(-)
diff --git a/plugins/cc/cc.c b/plugins/cc/cc.c
index 4d92be66..2139cf62 100644
--- a/plugins/cc/cc.c
+++ b/plugins/cc/cc.c
@@ -37,6 +37,7 @@
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
#include <dlfcn.h>
#define NBDKIT_API_VERSION 2
@@ -463,38 +464,75 @@ static int
cc_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset,
uint32_t flags)
{
- return subplugin.pwrite (handle, buf, count, offset, flags);
+ if (subplugin.pwrite)
+ return subplugin.pwrite (handle, buf, count, offset, flags);
+ else {
+ nbdkit_error ("missing %s callback", "pwrite");
+ errno = EROFS;
+ return -1;
+ }
}
static int
cc_flush (void *handle, uint32_t flags)
{
- return subplugin.flush (handle, flags);
+ if (subplugin.flush)
+ return subplugin.flush (handle, flags);
+ else {
+ nbdkit_error ("missing %s callback", "flush");
+ errno = EINVAL;
+ return -1;
+ }
}
static int
cc_trim (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
{
- return subplugin.trim (handle, count, offset, flags);
+ if (subplugin.trim)
+ return subplugin.trim (handle, count, offset, flags);
+ else {
+ nbdkit_error ("missing %s callback", "trim");
+ errno = EINVAL;
+ return -1;
+ }
}
static int
cc_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
{
- return subplugin.zero (handle, count, offset, flags);
+ if (subplugin.zero)
+ return subplugin.zero (handle, count, offset, flags);
+ else {
+ /* XXX nbdkit tries to emulate this and we should too. */
+ nbdkit_error ("missing %s callback", "zero");
+ errno = EINVAL;
+ return -1;
+ }
}
static int
cc_extents (void *handle, uint32_t count, uint64_t offset,
uint32_t flags, struct nbdkit_extents *extents)
{
- return subplugin.extents (handle, count, offset, flags, extents);
+ if (subplugin.extents)
+ return subplugin.extents (handle, count, offset, flags, extents);
+ else {
+ nbdkit_error ("missing %s callback", "extents");
+ errno = EINVAL;
+ return -1;
+ }
}
static int
cc_cache (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
{
- return subplugin.cache (handle, count, offset, flags);
+ if (subplugin.cache)
+ return subplugin.cache (handle, count, offset, flags);
+ else
+ /* A plugin may advertise caching but not provide .cache; in that
+ * case, caching is explicitly a no-op.
+ */
+ return 0;
}
static struct nbdkit_plugin plugin = {
--
2.25.0
4 years, 5 months
[PATCH nbdkit 0/5] vddk: Fix password parameter.
by Richard W.M. Jones
Probably needs a bit of cleanup, but seems like it is generally the
right direction.
One thing I've noticed is that the expect test randomly (but rarely)
hangs :-( I guess something is racey but I don't know what at the
moment.
Rich.
4 years, 5 months
Re: [Libguestfs] Provide NBD via Browser over Websockets
by Eric Wheeler
On Mon, 15 Oct 2018, Nir Soffer wrote:
> On Sat, Oct 13, 2018 at 9:45 PM Eric Wheeler <nbd(a)lists.ewheeler.net> wrote:
> Hello all,
>
> It might be neat to attach ISOs to KVM guests via websockets. Basically
> the browser would be the NBD "server" and an NBD client would run on the
> hypervisor, then use `virsh change-media vm1 hdc --insert /dev/nbd0` could
> use an ISO from my desk to boot from.
>
> Here's an HTML5 open file example:
> https://stackoverflow.com/questions/3582671/how-to-open-a-local-disk-file...
>
> and the NBD protocol looks simple enough to implement in javascript:
> https://stackoverflow.com/questions/17295140/where-is-the-network-block-d...
>
> What do you think? Does anyone have an interest in doing this?
>
>
> HTML File API is very limited:
> - you cannot access any file except file provided by the user interactively
> - no support for sparseness or underlying disk block size
>
> So it will be a pretty bad backend for NBD server.
>
> What are you trying to do?
Hi Nir and Eric,
I hope you are well!
(I'm resurecting this old thread, not sure how I missed the replies.)
We are interested in attaching a local ISO to a remote VM over http (maybe
.qcow's, but ISO is the primary interest).
This is common for remote KVM (iDRAC/iLO/iKVM/CIMC), so wondering about
an http front-end for qemu to do the same.
Combining that with a spice JS client or noVNC for VM console access would
be neat.
I also like Eric Blake's idea of direct NBD client integration with qemu
instead of using /dev/nbd0.
-Eric
>
> Nir
>
>
4 years, 5 months
server: Fix reading passwords interactively.
by Richard W.M. Jones
https://bugzilla.redhat.com/show_bug.cgi?id=1842440
Patches 1 and 2 address fairly obvious bugs in how we handle reading
passwords from stdin.
There are other ways we may consider fixing these bugs:
- Should password=- always open /dev/tty and ignore stdin entirely?
- Should we make password=-0/-1/-2 work by skipping the close? Or
perhaps reopen the file descriptors on /dev/null after reading the
password? (This seems over-complicated to me, I think -0/-1/-2 is
always likely to be a user error).
Rich.
4 years, 5 months
[PATCH nbdkit] vddk: Disallow password=-
by Richard W.M. Jones
This has been broken since we added the reexec code
(commit 155af3107292c351d54ed42c732f4a67bb9aa910) because it
tried to read the password twice (before and after the reexec) failing
the second time because stdin had already been reopened on /dev/null.
Virt-v2v used this feature, but I will change virt-v2v instead.
---
plugins/vddk/nbdkit-vddk-plugin.pod | 7 +------
plugins/vddk/vddk.c | 4 ++++
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/plugins/vddk/nbdkit-vddk-plugin.pod b/plugins/vddk/nbdkit-vddk-plugin.pod
index 73316dd1..96a665b6 100644
--- a/plugins/vddk/nbdkit-vddk-plugin.pod
+++ b/plugins/vddk/nbdkit-vddk-plugin.pod
@@ -7,8 +7,7 @@ nbdkit-vddk-plugin - nbdkit VMware VDDK plugin
nbdkit vddk [file=]FILENAME
[config=FILENAME] [cookie=COOKIE] [libdir=LIBRARY]
[nfchostport=PORT] [single-link=true]
- [password=PASSWORD | password=- | password=+FILENAME
- | password=-FD]
+ [password=PASSWORD | password=+FILENAME | password=-FD]
[port=PORT] [server=HOSTNAME] [snapshot=MOREF]
[thumbprint=THUMBPRINT] [transports=MODE:MODE:...]
[unbuffered=true] [user=USERNAME] [vm=moref=ID]
@@ -159,10 +158,6 @@ Set the password to use when connecting to the remote server.
Note that passing this on the command line is not secure on shared
machines.
-=item B<password=->
-
-Ask for the password (interactively) when nbdkit starts up.
-
=item B<password=+>FILENAME
Read the password from the named file. This is a secure method
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c
index 4815a43e..54a6e019 100644
--- a/plugins/vddk/vddk.c
+++ b/plugins/vddk/vddk.c
@@ -240,6 +240,10 @@ vddk_config (const char *key, const char *value)
return -1;
}
else if (strcmp (key, "password") == 0) {
+ if (strcmp (value, "-") == 0) {
+ nbdkit_error ("password=- is not supported with the VDDK plugin");
+ return -1;
+ }
free (password);
if (nbdkit_read_password (value, &password) == -1)
return -1;
--
2.25.0
4 years, 5 months
virt-v2v: error: redefinition of 'glib_autoptr_clear_OsinfoList'
by Kevin Locke
Hi All,
I'm attempting to compile virt-v2v 1.42.0 on Debian testing. With gcc
9.3.0, libosinfo 1.7.1, and glib 2.64.2, `./configure && make` fails
on libosinfo-c.c with the following error message:
-8<--------------------------------------------------------------------
In file included from /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h:9,
from /usr/include/glib-2.0/glib/gtypes.h:32,
from /usr/include/glib-2.0/glib/galloca.h:32,
from /usr/include/glib-2.0/glib.h:30,
from /usr/include/glib-2.0/gobject/gbinding.h:28,
from /usr/include/glib-2.0/glib-object.h:22,
from /usr/include/libosinfo-1.0/osinfo/osinfo.h:28,
from libosinfo-c.c:25:
/usr/include/glib-2.0/glib/gmacros.h:1028:49: error: redefinition of 'glib_autoptr_clear_OsinfoList'
1028 | #define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
| ^~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gmacros.h:1044:36: note: in expansion of macro '_GLIB_AUTOPTR_CLEAR_FUNC_NAME'
1044 | static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (TypeName *_ptr) \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gmacros.h:1061:3: note: in expansion of macro '_GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS'
1061 | _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, TypeName, func)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libosinfo-c.c:47:1: note: in expansion of macro 'G_DEFINE_AUTOPTR_CLEANUP_FUNC'
47 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoList, g_object_unref)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gmacros.h:1028:49: note: previous definition of 'glib_autoptr_clear_OsinfoList' was here
1028 | #define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
| ^~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gmacros.h:1044:36: note: in expansion of macro '_GLIB_AUTOPTR_CLEAR_FUNC_NAME'
1044 | static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (TypeName *_ptr) \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gmacros.h:1056:3: note: in expansion of macro '_GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS'
1056 | _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(ModuleObjName, ParentName, _GLIB_AUTOPTR_CLEAR_FUNC_NAME(ParentName))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1500:3: note: in expansion of macro '_GLIB_DEFINE_AUTOPTR_CHAINUP'
1500 | _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/libosinfo-1.0/osinfo/osinfo_list.h:33:1: note: in expansion of macro 'G_DECLARE_DERIVABLE_TYPE'
33 | G_DECLARE_DERIVABLE_TYPE(OsinfoList, osinfo_list, OSINFO, LIST, GObject)
| ^~~~~~~~~~~~~~~~~~~~~~~
-8<--------------------------------------------------------------------
The full build log is available at
https://kevinlocke.name/misc/virt-v2v/virt-v2v-1.42.0-buildlog.txt
Is this a version incompatibility or something I've misconfigured?
If someone could point me in the right direction, I'd appreciate it.
Thanks,
Kevin
4 years, 5 months
[v2v PATCH v2] libosinfo: do not declare OsinfoList auto-cleanup in certain situations
by Pino Toscano
libosinfo changed the way OsinfoList is declared in 1.7.0, however that
was changed back to the old way in 1.8.0; the change was an ABI break,
and made OsinfoList a Module class. Starting from 2.63.3, Module
classes have already auto-cleanup functions declared for them, leading
to double declarations in certain setups.
Hence, do some version check dance to declare the OsinfoList only when
using "safe" versions of libosinfo and glib.
Reported by: Kevin Locke.
---
v2v/libosinfo-c.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/v2v/libosinfo-c.c b/v2v/libosinfo-c.c
index 1ab6bb4d..e5327dff 100644
--- a/v2v/libosinfo-c.c
+++ b/v2v/libosinfo-c.c
@@ -44,7 +44,16 @@
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoFilter, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoLoader, g_object_unref)
+/*
+ * Because of a bug in OsinfoList in libosinfo 1.7.0 (fixed in 1.8.0),
+ * and a glib auto-cleanup addition for Module classes in 2.63.3,
+ * avoid declaring this when:
+ * - libosinfo is >= 1.7.0 and < 1.8.0
+ * - glib is >= 2.63.3
+ */
+#if !IS_LIBOSINFO_VERSION(1, 7, 0) || IS_LIBOSINFO_VERSION(1, 8, 0) || !GLIB_CHECK_VERSION(2, 63, 3)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoList, g_object_unref)
+#endif
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoOsList, g_object_unref)
typedef OsinfoDb *OsinfoDb_t;
--
2.25.4
4 years, 5 months
[v2v PATCH] libosinfo: declare OsinfoList auto-cleanup with glib < 2.63.3
by Pino Toscano
Starting from glib 2.63.3, Module classes have already auto-cleanup
functions declared for them.
Reported by: Kevin Locke.
---
v2v/libosinfo-c.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/v2v/libosinfo-c.c b/v2v/libosinfo-c.c
index 1ab6bb4d..e6827f76 100644
--- a/v2v/libosinfo-c.c
+++ b/v2v/libosinfo-c.c
@@ -44,7 +44,9 @@
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoFilter, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoLoader, g_object_unref)
+#if !GLIB_CHECK_VERSION(2, 63, 3)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoList, g_object_unref)
+#endif
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoOsList, g_object_unref)
typedef OsinfoDb *OsinfoDb_t;
--
2.25.4
4 years, 5 months