summaryrefslogtreecommitdiff
path: root/src/esx/esx_util.c
Commit message (Collapse)AuthorAgeFilesLines
* esx: Remove unused includesPeng Liang2022-06-161-3/+0
| | | | | Signed-off-by: Peng Liang <tcx4c70@gmail.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* lib: Drop internal virXXXPtr typedefsMichal Privoznik2021-04-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | Historically, we declared pointer type to our types: typedef struct _virXXX virXXX; typedef virXXX *virXXXPtr; But usefulness of such declaration is questionable, at best. Unfortunately, we can't drop every such declaration - we have to carry some over, because they are part of public API (e.g. virDomainPtr). But for internal types - we can do drop them and use what every other C project uses 'virXXX *'. This change was generated by a very ugly shell script that generated sed script which was then called over each file in the repository. For the shell script refer to the cover letter: https://listman.redhat.com/archives/libvir-list/2021-March/msg00537.html Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* esx: replace some VIR_FREE with g_clear_pointer(x, g_free)Laine Stump2021-02-161-4/+4
| | | | | | | | | | These are all cases when 1) the pointer is passed by reference from the caller (ie.e. **) and expects it to be NULL on return if there is an error, or 2) the variable holding the pointer is being checked or re-used in the same function, but not right away. Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* esx: eliminate unnecessary cleanup: labels and result variablesLaine Stump2021-02-161-6/+2
| | | | | | | switching to g_autofree left many cleanup: sections empty. Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* esx: switch VIR_FREE->g_free when the pointer will immediately go out of scopeLaine Stump2021-02-161-2/+2
| | | | | | | Or when it will be immediately have a new value assigned to it. Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* esx: switch VIR_FREE->g_free in esx*Free*()Laine Stump2021-02-161-5/+5
| | | | | | | | | | | | | | Although the three functions esxFreePrivate(), esxFreeStreamPrivate(), and esxUtil_FreeParsedUri() are calling VIR_FREE on *object, and so in theory the caller of the function might rely on "object" (the free function's arg) being set to NULL, in practice these functions are only called from a couple places each, and in all cases the pointer that is passed is a local variable, and goes out of scope almost immediately after calling the Free function, so it is safe to change VIR_FREE() into g_free(). Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* esx: use g_autofree for char* where it is trivially possibleLaine Stump2021-02-161-8/+3
| | | | | | | | | All of these strings are allocated once, freed once, and are never returned out of the function where they are created, used, and are freed. Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* esx: switch esxUtil_ResolveHostname to return a new stringPino Toscano2020-10-051-4/+7
| | | | | | | | | | Change the interface of esxUtil_ResolveHostname() to return a newly allocated string with the result address, instead of forcing the callers to provide a buffer and its size. This way we can simply (auto)free the string, and make the function stacks smaller. Signed-off-by: Pino Toscano <ptoscano@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
* esx: call freeaddrinfo earlier in esxUtil_ResolveHostnamePino Toscano2020-10-051-3/+1
| | | | | | | | Call freeaddrinfo() as soon as @result is not needed anymore, i.e. right after getnameinfo(); this avoids calling freeaddrinfo() in two branches. Signed-off-by: Pino Toscano <ptoscano@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
* esx: use g_new0 instead of VIR_ALLOC*Ján Tomko2020-10-011-2/+1
| | | | | Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* esx: improve some of the virErrorNumber usedPino Toscano2020-09-141-1/+1
| | | | | | | | | A lot of virReportError() calls use VIR_ERR_INTERNAL_ERROR to represent the number of the error, even in cases where there is one fitting more. Hence, replace some of them with better virErrorNumber values. Signed-off-by: Pino Toscano <ptoscano@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
* esx: use g_auto() for all virBuffersLaine Stump2020-07-081-2/+2
| | | | | Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* src: convert all code to use virsocket.hDaniel P. Berrangé2020-01-291-2/+1
| | | | | | | | | | | There are a large number of different header files that are related to the sockets APIs. The virsocket.h header includes all of the relevant headers for Windows and UNIX in one convenient place. If virsocketaddr.h is already included, then there's no need for virsocket.h Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* util: buffer: Remove virBufferCheckErrorPeter Krempa2019-10-241-6/+0
| | | | | | | The function now does not return an error so we can drop it fully. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* esx: use g_strdup instead of VIR_STRDUPJán Tomko2019-10-211-22/+11
| | | | | | | | | | | Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* Use g_strdup to fill in default valuesJán Tomko2019-10-211-3/+2
| | | | | | | | | | | | Replace: if (!s && VIR_STRDUP(s, str) < 0) goto; with: if (!s) s = g_strdup(str); Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* esx: Use ESX_VI_CHECK_ARG_LIST macro to avoid code duplicationMarcos Paulo de Souza2018-07-041-4/+1
| | | | | | | | | | | | | | | By using this macro we can avoid boilerplate code to check for arrays of objects from ESX driver. This replacement was done using the coccinelle script bellow: @@ identifier ptr; @@ -if (!ptr || *ptr) { ... } +ESX_VI_CHECK_ARG_LIST(ptr); Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
* Remove unnecessary curly brackets in rest of src/esx/Martin Kletzander2014-11-141-30/+15
| | | | Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
* Use virBufferCheckError everywhere we report OOM errorJán Tomko2014-07-031-10/+2
| | | | | | | | | | | | | | | | | Replace: if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); ... } with: if (virBufferCheckError(&buf) < 0) ... This should not be a functional change (unless some callers misused the virBuffer APIs - a different error would be reported then)
* Indent top-level labels by one space in src/esx/Ján Tomko2014-03-251-3/+3
|
* Add virLogSource variables to all source filesDaniel P. Berrange2014-03-181-1/+1
| | | | | | | | | Any source file which calls the logging APIs now needs to have a VIR_LOG_INIT("source.name") declaration at the start of the file. This provides a static variable of the virLogSource type. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Don't leave empty first line in C source filesMartin Kletzander2014-03-181-1/+0
| | | | | | | | | | | | If there should be some sort of separator it is better to use comment with the filename, copyright, description, license information and authors. Found by: git grep -nH '^$' | grep '\.[ch]:1:' Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
* esx: Remove unnecessary NULL comparisons (2/3)Geoff Hickey2013-10-171-24/+24
| | | | | | | | Code cleanup: remove explicit NULL comparisons like ptr == NULL and ptr != NULL from the ESX code, replacing them with the simpler ptr and !ptr. Part two of three.
* Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} filesDaniel P. Berrange2013-07-101-1/+1
| | | | | | | | | Convert the type of loop iterators named 'i', 'j', k', 'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or 'unsigned int', also santizing 'ii', 'jj', 'kk' to use the normal 'i', 'j', 'k' naming Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Adapt to VIR_ALLOC and virAsprintf in src/esx/*Michal Privoznik2013-07-101-3/+1
|
* esx: Replace almost all esxVI_String_DeepCopyValue vith VIR_STRDUPMatthias Bolte2013-05-211-7/+4
|
* Adapt to VIR_STRDUP and VIR_STRNDUP in src/esx/*Michal Privoznik2013-05-091-35/+10
|
* virutil: Move string related functions to virstring.cMichal Privoznik2013-05-021-1/+1
| | | | | | | | The source code base needs to be adapted as well. Some files include virutil.h just for the string related functions (here, the include is substituted to match the new file), some include virutil.h without any need (here, the include is removed), and some require both.
* Rename uuid.{c,h} to viruuid.{c,h}Daniel P. Berrange2012-12-211-1/+1
|
* Rename util.{c,h} to virutil.{c,h}Daniel P. Berrange2012-12-211-1/+1
|
* Rename memory.{c,h} to viralloc.{c,h}Daniel P. Berrange2012-12-211-1/+1
|
* Rename logging.{c,h} to virlog.{c,h}Daniel P. Berrange2012-12-211-1/+1
|
* maint: fix up copyright notice inconsistenciesEric Blake2012-09-201-1/+1
| | | | | | | | | https://www.gnu.org/licenses/gpl-howto.html recommends that the 'If not, see <url>.' phrase be a separate sentence. * tests/securityselinuxhelper.c: Remove doubled line. * tests/securityselinuxtest.c: Likewise. * globally: s/; If/. If/
* maint: fix missing spaces in messageEric Blake2012-09-121-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | I got an off-list report about a bad diagnostic: Target network card mac 52:54:00:49:07:ccdoes not match source 52:54:00:49:07:b8 True to form, I've added a syntax check rule to prevent it from recurring, and found several other offenders. * cfg.mk (sc_require_whitespace_in_translation): New rule. * src/conf/domain_conf.c (virDomainNetDefCheckABIStability): Add space. * src/esx/esx_util.c (esxUtil_ParseUri): Likewise. * src/qemu/qemu_command.c (qemuCollectPCIAddress): Likewise. * src/qemu/qemu_driver.c (qemuDomainSetMetadata) (qemuDomainGetMetadata): Likewise. * src/qemu/qemu_hotplug.c (qemuDomainChangeNetBridge): Likewise. * src/rpc/virnettlscontext.c (virNetTLSContextCheckCertDNWhitelist): Likewise. * src/vmware/vmware_driver.c (vmwareDomainResume): Likewise. * src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives): Avoid false negatives. * tools/virsh-domain.c (info_save_image_dumpxml): Reword. Based on a report by Luwen Su.
* Desert the FSF address in copyrightOsier Yang2012-07-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | Per the FSF address could be changed from time to time, and GNU recommends the following now: (http://www.gnu.org/licenses/gpl-howto.html) You should have received a copy of the GNU General Public License along with Foobar. If not, see <http://www.gnu.org/licenses/>. This patch removes the explicit FSF address, and uses above instead (of course, with inserting 'Lesser' before 'General'). Except a bunch of files for security driver, all others are changed automatically, the copyright for securify files are not complete, that's why to do it manually: src/security/security_selinux.h src/security/security_driver.h src/security/security_selinux.c src/security/security_apparmor.h src/security/security_apparmor.c src/security/security_driver.c
* Replace use of ESX_ERROR & ESX_VI_ERROR with virReportErrorDaniel P. Berrange2012-07-201-37/+37
| | | | | | | Update the ESX driver to use virReportError instead of the ESX_ERROR & ESX_VI_ERROR custom macros Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Consistent style for usage of sizeof operatorDaniel P. Berrange2012-03-301-1/+1
| | | | | | | | | | | | | The code is splattered with a mix of sizeof foo sizeof (foo) sizeof(foo) Standardize on sizeof(foo) and add a syntax check rule to enforce it Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Convert drivers over to use virURIPtr for query paramsDaniel P. Berrange2012-03-231-15/+2
| | | | | | | | | | | | | Convert drivers currently using the qparams APIs, to instead use the virURIPtr query parameters directly. * src/esx/esx_util.c, src/hyperv/hyperv_util.c, src/remote/remote_driver.c, src/xenapi/xenapi_utils.c: Remove use of qparams * src/util/qparams.h, src/util/qparams.c: Delete * src/Makefile.am, src/libvirt_private.syms: Remove qparams Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Use a libvirt custom struct for virURIPtrDaniel P. Berrange2012-03-231-4/+0
| | | | | | | | | Instead of just typedef'ing the xmlURIPtr struct for virURIPtr, use a custom libvirt struct. This allows us to fix various problems with libxml2. This initially just fixes the query vs query_raw handling problems. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Fixed URI parsingMartin Kletzander2012-02-241-1/+1
| | | | | | | | | | | | | | | | | | | | | Function xmlParseURI does not remove square brackets around IPv6 address when parsing. One of the solutions is making wrappers around functions working with xmlURI*. This assures that uri->server will be always properly assigned and it doesn't have to be changed when used on some new place in the code. For this purpose, functions virParseURI and virSaveURI were added. These function are wrappers around xmlParseURI and xmlSaveUri respectively. Also there is one new syntax check function to prohibit these functions anywhere else. File changes: - src/util/viruri.h -- declaration - src/util/viruri.c -- definition - src/libvirt_private.syms -- symbol export - src/Makefile.am -- added source and header files - cfg.mk -- added sc_prohibit_xmlURI - all others -- ID name and include fixes
* maint: typo fixesEric Blake2011-12-011-2/+2
| | | | | | | | | | | | | | | | | | | Many of these were mentioned by Yuri Chornoivan in: https://bugzilla.redhat.com/show_bug.cgi?id=669506 * src/esx/esx_vi.c (esxVI_WaitForTaskCompletion): Fix spelling. * src/conf/netdev_vport_profile_conf.c (virNetDevVPortProfileParse): Likewise. * src/xen/xend_internal.c (xenDaemonDomainSetVcpusFlags): Likewise. * src/xen/xm_internal.c (xenXMDomainSetVcpusFlags): Likewise. * src/esx/esx_util.c (esxUtil_ResolveHostname): Likewise. * src/storage/storage_backend_fs.c (virStorageBackendFileSystemBuild): Likewise. * daemon/libvirtd.conf: Likewise. * src/util/logging.c (virLogMessage): Likewise. * src/uml/uml_conf.c (umlBuildCommandLineNet): Likewise. * src/vmx/vmx.c (virVMXFormatEthernet): Likewise.
* esx: Support folders in the path of vpx:// connection URIsMatthias Bolte2011-11-011-19/+3
| | | | | | | | | | | | | | | | | | | | Allow the datacenter and compute resource parts of the path to be prefixed with folders. Therefore, the way the path is parsed has changed. Before, it was split in 2 or 3 items and the items' meanings were determined by their positions. Now the path can have 2 or more items and the the vCenter server is asked whether a folder, datacenter of compute resource with the specified name exists at the current hierarchy level. Before the datacenter and compute resource lookup automatically traversed folders during lookup. This is logic got removed and folders have to be specified explicitly. The proper datacenter path including folders is now used when accessing a datastore over HTTPS. This makes virsh dumpxml and define work for datacenters in folders. https://bugzilla.redhat.com/show_bug.cgi?id=732676
* esx: Remove dead store in esxUtil_ParseDatastorePathMatthias Bolte2011-05-041-6/+5
| | | | | | | | | | | The ++ on preliminaryFileName was a left over from a previous version of this function that explicitly returned the filename and did a strdup on preliminaryFileName afterwards. As the filename isn't returned explicitly anymore remove the preliminary variable for it and reuse the tmp variable instead. Reported by Eric Blake, detected by clang.
* esx: Escape password for XMLMatthias Bolte2011-03-031-0/+19
| | | | | | | Passwords are allowed to contain <, >, &, ', " characters. Those need to be replaced by the corresponding entities. Reported by Hereward Cooper.
* esx: Move VMX handling code out of the driver directoryMatthias Bolte2010-12-211-307/+2
| | | | | | | | | | | Now the VMware driver doesn't depend on the ESX driver anymore. Add a WITH_VMX option that depends on WITH_ESX and WITH_VMWARE. Also add a libvirt_vmx.syms file. Move some escaping functions from esx_util.c to vmx.c. Adapt the test suite, ESX and VMware driver to the new code layout.
* esx: Handle non-UTF-8 encoded VMX filesMatthias Bolte2010-10-191-3/+41
| | | | | | | | ESX(i) uses UTF-8, but a Windows based GSX server writes Windows-1252 encoded VMX files. Add a test case to ensure that libxml2 provides Windows-1252 to UTF-8 conversion.
* esx: Handle name escaping properlyMatthias Bolte2010-10-141-0/+198
| | | | | | | VMware uses a mix of percent-, pipe- and base64-encoding in different combinations in different places. Add a testcase for this.
* esx: Use the VirtualDisk UUID as storage volume keyMatthias Bolte2010-09-041-0/+19
| | | | | | VirtualDisks are .vmdk file based. Other files in a datastore like .iso or .flp files don't have a UUID attached, fall back to the path as key for them.
* esx: Rework datastore path parsing and handlingMatthias Bolte2010-09-031-30/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of splitting the path part of a datastore path into directory and file name, keep this in one piece. An example: "[datastore] directory/file" was split into this before: datastoreName = "datastore" directoryName = "directory" fileName = "file" Now it's split into this: datastoreName = "datastore" directoryName = "directory" directoryAndFileName = "directory/file" This simplifies code using esxUtil_ParseDatastorePath, because directoryAndFileName is used more often than fileName. Also the old approach expected the datastore path to reference an actual file, but this isn't always correct, especially when listing volumes. In that case esxUtil_ParseDatastorePath is used to parse a path that references a directory. This fails for a vpx:// connection because the vCenter returns directory paths with a trailing '/'. The new approach is robust against this and the actual decision if the datastore path should reference a file or a directory is up to the caller of esxUtil_ParseDatastorePath. Update the tests accordingly.
* esx: Make storage pool lookup by name and UUID more robustMatthias Bolte2010-08-021-12/+10
| | | | | | | | | | Don't rely on summary.url anymore, because its value is different between an esx:// and vpx:// connection. Use host.mountInfo.path instead. Don't fallback to lookup by UUID (actually lookup by absolute path) in esxVI_LookupDatastoreByName when lookup by name fails. Add a seperate function for this: esxVI_LookupDatastoreByAbsolutePath