1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-09-17 21:45:33 +03:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Dan Zheng
75cfb8434e nodedev: Add the missing PCI dev checks for 'mdev_types' capability
Similar to commit @f44ec9c1, commit @500cbc06 introduced a new nested
'mdev_types' capability, however the mentioned commit didn't adjust
virNodeDeviceNumOfCaps and virNodeDeviceListCaps functions accordingly
to provide proper support for this capability.

After applying this patch the following python snippet returns the
expected results:
    import libvirt
    conn = libvirt.openReadOnly('qemu:///system')
    devs = conn.listAllDevices()
    for dev in devs:
        if 'mdev_types' in dev.listCaps():
            print dev.name(),dev.numOfCaps(),dev.listCaps()

Signed-off-by: Dan Zheng <dzheng@redhat.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-16 10:33:25 +01:00
Michal Privoznik
74416b1d48 m4: Check for rl_completion_quote_character
Apparently we can't assume that people run readline recent enough
to have rl_completion_quote_character (added in readline-5.0
released in 2011). However, we can't compile without it. So if
not present, disable readline.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-01-15 17:59:26 +01:00
Michal Privoznik
0d6d5de53e tools: Always compile {virsh,virt-admin}-completer.c
The functions defined in these sources are referenced all over
the place, however, compiler only when building with readline.
Thus when building without it linker gets sad as it can't find
them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-01-15 15:49:11 +01:00
Michal Privoznik
66aa7e02c6 vsh: Provide cmdComplete stub for readline disabled builds
When building without readline, this function does nothing but
return false. Without touching any of its arguments which
triggers a build error. Therefore, provide a stub that has
arguments marked as unused.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-01-15 15:49:07 +01:00
Michal Privoznik
98bc781b42 vshReadlineOptionsGenerator: Don't add already specified options to the list
The current state of art is as follows:

 1) vshReadlineOptionsGenerator() generate all possible --options
 for given command, and then
 2) vshReadlineOptionsPrune() clears out already provided ones
 from the list.

Not only this brings needless memory complexity it is also not
trivial to get right. We can switch to easier approach: just
don't add already specified --options in the first step.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-01-15 15:45:14 +01:00
4 changed files with 63 additions and 81 deletions

View File

@@ -38,6 +38,19 @@ AC_DEFUN([LIBVIRT_CHECK_READLINE],[
LIBS="$lv_saved_libs $extra_LIBS"
fi
AC_CHECK_DECLS([rl_completion_quote_character],
[], [],
[[#include <stdio.h>
#include <readline/readline.h>]])
if test "$ac_cv_have_decl_rl_completion_quote_character" = "no" ; then
if test "$with_readline" = "yes" ; then
AC_MSG_ERROR([readline is missing rl_completion_quote_character])
else
with_readline=no;
fi
fi
# The normal library check...
LIBVIRT_CHECK_LIB([READLINE], [readline], [readline], [readline/readline.h])

View File

@@ -382,6 +382,12 @@ nodeDeviceNumOfCaps(virNodeDevicePtr device)
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)
ncaps++;
}
if (caps->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
if (caps->data.pci_dev.flags &
VIR_NODE_DEV_CAP_FLAG_PCI_MDEV)
ncaps++;
}
}
ret = ncaps;
@@ -432,6 +438,15 @@ nodeDeviceListCaps(virNodeDevicePtr device,
goto cleanup;
}
}
if (caps->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
if (ncaps < maxnames &&
caps->data.pci_dev.flags &
VIR_NODE_DEV_CAP_FLAG_PCI_MDEV) {
if (VIR_STRDUP(names[ncaps++],
virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_MDEV_TYPES)) < 0)
goto cleanup;
}
}
}
ret = ncaps;

View File

@@ -216,6 +216,7 @@ virt_login_shell_CFLAGS = \
virsh_SOURCES = \
virsh.c virsh.h \
virsh-completer.c virsh-completer.h \
virsh-console.c virsh-console.h \
virsh-domain.c virsh-domain.h \
virsh-domain-monitor.c virsh-domain-monitor.h \
@@ -231,15 +232,6 @@ virsh_SOURCES = \
virsh-volume.c virsh-volume.h \
$(NULL)
VIRSH_COMPLETER = \
virsh-completer.c virsh-completer.h
if WITH_READLINE
virsh_SOURCES += $(VIRSH_COMPLETER)
else ! WITH_READLINE
EXTRA_DIST += $(VIRSH_COMPLETER)
endif ! WITH_READLINE
virsh_LDFLAGS = \
$(AM_LDFLAGS) \
$(PIE_LDFLAGS) \
@@ -256,17 +248,9 @@ virsh_CFLAGS = \
virt_admin_SOURCES = \
virt-admin.c virt-admin.h \
virt-admin-completer.c virt-admin-completer.h \
$(NULL)
VIRT_ADMIN_COMPLETER = \
virt-admin-completer.c virt-admin-completer.h
if WITH_READLINE
virt_admin_SOURCES += $(VIRT_ADMIN_COMPLETER)
else ! WITH_READLINE
EXTRA_DIST += $(VIRT_ADMIN_COMPLETER)
endif ! WITH_READLINE
virt_admin_LDFLAGS = \
$(AM_LDFLAGS) \
$(COVERAGE_LDFLAGS) \

