[PATCH 00/40] Replace various string helpers (and fixes for surrounding code)

Peter Krempa pkrempa at redhat.com
Sat Feb 6 08:32:22 UTC 2021


This series mainly focuses on removal of virStringListAdd which tries
to promote the use of a string list without counter variable as a
dynamic array. This means that every operation counts the number of
elements and when used in a loop resutls in O(n^2) algorithms.

To discourage it's future buggy use remove the helpers completely.

The end of the series then replaces some libvirt helpers for string
lists by the glib equivalents.

Patches:
 1-3,18,24-25,28: cleanups
 4-6: fix buggy iteration and memory handling in qemuNamespaceUnlinkPaths
 7: helpers for easy use of GSList + char *
 8-17,19-20: Don't use virStringListAdd inside of loops and prepare for
             removal
 21: Remove virStringListAdd and virStringListRemove
 22-23: Open-code and remove virStringListGetFirstWithPrefix
 26-27: Replace virStringListHasString by g_strv_contains
 29-34: Preparation and removal of virStringListLength
        (mostly inefficient iteration)
 35-37,40: Replace/reimplement virStringSplit(Count) by g_strsplit
 38-39: Replace virStringListJoin by g_strjoinv

Peter Krempa (40):
  qemuMonitorJSONObjectProperty: Make 'str' member const
  util: virmacmap: Use g_autofree for virJSONValue
  util: macmap: Remove unused cleanup labels and 'ret' variables
  qemuDomainGetPreservedMounts: Refactor to return NULL-terminated
    string lists
  qemuNamespaceUnlinkPaths: Fix wrong use of iterator variable
  qemuNamespaceUnlinkPaths: Fix inconsistent cleanup handling
  util: Add helpers for auto-freeing GSList filled with strings
  qemu: namespace: Don't use 'virStringListAdd' inside loops
  virHookCall: Don't use 'virStringListAdd' to construct list in loop
  qemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct
    list
  virCPUDefCheckFeatures: Don't use 'virStringListAdd' to construct list
  x86ModelParseFeatures: Don't construct list using 'virStringListAdd'
  virResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to
    construct list
  virResctrlMonitorGetStats: Don't use 'virStringListAdd'
  qemu: Convert 'priv->dbusVMStateIds' to a GSList
  util: macmap: Convert to use GSList for storing macs instead of string
    lists
  xenParseXLNamespaceData: Pre-calculate the length of array
  virfirewalltest: Shuffle the code around to remove a loop
  virfirewalltest: Avoid use of 'virStringListAdd'
  qemusecuritytest: Store 'notRestored' files in a hash table
  util: virstring: Remove virStringListAdd and virStringListRemove
  virCgroupGetValueForBlkDev: Rewrite lookup of returned string
  virStringListGetFirstWithPrefix: Remove unused helper
  vz: Replace virStringSplitCount(, , , NULL) with virStringSplit
  qemuProcessUpdateDevices: Refactor cleanup and memory handling
  Replace virStringListHasString by g_strv_contains
  util: virstring: Remove virStringListHasString
  virStorageBackendSheepdogAddVolume: Clean up memory handling
  qemufirmwaretest: Base iteration on string lists
  qemuvhostusertest: Base iteration on string lists
  Replace virStringListLength where actual lenght is not needed
  virPolkitCheckAuth: Avoid virStringListLength in loop condition
  Replace virStringListLength by g_strv_length
  util: virstring: Remove virStringListLength
  Replace virStringSplit with g_strsplit
  util: virstring: Remove virStringSplit
  virStringSplitCount: Reimplement using g_strsplit and g_strv_length
  Replace virStringListJoin by g_strjoinv
  util: virstring: Remove virStringListJoin
  virstringtest: Remove testing of virStringSplitCount

 src/bhyve/bhyve_command.c                     |   2 +-
 src/bhyve/bhyve_parse_command.c               |   4 +-
 src/conf/cpu_conf.c                           |  14 +-
 src/conf/storage_conf.c                       |   2 +-
 src/cpu/cpu_arm.c                             |   2 +-
 src/cpu/cpu_x86.c                             |   8 +-
 src/libvirt_private.syms                      |  11 +-
 src/libxl/libxl_conf.c                        |   8 +-
 src/libxl/xen_common.c                        |   8 +-
 src/libxl/xen_xl.c                            |  49 +--
 src/lxc/lxc_native.c                          |  14 +-
 src/qemu/qemu_capabilities.c                  |   8 +-
 src/qemu/qemu_command.c                       |   2 +-
 src/qemu/qemu_conf.c                          |   4 +-
 src/qemu/qemu_dbus.c                          |  19 +-
 src/qemu/qemu_dbus.h                          |   2 +-
 src/qemu/qemu_domain.c                        |   4 +-
 src/qemu/qemu_domain.h                        |   2 +-
 src/qemu/qemu_driver.c                        |   4 +-
 src/qemu/qemu_firmware.c                      |   5 +-
 src/qemu/qemu_interop_config.c                |  13 +-
 src/qemu/qemu_migration.c                     |  10 +-
 src/qemu/qemu_monitor.c                       |  19 +-
 src/qemu/qemu_monitor.h                       |   2 +-
 src/qemu/qemu_monitor_json.c                  |   5 +-
 src/qemu/qemu_monitor_json.h                  |   4 +-
 src/qemu/qemu_namespace.c                     | 283 +++++++++---------
 src/qemu/qemu_process.c                       |  37 +--
 src/qemu/qemu_qapi.c                          |   2 +-
 src/qemu/qemu_slirp.c                         |   7 +-
 src/qemu/qemu_vhost_user.c                    |   4 +-
 src/rpc/virnetsocket.c                        |   4 +-
 src/storage/storage_backend_sheepdog.c        |  15 +-
 src/storage/storage_backend_zfs.c             |   6 +-
 .../storage_source_backingstore.c             |   8 +-
 src/util/meson.build                          |   1 +
 src/util/vircgroup.c                          |  26 +-
 src/util/vircgroupv2.c                        |   2 +-
 src/util/vircommand.c                         |   2 +-
 src/util/virdevmapper.c                       |   2 +-
 src/util/virfile.c                            |   2 +-
 src/util/virfirewall.c                        |   2 +-
 src/util/virfirmware.c                        |   4 +-
 src/util/virglibutil.c                        |  27 ++
 src/util/virglibutil.h                        |  28 ++
 src/util/virhook.c                            |  15 +-
 src/util/virmacmap.c                          | 175 ++++++-----
 src/util/virmacmap.h                          |   6 +-
 src/util/virpolkit.c                          |  13 +-
 src/util/virprocess.c                         |   5 +-
 src/util/virresctrl.c                         |  17 +-
 src/util/virstring.c                          | 226 +-------------
 src/util/virstring.h                          |  24 +-
 src/vz/vz_sdk.c                               |   2 +-
 tests/qemufirmwaretest.c                      |  24 +-
 tests/qemumonitorjsontest.c                   |   6 +-
 tests/qemusecuritymock.c                      |  19 +-
 tests/qemusecuritytest.c                      |  14 +-
 tests/qemusecuritytest.h                      |   4 +-
 tests/qemuvhostusertest.c                     |  24 +-
 tests/qemuxml2argvtest.c                      |   2 +-
 tests/vboxsnapshotxmltest.c                   |   2 +-
 tests/virconftest.c                           |   4 +-
 tests/virfirewalltest.c                       |  30 +-
 tests/virmacmaptest.c                         |  21 +-
 tests/virstringtest.c                         | 211 +------------
 tools/virsh-completer.c                       |   7 +-
 tools/virsh-domain.c                          |  14 +-
 tools/virsh-host.c                            |   4 +-
 tools/virt-login-shell-helper.c               |   2 +-
 tools/vsh.c                                   |   2 +-
 71 files changed, 595 insertions(+), 965 deletions(-)
 create mode 100644 src/util/virglibutil.c
 create mode 100644 src/util/virglibutil.h

-- 
2.29.2




More information about the libvir-list mailing list