[libnbd PATCH v3 00/18] Improve NBD_OPT_ control
by Eric Blake
v2 was here:
https://listman.redhat.com/archives/libguestfs/2022-August/029726.html
Since then, I've addressed even more bug fixes, improved comments and
commit messages to better explain the changes along the way, added a
couple more APIs (nbd_opt_list_meta_context_queries,
nbd_opt_structured_reply), and improved some unit tests. A lot of
this work is thanks to Laszlo's careful reviews.
I still want to add nbd_opt_starttls, but this series has already
grown big enough that it is worth getting more of it committed.
Eric Blake (18):
api: Fix crashes on nbd_connect_command with bad argv
tests: Add coverage of unusual nbd_connect_command argv
api: Allow nbd_opt_list_meta_context() without SR
tests: Test nbd_opt_list_meta_context() without SR
api: Localize list used during NBD_OPT_*_META_CONTEXT
api: Add nbd_[aio_]opt_list_meta_context_queries
tests: Language port of nbd_opt_list_meta_context_queries()
api: Add nbd_set_request_meta_context()
tests: Language port of nbd_set_request_meta_context() tests
info: Explicitly skip NBD_OPT_SET_META_CONTEXT in --list mode
api: Make nbd_opt_list_meta_context stateless
tests: Add coverage for stateless nbd_opt_list_meta_context
api: Reset state on changed nbd_set_export_name()
tests: Add coverage for nbd_set_export_name fix
api: Add nbd_[aio_]opt_set_meta_context[_queries]
tests: Language port of nbd_opt_set_meta_context() tests
api: Add nbd_[aio_]opt_structured_reply()
tests: Language port of nbd_opt_structured_reply() tests
lib/internal.h | 6 +-
generator/API.ml | 430 +++++++++++++++++-
generator/C.ml | 2 +-
generator/states-newstyle-opt-go.c | 2 +
generator/states-newstyle-opt-meta-context.c | 85 ++--
generator/states-newstyle-opt-starttls.c | 1 +
.../states-newstyle-opt-structured-reply.c | 22 +-
generator/states-newstyle.c | 4 +
lib/connect.c | 10 +-
lib/flags.c | 4 +-
lib/handle.c | 22 +
lib/opt.c | 143 +++++-
lib/utils.c | 81 +++-
python/t/110-defaults.py | 1 +
python/t/120-set-non-defaults.py | 2 +
python/t/230-opt-info.py | 36 +-
python/t/240-opt-list-meta.py | 61 ++-
python/t/245-opt-list-meta-queries.py | 68 +++
python/t/250-opt-set-meta.py | 134 ++++++
python/t/255-opt-set-meta-queries.py | 76 ++++
ocaml/tests/Makefile.am | 3 +
ocaml/tests/test_110_defaults.ml | 2 +
ocaml/tests/test_120_set_non_defaults.ml | 3 +
ocaml/tests/test_230_opt_info.ml | 43 +-
ocaml/tests/test_240_opt_list_meta.ml | 73 ++-
ocaml/tests/test_245_opt_list_meta_queries.ml | 68 +++
ocaml/tests/test_250_opt_set_meta.ml | 170 +++++++
ocaml/tests/test_255_opt_set_meta_queries.ml | 79 ++++
tests/Makefile.am | 29 ++
tests/errors-connect-null.c | 88 ++++
tests/opt-info.c | 92 +++-
tests/opt-list-meta-queries.c | 146 ++++++
tests/opt-list-meta.c | 135 +++++-
tests/opt-set-meta-queries.c | 150 ++++++
tests/opt-set-meta.c | 259 +++++++++++
tests/opt-structured-twice.c | 145 ++++++
.gitignore | 5 +
golang/Makefile.am | 3 +
golang/libnbd_110_defaults_test.go | 8 +
golang/libnbd_120_set_non_defaults_test.go | 12 +
golang/libnbd_230_opt_info_test.go | 111 ++++-
golang/libnbd_240_opt_list_meta_test.go | 176 ++++++-
.../libnbd_245_opt_list_meta_queries_test.go | 115 +++++
golang/libnbd_250_opt_set_meta_test.go | 307 +++++++++++++
.../libnbd_255_opt_set_meta_queries_test.go | 141 ++++++
info/list.c | 3 +-
info/show.c | 3 +-
47 files changed, 3405 insertions(+), 154 deletions(-)
create mode 100644 python/t/245-opt-list-meta-queries.py
create mode 100644 python/t/250-opt-set-meta.py
create mode 100644 python/t/255-opt-set-meta-queries.py
create mode 100644 ocaml/tests/test_245_opt_list_meta_queries.ml
create mode 100644 ocaml/tests/test_250_opt_set_meta.ml
create mode 100644 ocaml/tests/test_255_opt_set_meta_queries.ml
create mode 100644 tests/errors-connect-null.c
create mode 100644 tests/opt-list-meta-queries.c
create mode 100644 tests/opt-set-meta-queries.c
create mode 100644 tests/opt-set-meta.c
create mode 100644 tests/opt-structured-twice.c
create mode 100644 golang/libnbd_245_opt_list_meta_queries_test.go
create mode 100644 golang/libnbd_250_opt_set_meta_test.go
create mode 100644 golang/libnbd_255_opt_set_meta_queries_test.go
--
2.37.3
2 years, 3 months
[PATCH libguestfs-common] options: Don't attempt to scan LVs if "lvm2" feature is not available
by Richard W.M. Jones
Since we added support for transparent decryption of LUKS in
commit a232e62dcf ("fish: '-i' option automatically handles whole-disk
encryption") we have always assumed that the "lvm2" feature is
available and so we could call guestfs_vg_activate_all. That API
would have failed in the unlikely event that the feature is not
available, preventing opening any (even unencrypted) disk.
The code has changed greatly since then but the basic problem remains.
Test for the "lvm2" feature, otherwise avoid trying to scan LVs.
Reported-by: Feng Li
Fixes: a232e62dcf
---
options/decrypt.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/options/decrypt.c b/options/decrypt.c
index 6fc7760e3..19fe93ce2 100644
--- a/options/decrypt.c
+++ b/options/decrypt.c
@@ -202,8 +202,8 @@ decrypt_mountables (guestfs_h *g, const char * const *mountables,
void
inspect_do_decrypt (guestfs_h *g, struct key_store *ks)
{
+ const char *lvm2_feature[] = { "lvm2", NULL };
CLEANUP_FREE_STRING_LIST char **partitions = guestfs_list_partitions (g);
- CLEANUP_FREE_STRING_LIST char **lvs = NULL;
bool need_rescan;
if (partitions == NULL)
@@ -211,13 +211,17 @@ inspect_do_decrypt (guestfs_h *g, struct key_store *ks)
need_rescan = decrypt_mountables (g, (const char * const *)partitions, ks);
- if (need_rescan) {
- if (guestfs_lvm_scan (g, 1) == -1)
+ if (guestfs_feature_available (g, (char **) lvm2_feature) > 0) {
+ CLEANUP_FREE_STRING_LIST char **lvs = NULL;
+
+ if (need_rescan) {
+ if (guestfs_lvm_scan (g, 1) == -1)
+ exit (EXIT_FAILURE);
+ }
+
+ lvs = guestfs_lvs (g);
+ if (lvs == NULL)
exit (EXIT_FAILURE);
+ decrypt_mountables (g, (const char * const *)lvs, ks);
}
-
- lvs = guestfs_lvs (g);
- if (lvs == NULL)
- exit (EXIT_FAILURE);
- decrypt_mountables (g, (const char * const *)lvs, ks);
}
--
2.37.0.rc2
2 years, 3 months
[PATCH libnbd] ublk: Add new nbdublk program
by Richard W.M. Jones
This patch adds simple support for a ublk-based NBD client.
It is also available here:
https://gitlab.com/rwmjones/libnbd/-/tree/nbdublk/ublk
ublk is a way to write Linux block device drivers in userspace:
https://lwn.net/Articles/903855/
For simplicity of implementation and because I don't currently
understand the thread model of ublksrv, this only implements
synchronous calls for now. It should be possible to extend this to a
fully asynchronous client without too much difficulty.
It does appear to work, at least for simple cases. I have created
filesystems, files, etc on a ublk device backed by an nbdkit RAM disk,
eg: On one machine do:
$ nbdkit memory 1G
On the client machine with the right kernel etc [see below] do:
# modprobe ublk_drv
# nbdublk /dev/ublkb0 nbd://remote
# ublk list
# blockdev --getsize64 /dev/ublkb0
# mke2fs /dev/ublkb0
# ...
# ublk del -n 0
Testing this is not for the fainthearted. I would start with a
throwaway Fedora Rawhide virtual machine, fully upgraded. You will
need to recompile the kernel with CONFIG_BLK_DEV_UBLK=m
You will need to upgrade to liburing 2.2 (I pushed this to Rawhide a
few days ago).
You will need to download & compile: https://github.com/ming1/ubdsrv
Apply this patch to libnbd and compile it with:
export PKG_CONFIG_PATH=$HOME/ubdsrv
export CFLAGS="$CFLAGS -I$HOME/ubdsrv/include"
export CXXFLAGS="$CXXFLAGS -I$HOME/ubdsrv/include"
export LDFLAGS="$LDFLAGS -L$HOME/ubdsrv/lib"
./configure
make
(Check that ublk dependencies are found and nbdublk is compiled)
You will then be able to run nbdublk from the compile directory using:
sudo ./run nbdublk --help
Rich.
2 years, 3 months
[PATCH libguestfs] daemon: Make vg_scan and lvm_scan no-ops if no LVM feature
by Richard W.M. Jones
If the LVM ("lvm2") feature is not available, these calls would fail.
Really they ought to be part of the "lvm2" optgroup which would cause
the generator to call reply_with_unavailable_feature and generate the
correct ENOTSUP error. When vgscan was originally added in 2010 it
was not added to the optgroup, and when lvm_scan was later added in
2018 and deprecating vgscan, the same mistake was copied.
Before this commit they will try to run the lvm pvscan command which
will fail returning some other error (instead of ENOTSUP).
Fix this by turning the calls into no-ops if the LVM feature is not
available, since scanning for LVM objects when there is no LVM can be
safely turned into a no-op.
See also
https://listman.redhat.com/archives/libguestfs/2022-September/thread.html...
Reported-by: Laszlo Ersek
Fixes: 55dfcb2211 ("New API: lvm_scan, deprecate vgscan")
Fixes: 9752039e52 ("New API: vgscan")
---
daemon/lvm.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/daemon/lvm.c b/daemon/lvm.c
index 72c59c3a1b..c273946d34 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -651,6 +651,13 @@ do_lvm_scan (int activate)
const char *argv[MAX_ARGS];
size_t i = 0;
+ /* Historically this call was never added to the "lvm2" optgroup.
+ * Rather than changing that and have the small risk of breaking
+ * callers, just make it into a no-op if LVM is not available.
+ */
+ if (optgroup_lvm2_available () == 0)
+ return 0;
+
ADD_ARG (argv, i, "lvm");
ADD_ARG (argv, i, "pvscan");
ADD_ARG (argv, i, "--cache");
--
2.37.0.rc2
2 years, 3 months