View File

@@ -2663,7 +2663,9 @@ vshReadlineCommandGenerator(const char *text)
}
static char **
vshReadlineOptionsGenerator(const char *text, const vshCmdDef *cmd)
vshReadlineOptionsGenerator(const char *text,
const vshCmdDef *cmd,
vshCmd *last)
{
size_t list_index = 0;
size_t len = strlen(text);
@@ -2678,6 +2680,8 @@ vshReadlineOptionsGenerator(const char *text, const vshCmdDef *cmd)
return NULL;
while ((name = cmd->opts[list_index].name)) {
bool exists = false;
vshCmdOpt *opt = last->opts;
size_t name_len;
list_index++;
@@ -2692,6 +2696,18 @@ vshReadlineOptionsGenerator(const char *text, const vshCmdDef *cmd)
return NULL;
}
while (opt) {
if (STREQ(opt->def->name, name)) {
exists = true;
break;
}
opt = opt->next;
}
if (exists)
continue;
if (VIR_REALLOC_N(ret, ret_size + 2) < 0) {
virStringListFree(ret);
return NULL;
@@ -2772,60 +2788,6 @@ vshCompleterFilter(char ***list,
}
static int
vshReadlineOptionsPrune(char ***list,
vshCmd *last)
{
char **newList = NULL;
size_t newList_len = 0;
size_t list_len;
size_t i;
if (!list || !*list)
return -1;
if (!last->opts)
return 0;
list_len = virStringListLength((const char **) *list);
if (VIR_ALLOC_N(newList, list_len + 1) < 0)
return -1;
for (i = 0; i < list_len; i++) {
const char *list_opt = STRSKIP((*list)[i], "--");
bool exist = false;
vshCmdOpt *opt = last->opts;
/* Should never happen (TM) */
if (!list_opt)
return -1;
while (opt) {
if (STREQ(opt->def->name, list_opt)) {
exist = true;
break;
}
opt = opt->next;
}
if (exist) {
VIR_FREE((*list)[i]);
continue;
}
VIR_STEAL_PTR(newList[newList_len], (*list)[i]);
newList_len++;
}
ignore_value(VIR_REALLOC_N_QUIET(newList, newList_len + 1));
VIR_FREE(*list);
*list = newList;
return 0;
}
static char *
vshReadlineParse(const char *text, int state)
{
@@ -2874,12 +2836,8 @@ vshReadlineParse(const char *text, int state)
if (!cmd) {
list = vshReadlineCommandGenerator(text);
} else {
if (!opt || (opt->type != VSH_OT_DATA && opt->type != VSH_OT_STRING)) {
list = vshReadlineOptionsGenerator(text, cmd);
if (vshReadlineOptionsPrune(&list, partial) < 0)
goto cleanup;
}
if (!opt || (opt->type != VSH_OT_DATA && opt->type != VSH_OT_STRING))
list = vshReadlineOptionsGenerator(text, cmd, partial);
if (opt && opt->completer) {
char **completer_list = opt->completer(autoCompleteOpaque,
@@ -3499,11 +3457,12 @@ const vshCmdInfo info_complete[] = {
{.name = NULL}
};
#ifdef WITH_READLINE
bool
cmdComplete(vshControl *ctl, const vshCmd *cmd)
{
bool ret = false;
#ifdef WITH_READLINE
const vshClientHooks *hooks = ctl->hooks;
int stdin_fileno = STDIN_FILENO;
const char *arg = "";
@@ -3552,6 +3511,17 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
cleanup:
virBufferFreeAndReset(&buf);
virStringListFree(matches);
#endif /* WITH_READLINE */
return ret;
}
#else /* !WITH_READLINE */
bool
cmdComplete(vshControl *ctl ATTRIBUTE_UNUSED,
const vshCmd *cmd ATTRIBUTE_UNUSED)
{
return false;
}
#endif /* !WITH_READLINE */