You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
3.0 KiB

  1. /*
  2. * virsh-completer-nodedev.c: virsh completer callbacks related to nodedev
  3. *
  4. * Copyright (C) 2019 Red Hat, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include "virsh-completer-nodedev.h"
  22. #include "conf/node_device_conf.h"
  23. #include "viralloc.h"
  24. #include "virsh-nodedev.h"
  25. #include "virsh.h"
  26. #include "virstring.h"
  27. char **
  28. virshNodeDeviceNameCompleter(vshControl *ctl,
  29. const vshCmd *cmd G_GNUC_UNUSED,
  30. unsigned int flags)
  31. {
  32. virshControlPtr priv = ctl->privData;
  33. virNodeDevicePtr *devs = NULL;
  34. int ndevs = 0;
  35. size_t i = 0;
  36. char **ret = NULL;
  37. VIR_AUTOSTRINGLIST tmp = NULL;
  38. virCheckFlags(0, NULL);
  39. if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
  40. return NULL;
  41. if ((ndevs = virConnectListAllNodeDevices(priv->conn, &devs, flags)) < 0)
  42. return NULL;
  43. if (VIR_ALLOC_N(tmp, ndevs + 1) < 0)
  44. goto cleanup;
  45. for (i = 0; i < ndevs; i++) {
  46. const char *name = virNodeDeviceGetName(devs[i]);
  47. tmp[i] = g_strdup(name);
  48. }
  49. ret = g_steal_pointer(&tmp);
  50. cleanup:
  51. for (i = 0; i < ndevs; i++)
  52. virNodeDeviceFree(devs[i]);
  53. VIR_FREE(devs);
  54. return ret;
  55. }
  56. char **
  57. virshNodeDeviceEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
  58. const vshCmd *cmd G_GNUC_UNUSED,
  59. unsigned int flags)
  60. {
  61. size_t i = 0;
  62. VIR_AUTOSTRINGLIST tmp = NULL;
  63. virCheckFlags(0, NULL);
  64. if (VIR_ALLOC_N(tmp, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0)
  65. return NULL;
  66. for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++)
  67. tmp[i] = g_strdup(virshNodeDeviceEventCallbacks[i].name);
  68. return g_steal_pointer(&tmp);
  69. }
  70. char **
  71. virshNodeDeviceCapabilityNameCompleter(vshControl *ctl,
  72. const vshCmd *cmd,
  73. unsigned int flags)
  74. {
  75. VIR_AUTOSTRINGLIST tmp = NULL;
  76. const char *cap_str = NULL;
  77. size_t i = 0;
  78. virCheckFlags(0, NULL);
  79. if (vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str) < 0)
  80. return NULL;
  81. if (VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST + 1) < 0)
  82. return NULL;
  83. for (i = 0; i < VIR_NODE_DEV_CAP_LAST; i++)
  84. tmp[i] = g_strdup(virNodeDevCapTypeToString(i));
  85. return virshCommaStringListComplete(cap_str, (const char **)tmp);
  86. }