[libvirt] [PATCHv2 00/27] flags cleanup

Addressing my review comments from round 1, and introducing a few more goodies along the way. I've added some syntax checks to make it easier to stick with this style in the future. v1 was at https://www.redhat.com/archives/libvir-list/2011-July/msg00264.html, with patches 1-5 already applied, and patches 6-20 of that series revamped in this series as 5-19. Patches 1-4 and 20-27 in this series are new. Eric Blake (27): maint: exclude more files from syntax check maint: print flags in hex during debug build: also check qemu_protocol for on-the-wire stability libvirt-qemu: use unsigned flags util: reject unknown flags, and prefer unsigned flags node_device: reject unknown flags storage: reject unknown flags esx: reject unknown flags libxl: reject unknown flags lxc: reject unknown flags openvz: reject unknown flags phyp: reject unknown flags qemu: reject unknown flags test: reject unknown flags uml: reject unknown flags vbox: reject unknown flags vmware: reject unknown flags xen: reject unknown flags xenapi: reject unknown flags virsh, daemon: prefer unsigned flags node_device: avoid implicit int python: prefer unsigned flags conf: prefer unsigned flags build: don't hand-roll cloexec code conf: delete unused flags arguments remote: prefer unsigned flags build: add syntax check for proper flags use cfg.mk | 49 +++++++++--- daemon/remote.c | 2 +- python/libvirt-override.c | 6 +- src/Makefile.am | 20 +++-- src/conf/cpu_conf.c | 6 +- src/conf/cpu_conf.h | 6 +- src/conf/domain_conf.c | 24 ++---- src/conf/node_device_conf.h | 58 +++++++------- src/conf/storage_conf.c | 4 +- src/datatypes.h | 4 +- src/esx/esx_device_monitor.c | 4 +- src/esx/esx_driver.c | 28 +++++-- src/esx/esx_interface_driver.c | 4 +- src/esx/esx_network_driver.c | 4 +- src/esx/esx_nwfilter_driver.c | 4 +- src/esx/esx_secret_driver.c | 4 +- src/esx/esx_storage_driver.c | 4 +- src/fdstream.c | 28 +++--- src/fdstream.h | 6 +- src/interface/netcf_driver.c | 16 +++- src/libvirt-qemu.c | 5 +- src/libxl/libxl_driver.c | 18 +++- src/locking/lock_driver_nop.c | 13 ++-- src/locking/lock_driver_sanlock.c | 3 +- src/locking/lock_manager.c | 18 +++-- src/lxc/lxc_container.c | 4 +- src/lxc/lxc_driver.c | 12 ++- src/network/bridge_driver.c | 9 ++- src/node_device/node_device_driver.c | 18 +++- src/node_device/node_device_hal.c | 4 +- src/node_device/node_device_udev.c | 4 +- src/nodeinfo.h | 6 +- src/nwfilter/nwfilter_driver.c | 4 +- src/openvz/openvz_driver.c | 9 ++- src/phyp/phyp_driver.c | 12 ++- src/qemu/qemu_domain.c | 21 +++--- src/qemu/qemu_domain.h | 4 +- src/qemu/qemu_driver.c | 30 +++++-- src/qemu/qemu_migration.c | 32 ++++---- src/qemu/qemu_monitor.c | 10 +- src/qemu_protocol-structs | 14 +++ src/remote/qemu_protocol.x | 4 +- src/remote/remote_driver.c | 6 +- src/rpc/virnetserverclient.c | 2 +- src/secret/secret_driver.c | 17 +++- src/storage/storage_backend.c | 12 ++- src/storage/storage_backend_disk.c | 10 ++- src/storage/storage_backend_fs.c | 26 +++++-- src/storage/storage_backend_iscsi.c | 4 +- src/storage/storage_backend_logical.c | 18 +++- src/storage/storage_driver.c | 45 ++++++++-- src/test/test_driver.c | 144 +++++++++++++++++++++++++------- src/uml/uml_driver.c | 33 +++----- src/util/bridge.c | 19 +--- src/util/command.c | 18 ++-- src/util/iohelper.c | 18 ++-- src/util/logging.c | 13 +++- src/util/logging.h | 8 +- src/util/util.c | 14 ++-- src/vbox/vbox_driver.c | 5 +- src/vbox/vbox_tmpl.c | 44 ++++++++-- src/vmware/vmware_driver.c | 17 +++- src/xen/xen_driver.c | 12 ++- src/xen/xen_hypervisor.c | 8 ++- src/xen/xen_inotify.c | 4 +- src/xen/xend_internal.c | 23 ++++-- src/xen/xend_internal.h | 3 +- src/xen/xm_internal.c | 11 ++- src/xen/xm_internal.h | 2 +- src/xen/xs_internal.c | 12 ++- src/xenapi/xenapi_driver.c | 13 +++- tools/virsh.c | 2 +- 72 files changed, 731 insertions(+), 367 deletions(-) create mode 100644 src/qemu_protocol-structs -- 1.7.4.4

* cfg.mk (VC_LIST_ALWAYS_EXCLUDE_REGEX): Exempt docs/api_extension/*.patch. (exclude_file_name_regexp--sc_prohibit_always_true_header_tests) (exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF) (exclude_file_name_regexp--sc_prohibit_fork_wrappers) (exclude_file_name_regexp--sc_trailing_blank): Simplify. (exclude_file_name_regexp--sc_prohibit_gettext_noop): Delete. (exclude_file_name_regexp--sc_prohibit_close) (exclude_file_name_regexp--sc_prohibit_nonreentrant) (exclude_file_name_regexp--sc_prohibit_sprintf): Tighten. --- v2: new patch cfg.mk | 19 +++++++++---------- 1 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cfg.mk b/cfg.mk index b00cda3..f266bb0 100644 --- a/cfg.mk +++ b/cfg.mk @@ -74,7 +74,8 @@ local-checks-to-skip = \ sc_useless_cpp_parens # Files that should never cause syntax check failures. -VC_LIST_ALWAYS_EXCLUDE_REGEX = (^(HACKING|docs/news\.html\.in)|\.po)$$ +VC_LIST_ALWAYS_EXCLUDE_REGEX = \ + (^(HACKING|docs/(news\.html\.in|.*\.patch))|\.po)$$ # Functions like free() that are no-ops on NULL arguments. useless_free_options = \ @@ -633,36 +634,34 @@ exclude_file_name_regexp--sc_prohibit_VIR_ERR_NO_MEMORY = \ exclude_file_name_regexp--sc_prohibit_access_xok = ^src/util/util\.c$$ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ - (^docs|^python/(libvirt-override|typewrappers)\.c$$) + ^python/(libvirt-override|typewrappers)\.c$$ exclude_file_name_regexp--sc_prohibit_asprintf = \ ^(bootstrap.conf$$|src/util/util\.c$$|examples/domain-events/events-c/event-test\.c$$) exclude_file_name_regexp--sc_prohibit_close = \ - (\.p[yl]$$|^docs/|(src/util/files\.c|src/libvirt\.c)$$) + (\.p[yl]$$|^docs/|^(src/util/files\.c|src/libvirt\.c)$$) exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = \ - (^docs/api_extension/|^tests/qemuhelpdata/|\.(gif|ico|png)$$) + (^tests/qemuhelpdata/|\.(gif|ico|png)$$) _src2=src/(util/command|libvirt|lxc/lxc_controller) exclude_file_name_regexp--sc_prohibit_fork_wrappers = \ - (^docs|^($(_src2)|tests/testutils|daemon/libvirtd)\.c$$) + (^($(_src2)|tests/testutils|daemon/libvirtd)\.c$$) exclude_file_name_regexp--sc_prohibit_gethostname = ^src/util/util\.c$$ -exclude_file_name_regexp--sc_prohibit_gettext_noop = ^docs/ - exclude_file_name_regexp--sc_prohibit_newline_at_end_of_diagnostic = \ ^src/rpc/gendispatch\.pl$$ exclude_file_name_regexp--sc_prohibit_nonreentrant = \ - ^((po|docs|tests)/|tools/(virsh|console)\.c$$) + ^((po|tests)/|docs/.*py$$|tools/(virsh|console)\.c$$) exclude_file_name_regexp--sc_prohibit_readlink = ^src/util/util\.c$$ exclude_file_name_regexp--sc_prohibit_setuid = ^src/util/util\.c$$ -exclude_file_name_regexp--sc_prohibit_sprintf = ^(docs/|HACKING$$) +exclude_file_name_regexp--sc_prohibit_sprintf = ^docs/hacking\.html\.in$$ exclude_file_name_regexp--sc_prohibit_strncpy = \ ^(src/util/util|tools/virsh)\.c$$ @@ -673,7 +672,7 @@ exclude_file_name_regexp--sc_require_config_h = ^examples/ exclude_file_name_regexp--sc_require_config_h_first = ^examples/ -exclude_file_name_regexp--sc_trailing_blank = (^docs/|\.(fig|gif|ico|png)$$) +exclude_file_name_regexp--sc_trailing_blank = \.(fig|gif|ico|png)$$ exclude_file_name_regexp--sc_unmarked_diagnostics = \ ^(docs/apibuild.py|tests/virt-aa-helper-test)$$ -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* cfg.mk (VC_LIST_ALWAYS_EXCLUDE_REGEX): Exempt docs/api_extension/*.patch. (exclude_file_name_regexp--sc_prohibit_always_true_header_tests) (exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF) (exclude_file_name_regexp--sc_prohibit_fork_wrappers) (exclude_file_name_regexp--sc_trailing_blank): Simplify. (exclude_file_name_regexp--sc_prohibit_gettext_noop): Delete. (exclude_file_name_regexp--sc_prohibit_close) (exclude_file_name_regexp--sc_prohibit_nonreentrant) (exclude_file_name_regexp--sc_prohibit_sprintf): Tighten. ---
v2: new patch
cfg.mk | 19 +++++++++---------- 1 files changed, 9 insertions(+), 10 deletions(-)
Looks good and make syntax-check still passes, ACK. -- Matthias Bolte http://photron.blogspot.com

Continuation of commit 313ac7fd, and enforce things with a syntax check. Technically, virNetServerClientCalculateHandleMode is not printing a mode_t, but rather a collection of VIR_EVENT_HANDLE_* bits; however, these bits are < 8, so there is no different in the output, and that was the easiest way to silence the new syntax check. * cfg.mk (sc_flags_debug): New syntax check. (exclude_file_name_regexp--sc_flags_debug): Add exemptions. * src/fdstream.c (virFDStreamOpenFileInternal): Print flags in hex, mode_t in octal. * src/libvirt-qemu.c (virDomainQemuMonitorCommand): Likewise. * src/locking/lock_driver_nop.c (virLockManagerNopInit): Likewise. * src/locking/lock_driver_sanlock.c (virLockManagerSanlockInit): Likewise. * src/locking/lock_manager.c: Likewise. * src/qemu/qemu_migration.c: Likewise. * src/qemu/qemu_monitor.c: Likewise. * src/rpc/virnetserverclient.c (virNetServerClientCalculateHandleMode): Print mode with %o. --- v2: new patch, first new syntax check cfg.mk | 11 +++++++++++ src/fdstream.c | 2 +- src/libvirt-qemu.c | 5 +++-- src/locking/lock_driver_nop.c | 3 ++- src/locking/lock_driver_sanlock.c | 3 ++- src/locking/lock_manager.c | 11 ++++++----- src/qemu/qemu_migration.c | 16 ++++++++-------- src/qemu/qemu_monitor.c | 10 +++++----- src/rpc/virnetserverclient.c | 2 +- 9 files changed, 39 insertions(+), 24 deletions(-) diff --git a/cfg.mk b/cfg.mk index f266bb0..24539b1 100644 --- a/cfg.mk +++ b/cfg.mk @@ -269,6 +269,15 @@ sc_avoid_write: halt='consider using safewrite instead of write' \ $(_sc_search_regexp) +# In debug statements, print flags as bitmask and mode_t as octal. +sc_flags_debug: + @prohibit='\<mode=%[0-9.]*[diux]' \ + halt='debug mode_t values with %o' \ + $(_sc_search_regexp) + @prohibit='\<flags=%[0-9.]*l*[diou]' \ + halt='debug flag values with %x' \ + $(_sc_search_regexp) + # Avoid functions that can lead to double-close bugs. sc_prohibit_close: @prohibit='([^>.]|^)\<[fp]?close *\(' \ @@ -623,6 +632,8 @@ exclude_file_name_regexp--sc_avoid_write = \ exclude_file_name_regexp--sc_bindtextdomain = ^(tests|examples)/ +exclude_file_name_regexp--sc_flags_debug = ^docs/ + exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics = \ ^src/rpc/gendispatch\.pl$$ diff --git a/src/fdstream.c b/src/fdstream.c index 54f8198..c9fe2f3 100644 --- a/src/fdstream.c +++ b/src/fdstream.c @@ -516,7 +516,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, int errfd = -1; pid_t pid = 0; - VIR_DEBUG("st=%p path=%s flags=%d offset=%llu length=%llu mode=%d delete=%d", + VIR_DEBUG("st=%p path=%s flags=%x offset=%llu length=%llu mode=%o delete=%d", st, path, flags, offset, length, mode, delete); if (flags & O_CREAT) diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c index 46727c8..f03f804 100644 --- a/src/libvirt-qemu.c +++ b/src/libvirt-qemu.c @@ -2,7 +2,7 @@ * libvirt-qemu.c: Interfaces for the libvirt library to handle qemu-specific * APIs. * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -42,7 +42,8 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, { virConnectPtr conn; - VIR_DEBUG("domain=%p, cmd=%s, result=%p, flags=%u", domain, cmd, result, flags); + VIR_DEBUG("domain=%p, cmd=%s, result=%p, flags=%x", + domain, cmd, result, flags); virResetLastError(); diff --git a/src/locking/lock_driver_nop.c b/src/locking/lock_driver_nop.c index 0fab54c..0dcd794 100644 --- a/src/locking/lock_driver_nop.c +++ b/src/locking/lock_driver_nop.c @@ -31,7 +31,8 @@ static int virLockManagerNopInit(unsigned int version, const char *configFile, unsigned int flags) { - VIR_DEBUG("version=%u configFile=%s flags=%u", version, NULLSTR(configFile), flags); + VIR_DEBUG("version=%u configFile=%s flags=%x", + version, NULLSTR(configFile), flags); return 0; } diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index cd2bbb5..e6b2f1b 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -265,7 +265,8 @@ static int virLockManagerSanlockInit(unsigned int version, const char *configFile, unsigned int flags) { - VIR_DEBUG("version=%u configFile=%s flags=%u", version, NULLSTR(configFile), flags); + VIR_DEBUG("version=%u configFile=%s flags=%x", + version, NULLSTR(configFile), flags); virCheckFlags(0, -1); if (driver) diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c index 4ee7f44..d27cf8f 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -286,7 +286,7 @@ virLockManagerPtr virLockManagerNew(virLockManagerPluginPtr plugin, unsigned int flags) { virLockManagerPtr lock; - VIR_DEBUG("plugin=%p type=%u nparams=%zu params=%p flags=%u", + VIR_DEBUG("plugin=%p type=%u nparams=%zu params=%p flags=%x", plugin, type, nparams, params, flags); virLockManagerLogParams(nparams, params); @@ -315,7 +315,7 @@ int virLockManagerAddResource(virLockManagerPtr lock, virLockManagerParamPtr params, unsigned int flags) { - VIR_DEBUG("lock=%p type=%u name=%s nparams=%zu params=%p flags=%u", + VIR_DEBUG("lock=%p type=%u name=%s nparams=%zu params=%p flags=%x", lock, type, name, nparams, params, flags); virLockManagerLogParams(nparams, params); @@ -332,7 +332,8 @@ int virLockManagerAcquire(virLockManagerPtr lock, unsigned int flags, int *fd) { - VIR_DEBUG("lock=%p state='%s' flags=%u fd=%p", lock, NULLSTR(state), flags, fd); + VIR_DEBUG("lock=%p state='%s' flags=%x fd=%p", + lock, NULLSTR(state), flags, fd); CHECK_MANAGER(drvAcquire, -1); @@ -347,7 +348,7 @@ int virLockManagerRelease(virLockManagerPtr lock, char **state, unsigned int flags) { - VIR_DEBUG("lock=%p state=%p flags=%u", lock, state, flags); + VIR_DEBUG("lock=%p state=%p flags=%x", lock, state, flags); CHECK_MANAGER(drvRelease, -1); @@ -359,7 +360,7 @@ int virLockManagerInquire(virLockManagerPtr lock, char **state, unsigned int flags) { - VIR_DEBUG("lock=%p state=%p flags=%u", lock, state, flags); + VIR_DEBUG("lock=%p state=%p flags=%x", lock, state, flags); CHECK_MANAGER(drvInquire, -1); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index d7b27a0..48fc0c0 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1443,7 +1443,7 @@ static int doNativeMigrate(struct qemud_driver *driver, unsigned int background_flags = QEMU_MONITOR_MIGRATE_BACKGROUND; qemuMigrationCookiePtr mig = NULL; VIR_DEBUG("driver=%p, vm=%p, uri=%s, cookiein=%s, cookieinlen=%d, " - "cookieout=%p, cookieoutlen=%p, flags=%u, dname=%s, resource=%lu", + "cookieout=%p, cookieoutlen=%p, flags=%x, dname=%s, resource=%lu", driver, vm, uri, NULLSTR(cookiein), cookieinlen, cookieout, cookieoutlen, flags, NULLSTR(dname), resource); @@ -1661,7 +1661,7 @@ static int doTunnelMigrate(struct qemud_driver *driver, qemuMigrationCookiePtr mig = NULL; qemuMigrationIOThreadPtr iothread = NULL; VIR_DEBUG("driver=%p, vm=%p, st=%p, cookiein=%s, cookieinlen=%d, " - "cookieout=%p, cookieoutlen=%p, flags=%lu, resource=%lu", + "cookieout=%p, cookieoutlen=%p, flags=%lx, resource=%lu", driver, vm, st, NULLSTR(cookiein), cookieinlen, cookieout, cookieoutlen, flags, resource); @@ -1886,7 +1886,7 @@ static int doPeer2PeerMigrate2(struct qemud_driver *driver, int cancelled; virStreamPtr st = NULL; VIR_DEBUG("driver=%p, sconn=%p, dconn=%p, vm=%p, dconnuri=%s, " - "flags=%lu, dname=%s, resource=%lu", + "flags=%lx, dname=%s, resource=%lu", driver, sconn, dconn, vm, NULLSTR(dconnuri), flags, NULLSTR(dname), resource); @@ -2029,7 +2029,7 @@ static int doPeer2PeerMigrate3(struct qemud_driver *driver, int cancelled; virStreamPtr st = NULL; VIR_DEBUG("driver=%p, sconn=%p, dconn=%p, vm=%p, xmlin=%s, " - "dconnuri=%s, uri=%s, flags=%lu, dname=%s, resource=%lu", + "dconnuri=%s, uri=%s, flags=%lx, dname=%s, resource=%lu", driver, sconn, dconn, vm, NULLSTR(xmlin), NULLSTR(dconnuri), NULLSTR(uri), flags, NULLSTR(dname), resource); @@ -2199,7 +2199,7 @@ static int doPeer2PeerMigrate(struct qemud_driver *driver, virConnectPtr dconn = NULL; bool p2p; VIR_DEBUG("driver=%p, sconn=%p, vm=%p, xmlin=%s, dconnuri=%s, " - "uri=%s, flags=%lu, dname=%s, resource=%lu", + "uri=%s, flags=%lx, dname=%s, resource=%lu", driver, sconn, vm, NULLSTR(xmlin), NULLSTR(dconnuri), NULLSTR(uri), flags, NULLSTR(dname), resource); @@ -2278,7 +2278,7 @@ int qemuMigrationPerform(struct qemud_driver *driver, qemuDomainObjPrivatePtr priv = vm->privateData; VIR_DEBUG("driver=%p, conn=%p, vm=%p, xmlin=%s, dconnuri=%s, " "uri=%s, cookiein=%s, cookieinlen=%d, cookieout=%p, " - "cookieoutlen=%p, flags=%lu, dname=%s, resource=%lu, v3proto=%d", + "cookieoutlen=%p, flags=%lx, dname=%s, resource=%lu, v3proto=%d", driver, conn, vm, NULLSTR(xmlin), NULLSTR(dconnuri), NULLSTR(uri), NULLSTR(cookiein), cookieinlen, cookieout, cookieoutlen, flags, NULLSTR(dname), @@ -2444,7 +2444,7 @@ qemuMigrationFinish(struct qemud_driver *driver, qemuDomainObjPrivatePtr priv = NULL; qemuMigrationCookiePtr mig = NULL; VIR_DEBUG("driver=%p, dconn=%p, vm=%p, cookiein=%s, cookieinlen=%d, " - "cookieout=%p, cookieoutlen=%p, flags=%lu, retcode=%d", + "cookieout=%p, cookieoutlen=%p, flags=%lx, retcode=%d", driver, dconn, vm, NULLSTR(cookiein), cookieinlen, cookieout, cookieoutlen, flags, retcode); virErrorPtr orig_err = NULL; @@ -2612,7 +2612,7 @@ int qemuMigrationConfirm(struct qemud_driver *driver, virDomainEventPtr event = NULL; int rv = -1; VIR_DEBUG("driver=%p, conn=%p, vm=%p, cookiein=%s, cookieinlen=%d, " - "flags=%u, retcode=%d", + "flags=%x, retcode=%d", driver, conn, vm, NULLSTR(cookiein), cookieinlen, flags, retcode); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 8573262..0ce822b 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1513,7 +1513,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon, int fd) { int ret; - VIR_DEBUG("mon=%p fd=%d flags=%u", + VIR_DEBUG("mon=%p fd=%d flags=%x", mon, fd, flags); if (!mon) { @@ -1546,7 +1546,7 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon, { int ret; char *uri = NULL; - VIR_DEBUG("mon=%p hostname=%s port=%d flags=%u", + VIR_DEBUG("mon=%p hostname=%s port=%d flags=%x", mon, hostname, port, flags); if (!mon) { @@ -1578,7 +1578,7 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon, char *argstr; char *dest = NULL; int ret = -1; - VIR_DEBUG("mon=%p argv=%p flags=%u", + VIR_DEBUG("mon=%p argv=%p flags=%x", mon, argv, flags); if (!mon) { @@ -1619,7 +1619,7 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon, char *dest = NULL; int ret = -1; char *safe_target = NULL; - VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%u", + VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%x", mon, argv, target, offset, flags); if (!mon) { @@ -1682,7 +1682,7 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, { char *dest = NULL; int ret = -1; - VIR_DEBUG("mon=%p, unixfile=%s flags=%u", + VIR_DEBUG("mon=%p, unixfile=%s flags=%x", mon, unixfile, flags); if (!mon) { diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 742c3a4..341981f 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -156,7 +156,7 @@ virNetServerClientCalculateHandleMode(virNetServerClientPtr client) { if (client->tx) mode |= VIR_EVENT_HANDLE_WRITABLE; } - VIR_DEBUG("mode=%d", mode); + VIR_DEBUG("mode=%o", mode); return mode; } -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
Continuation of commit 313ac7fd, and enforce things with a syntax check.
Technically, virNetServerClientCalculateHandleMode is not printing a mode_t, but rather a collection of VIR_EVENT_HANDLE_* bits; however, these bits are < 8, so there is no different in the output, and that was the easiest way to silence the new syntax check.
* cfg.mk (sc_flags_debug): New syntax check. (exclude_file_name_regexp--sc_flags_debug): Add exemptions. * src/fdstream.c (virFDStreamOpenFileInternal): Print flags in hex, mode_t in octal. * src/libvirt-qemu.c (virDomainQemuMonitorCommand): Likewise. * src/locking/lock_driver_nop.c (virLockManagerNopInit): Likewise. * src/locking/lock_driver_sanlock.c (virLockManagerSanlockInit): Likewise. * src/locking/lock_manager.c: Likewise. * src/qemu/qemu_migration.c: Likewise. * src/qemu/qemu_monitor.c: Likewise. * src/rpc/virnetserverclient.c (virNetServerClientCalculateHandleMode): Print mode with %o. ---
v2: new patch, first new syntax check
cfg.mk | 11 +++++++++++ src/fdstream.c | 2 +- src/libvirt-qemu.c | 5 +++-- src/locking/lock_driver_nop.c | 3 ++- src/locking/lock_driver_sanlock.c | 3 ++- src/locking/lock_manager.c | 11 ++++++----- src/qemu/qemu_migration.c | 16 ++++++++-------- src/qemu/qemu_monitor.c | 10 +++++----- src/rpc/virnetserverclient.c | 2 +- 9 files changed, 39 insertions(+), 24 deletions(-)
flags_debug src/libvirt-qemu.c:117: VIR_DEBUG("conn=%p, pid=%u, flags=%u", conn, pid, flags); maint.mk: debug flag values with %x Dan commited this after you posted your series. So ACK with that new offender fix too. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 03:49 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
Continuation of commit 313ac7fd, and enforce things with a syntax check.
Technically, virNetServerClientCalculateHandleMode is not printing a mode_t, but rather a collection of VIR_EVENT_HANDLE_* bits; however, these bits are < 8, so there is no different in the output, and that was the easiest way to silence the new syntax check.
flags_debug src/libvirt-qemu.c:117: VIR_DEBUG("conn=%p, pid=%u, flags=%u", conn, pid, flags); maint.mk: debug flag values with %x
Dan commited this after you posted your series. So ACK with that new offender fix too.
Yep, I noticed that while rebasing as well. Fixed and pushed, along with patch 1/27. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Since we are going to add some libvirt-qemu.so entry points in 0.9.4, we might as well start checking for RPC stability, just as for libvirt.so. * src/Makefile.am (PROTOCOL_STRUCTS): New variable. (remote_protocol-structs): Rename... (%_protocol-structs): ...and make more generic. * src/qemu_protocol-structs: New file. --- v2: new patch, first suggested here: https://www.redhat.com/archives/libvir-list/2011-July/msg00433.html src/Makefile.am | 20 +++++++++++--------- src/qemu_protocol-structs | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 src/qemu_protocol-structs diff --git a/src/Makefile.am b/src/Makefile.am index cd8a7e9..bd965de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -211,16 +211,18 @@ EXTRA_DIST += $(REMOTE_DRIVER_PROTOCOL) \ r1 = (?:/\* \d+ \*/\n)? r2 = /\* <[[:xdigit:]]+> \S+:\d+ \*/ -.PHONY: remote_protocol-structs +PROTOCOL_STRUCTS = \ + $(srcdir)/remote_protocol-structs \ + $(srcdir)/qemu_protocol-structs if WITH_REMOTE # The .o file that pdwtags parses is created as a side effect of running # libtool; but from make's perspective we depend on the .lo file. -remote_protocol-structs: libvirt_driver_remote_la-remote_protocol.lo +%_protocol-structs: libvirt_driver_remote_la-%_protocol.lo $(AM_V_GEN)if (pdwtags --help) > /dev/null 2>&1; then \ - pdwtags --verbose libvirt_driver_remote_la-remote_protocol.$(OBJEXT) \ + pdwtags --verbose $(<:.lo=.$(OBJEXT)) \ | perl -0777 -n \ -e 'foreach my $$p (split m!\n\n$(r1)$(r2)\n!) {' \ - -e ' if ($$p =~ /^struct remote_/) {' \ + -e ' if ($$p =~ /^struct (remote|qemu)_/) {' \ -e ' $$p =~ s!\t*/\*.*?\*/!!sg;' \ -e ' $$p =~ s!\s+\n!\n!sg;' \ -e ' $$p =~ s!\s+$$!!;' \ @@ -233,7 +235,7 @@ remote_protocol-structs: libvirt_driver_remote_la-remote_protocol.lo -e ' print "/* -*- c -*- */\n";' \ -e '}' \ -e 'END {' \ - -e ' if ($$n < 300) {' \ + -e ' if ($$n < 3) {' \ -e ' warn "WARNING: your pdwtags program is too old\n";' \ -e ' warn "WARNING: skipping the $@ test\n";' \ -e ' warn "WARNING: install dwarves-1.3 or newer\n";' \ @@ -248,12 +250,12 @@ remote_protocol-structs: libvirt_driver_remote_la-remote_protocol.lo echo 'WARNING: install the dwarves package to get pdwtags' >&2; \ fi else !WITH_REMOTE -# This generated file must live in git, because it cannot be re-generated +# These generated files must live in git, because they cannot be re-generated # when configured --without-remote. -remote_protocol-structs: +$(srcdir)/%_protocol-structs: endif -EXTRA_DIST += remote_protocol-structs -check-local: remote_protocol-structs +EXTRA_DIST += $(PROTOCOL_STRUCTS) +check-local: $(PROTOCOL_STRUCTS) # Mock driver, covering domains, storage, networks, etc TEST_DRIVER_SOURCES = \ diff --git a/src/qemu_protocol-structs b/src/qemu_protocol-structs new file mode 100644 index 0000000..e93e8bf --- /dev/null +++ b/src/qemu_protocol-structs @@ -0,0 +1,14 @@ +/* -*- c -*- */ +struct remote_nonnull_domain { + remote_nonnull_string name; + remote_uuid uuid; + int id; +}; +struct qemu_monitor_command_args { + remote_nonnull_domain dom; + remote_nonnull_string cmd; + int flags; +}; +struct qemu_monitor_command_ret { + remote_nonnull_string result; +}; -- 1.7.4.4

On Fri, Jul 08, 2011 at 01:25:45PM -0600, Eric Blake wrote:
Since we are going to add some libvirt-qemu.so entry points in 0.9.4, we might as well start checking for RPC stability, just as for libvirt.so.
* src/Makefile.am (PROTOCOL_STRUCTS): New variable. (remote_protocol-structs): Rename... (%_protocol-structs): ...and make more generic. * src/qemu_protocol-structs: New file. ---
v2: new patch, first suggested here: https://www.redhat.com/archives/libvir-list/2011-July/msg00433.html
src/Makefile.am | 20 +++++++++++--------- src/qemu_protocol-structs | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 src/qemu_protocol-structs
diff --git a/src/Makefile.am b/src/Makefile.am index cd8a7e9..bd965de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -211,16 +211,18 @@ EXTRA_DIST += $(REMOTE_DRIVER_PROTOCOL) \ r1 = (?:/\* \d+ \*/\n)? r2 = /\* <[[:xdigit:]]+> \S+:\d+ \*/
-.PHONY: remote_protocol-structs +PROTOCOL_STRUCTS = \ + $(srcdir)/remote_protocol-structs \ + $(srcdir)/qemu_protocol-structs if WITH_REMOTE # The .o file that pdwtags parses is created as a side effect of running # libtool; but from make's perspective we depend on the .lo file. -remote_protocol-structs: libvirt_driver_remote_la-remote_protocol.lo +%_protocol-structs: libvirt_driver_remote_la-%_protocol.lo $(AM_V_GEN)if (pdwtags --help) > /dev/null 2>&1; then \ - pdwtags --verbose libvirt_driver_remote_la-remote_protocol.$(OBJEXT) \ + pdwtags --verbose $(<:.lo=.$(OBJEXT)) \ | perl -0777 -n \ -e 'foreach my $$p (split m!\n\n$(r1)$(r2)\n!) {' \ - -e ' if ($$p =~ /^struct remote_/) {' \ + -e ' if ($$p =~ /^struct (remote|qemu)_/) {' \ -e ' $$p =~ s!\t*/\*.*?\*/!!sg;' \ -e ' $$p =~ s!\s+\n!\n!sg;' \ -e ' $$p =~ s!\s+$$!!;' \ @@ -233,7 +235,7 @@ remote_protocol-structs: libvirt_driver_remote_la-remote_protocol.lo -e ' print "/* -*- c -*- */\n";' \ -e '}' \ -e 'END {' \ - -e ' if ($$n < 300) {' \ + -e ' if ($$n < 3) {' \ -e ' warn "WARNING: your pdwtags program is too old\n";' \ -e ' warn "WARNING: skipping the $@ test\n";' \ -e ' warn "WARNING: install dwarves-1.3 or newer\n";' \ @@ -248,12 +250,12 @@ remote_protocol-structs: libvirt_driver_remote_la-remote_protocol.lo echo 'WARNING: install the dwarves package to get pdwtags' >&2; \ fi else !WITH_REMOTE -# This generated file must live in git, because it cannot be re-generated +# These generated files must live in git, because they cannot be re-generated # when configured --without-remote. -remote_protocol-structs: +$(srcdir)/%_protocol-structs: endif -EXTRA_DIST += remote_protocol-structs -check-local: remote_protocol-structs +EXTRA_DIST += $(PROTOCOL_STRUCTS) +check-local: $(PROTOCOL_STRUCTS)
# Mock driver, covering domains, storage, networks, etc TEST_DRIVER_SOURCES = \ diff --git a/src/qemu_protocol-structs b/src/qemu_protocol-structs new file mode 100644 index 0000000..e93e8bf --- /dev/null +++ b/src/qemu_protocol-structs @@ -0,0 +1,14 @@ +/* -*- c -*- */ +struct remote_nonnull_domain { + remote_nonnull_string name; + remote_uuid uuid; + int id; +}; +struct qemu_monitor_command_args { + remote_nonnull_domain dom; + remote_nonnull_string cmd; + int flags; +}; +struct qemu_monitor_command_ret { + remote_nonnull_string result; +};
ACK If we want real paranoia we can do src/rpc/virnetprotocol.x too, though that should basically never be changed by normal patches. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 07/11/2011 02:01 PM, Daniel P. Berrange wrote:
On Fri, Jul 08, 2011 at 01:25:45PM -0600, Eric Blake wrote:
Since we are going to add some libvirt-qemu.so entry points in 0.9.4, we might as well start checking for RPC stability, just as for libvirt.so.
* src/Makefile.am (PROTOCOL_STRUCTS): New variable. (remote_protocol-structs): Rename... (%_protocol-structs): ...and make more generic. * src/qemu_protocol-structs: New file.
ACK
Thanks; pushed.
If we want real paranoia we can do src/rpc/virnetprotocol.x too, though that should basically never be changed by normal patches.
I'll look into that; however, it can't quite reuse the same makefile rule because libvirt_net_rpc_la-virnetprotocol.lo doesn't fit the pattern libvirt_driver_remote_la-%_protocol.lo. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Like commit 1740c381, but for libvirt-qemu. * src/remote/qemu_protocol.x (qemu_monitor_command_args): Adjust type to match API. * src/qemu_protocol-structs: Update accordingly. --- v2: new patch src/qemu_protocol-structs | 2 +- src/remote/qemu_protocol.x | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu_protocol-structs b/src/qemu_protocol-structs index e93e8bf..b124dfa 100644 --- a/src/qemu_protocol-structs +++ b/src/qemu_protocol-structs @@ -7,7 +7,7 @@ struct remote_nonnull_domain { struct qemu_monitor_command_args { remote_nonnull_domain dom; remote_nonnull_string cmd; - int flags; + u_int flags; }; struct qemu_monitor_command_ret { remote_nonnull_string result; diff --git a/src/remote/qemu_protocol.x b/src/remote/qemu_protocol.x index fa453f4..7539e42 100644 --- a/src/remote/qemu_protocol.x +++ b/src/remote/qemu_protocol.x @@ -3,7 +3,7 @@ * remote_internal driver and libvirtd. This protocol is * internal and may change at any time. * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -30,7 +30,7 @@ struct qemu_monitor_command_args { remote_nonnull_domain dom; remote_nonnull_string cmd; - int flags; + unsigned int flags; }; struct qemu_monitor_command_ret { -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
Like commit 1740c381, but for libvirt-qemu.
* src/remote/qemu_protocol.x (qemu_monitor_command_args): Adjust type to match API. * src/qemu_protocol-structs: Update accordingly. ---
v2: new patch
src/qemu_protocol-structs | 2 +- src/remote/qemu_protocol.x | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Should we have a syntax-check rule to enforce unsigned int flags in the RPC protocol like you added a rule to do this in the public API. ACK. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 03:54 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
Like commit 1740c381, but for libvirt-qemu.
* src/remote/qemu_protocol.x (qemu_monitor_command_args): Adjust type to match API. * src/qemu_protocol-structs: Update accordingly. ---
v2: new patch
src/qemu_protocol-structs | 2 +- src/remote/qemu_protocol.x | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Should we have a syntax-check rule to enforce unsigned int flags in the RPC protocol like you added a rule to do this in the public API.
The syntax-check rule in 27/27 should cover this - it will complain if we introduce a 'int flags;' in any of the *protocol.x files, which should prod us to use 'unsigned int flags;' instead. Or are you referring to the fact that patch 27/27 only checked libvirt.h.in for additions of '...long flags', to ensure that no more than the existing 4 uses for migration are added? In that case, yeah, that rule can be enhanced to check include/libvirt/libvirt-qemu.h as well, to ensure that all new public APIs, whether for libvirt proper or for libvirt-qemu, use 'unsigned int flags'. But that's a tweak to 27, not to this one, so I pushed 4/27 as-is.
ACK.
-- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Silently ignored flags get in the way of new features that use those flags. Also, an upcoming syntax check will favor unsigned flags. * src/nodeinfo.h (nodeGetCPUStats, nodeGetMemoryStats): Drop unused attribute. * src/interface/netcf_driver.c (interfaceOpenInterface) (interfaceDefineXML, interfaceCreate, interfaceDestroy): Reject unknown flags. * src/network/bridge_driver.c (networkOpenNetwork) (networkGetXMLDesc): Likewise. * src/nwfilter/nwfilter_driver.c (nwfilterOpen): Likewise. * src/secret/secret_driver.c (secretOpen, secretDefineXML) (secretGetXMLDesc, secretSetValue): Likewise. * src/util/logging.c (virLogDefineFilter, virLogDefineOutput) (virLogMessage): Likewise; also use unsigned flags. * src/util/logging.h (virLogDefineFilter, virLogDefineOutput) (virLogMessage): Change signature. * src/util/command.c (virExecWithHook): Likewise. --- v2: rebase, fix driver open bug, and add in a few more instances (same goes for next 15 or so patches) src/interface/netcf_driver.c | 16 ++++++++++++---- src/network/bridge_driver.c | 9 +++++++-- src/nodeinfo.h | 6 +++--- src/nwfilter/nwfilter_driver.c | 4 +++- src/secret/secret_driver.c | 17 +++++++++++++---- src/util/command.c | 16 ++++++++-------- src/util/logging.c | 13 ++++++++++--- src/util/logging.h | 8 +++++--- 8 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/interface/netcf_driver.c b/src/interface/netcf_driver.c index 8900722..855b5a3 100644 --- a/src/interface/netcf_driver.c +++ b/src/interface/netcf_driver.c @@ -121,10 +121,12 @@ static struct netcf_if *interfaceDriverGetNetcfIF(struct netcf *ncf, virInterfac static virDrvOpenStatus interfaceOpenInterface(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct interface_driver *driverState; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (VIR_ALLOC(driverState) < 0) { virReportOOMError(); @@ -387,7 +389,7 @@ cleanup: static virInterfacePtr interfaceDefineXML(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct interface_driver *driver = conn->interfacePrivateData; struct netcf_if *iface = NULL; @@ -395,6 +397,8 @@ static virInterfacePtr interfaceDefineXML(virConnectPtr conn, virInterfaceDefPtr ifacedef = NULL; virInterfacePtr ret = NULL; + virCheckFlags(0, NULL); + interfaceDriverLock(driver); ifacedef = virInterfaceDefParseString(xml); @@ -461,12 +465,14 @@ cleanup: } static int interfaceCreate(virInterfacePtr ifinfo, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct interface_driver *driver = ifinfo->conn->interfacePrivateData; struct netcf_if *iface = NULL; int ret = -1; + virCheckFlags(0, -1); + interfaceDriverLock(driver); iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo); @@ -493,12 +499,14 @@ cleanup: } static int interfaceDestroy(virInterfacePtr ifinfo, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct interface_driver *driver = ifinfo->conn->interfacePrivateData; struct netcf_if *iface = NULL; int ret = -1; + virCheckFlags(0, -1); + interfaceDriverLock(driver); iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 554a8ac..0a12bc0 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2010,7 +2010,10 @@ cleanup: static virDrvOpenStatus networkOpenNetwork(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (!driverState) return VIR_DRV_OPEN_DECLINED; @@ -2416,12 +2419,14 @@ cleanup: } static char *networkGetXMLDesc(virNetworkPtr net, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct network_driver *driver = net->conn->networkPrivateData; virNetworkObjPtr network; char *ret = NULL; + virCheckFlags(0, NULL); + networkDriverLock(driver); network = virNetworkFindByUUID(&driver->networks, net->uuid); networkDriverUnlock(driver); diff --git a/src/nodeinfo.h b/src/nodeinfo.h index 9b2658f..e5ac1e0 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -1,7 +1,7 @@ /* * nodeinfo.c: Helper routines for OS specific node information * - * Copyright (C) 2006-2008 Red Hat, Inc. + * Copyright (C) 2006-2008, 2011 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -34,12 +34,12 @@ int nodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED, int cpuNum, virNodeCPUStatsPtr params, int *nparams, - unsigned int flags ATTRIBUTE_UNUSED); + unsigned int flags); int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, int cellNum, virNodeMemoryStatsPtr params, int *nparams, - unsigned int flags ATTRIBUTE_UNUSED); + unsigned int flags); int nodeGetCellsFreeMemory(virConnectPtr conn, unsigned long long *freeMems, int startCell, diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index bfe7f2f..a735059 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -272,8 +272,10 @@ cleanup: static virDrvOpenStatus nwfilterOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (!driverState) return VIR_DRV_OPEN_DECLINED; diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 552b7e4..c45ba51 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -525,7 +525,10 @@ cleanup: static virDrvOpenStatus secretOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (driverState == NULL) return VIR_DRV_OPEN_DECLINED; @@ -667,7 +670,7 @@ cleanup: static virSecretPtr secretDefineXML(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virSecretDriverStatePtr driver = conn->secretPrivateData; virSecretPtr ret = NULL; @@ -675,6 +678,8 @@ secretDefineXML(virConnectPtr conn, const char *xml, virSecretDefPtr backup = NULL; virSecretDefPtr new_attrs; + virCheckFlags(0, NULL); + new_attrs = virSecretDefParseString(xml); if (new_attrs == NULL) return NULL; @@ -778,12 +783,14 @@ cleanup: } static char * -secretGetXMLDesc(virSecretPtr obj, unsigned int flags ATTRIBUTE_UNUSED) +secretGetXMLDesc(virSecretPtr obj, unsigned int flags) { virSecretDriverStatePtr driver = obj->conn->secretPrivateData; char *ret = NULL; virSecretEntryPtr secret; + virCheckFlags(0, NULL); + secretDriverLock(driver); secret = secretFindByUUID(driver, obj->uuid); @@ -805,7 +812,7 @@ cleanup: static int secretSetValue(virSecretPtr obj, const unsigned char *value, - size_t value_size, unsigned int flags ATTRIBUTE_UNUSED) + size_t value_size, unsigned int flags) { virSecretDriverStatePtr driver = obj->conn->secretPrivateData; int ret = -1; @@ -813,6 +820,8 @@ secretSetValue(virSecretPtr obj, const unsigned char *value, size_t old_value_size; virSecretEntryPtr secret; + virCheckFlags(0, -1); + if (VIR_ALLOC_N(new_value, value_size) < 0) { virReportOOMError(); return -1; diff --git a/src/util/command.c b/src/util/command.c index eae58b2..6c19cd1 100644 --- a/src/util/command.c +++ b/src/util/command.c @@ -285,14 +285,14 @@ getDevNull(int *null) */ static int virExecWithHook(const char *const*argv, - const char *const*envp, - const fd_set *keepfd, - pid_t *retpid, - int infd, int *outfd, int *errfd, - int flags, - virExecHook hook, - void *data, - char *pidfile) + const char *const*envp, + const fd_set *keepfd, + pid_t *retpid, + int infd, int *outfd, int *errfd, + unsigned int flags, + virExecHook hook, + void *data, + char *pidfile) { pid_t pid; int null = -1, i, openmax; diff --git a/src/util/logging.c b/src/util/logging.c index c86fcda..d340f57 100644 --- a/src/util/logging.c +++ b/src/util/logging.c @@ -481,10 +481,13 @@ static int virLogResetFilters(void) { * Returns -1 in case of failure or the filter number if successful */ int virLogDefineFilter(const char *match, int priority, - int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ int i; char *mdup = NULL; + virCheckFlags(0, -1); + if ((match == NULL) || (priority < VIR_LOG_DEBUG) || (priority > VIR_LOG_ERROR)) return -1; @@ -579,10 +582,13 @@ static int virLogResetOutputs(void) { */ int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data, int priority, int dest, const char *name, - int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ int ret = -1; char *ndup = NULL; + virCheckFlags(0, -1); + if (f == NULL) return -1; @@ -683,7 +689,8 @@ virLogVersionString(char **msg, * the message may be stored, sent to output or just discarded */ void virLogMessage(const char *category, int priority, const char *funcname, - long long linenr, int flags, const char *fmt, ...) { + long long linenr, unsigned int flags, const char *fmt, ...) +{ static bool logVersionStderr = true; char *str = NULL; char *msg = NULL; diff --git a/src/util/logging.h b/src/util/logging.h index 6683e6f..20c8948 100644 --- a/src/util/logging.h +++ b/src/util/logging.h @@ -105,10 +105,11 @@ extern char *virLogGetOutputs(void); extern int virLogGetDefaultPriority(void); extern int virLogSetDefaultPriority(int priority); extern void virLogSetFromEnv(void); -extern int virLogDefineFilter(const char *match, int priority, int flags); +extern int virLogDefineFilter(const char *match, int priority, + unsigned int flags); extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data, int priority, int dest, const char *name, - int flags); + unsigned int flags); /* * Internal logging API @@ -123,7 +124,8 @@ extern int virLogParseDefaultPriority(const char *priority); extern int virLogParseFilters(const char *filters); extern int virLogParseOutputs(const char *output); extern void virLogMessage(const char *category, int priority, - const char *funcname, long long linenr, int flags, + const char *funcname, long long linenr, + unsigned int flags, const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7); extern int virLogSetBufferSize(int size); extern void virLogEmergencyDumpAll(int signum); -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
Silently ignored flags get in the way of new features that use those flags. Also, an upcoming syntax check will favor unsigned flags.
* src/nodeinfo.h (nodeGetCPUStats, nodeGetMemoryStats): Drop unused attribute. * src/interface/netcf_driver.c (interfaceOpenInterface) (interfaceDefineXML, interfaceCreate, interfaceDestroy): Reject unknown flags. * src/network/bridge_driver.c (networkOpenNetwork) (networkGetXMLDesc): Likewise. * src/nwfilter/nwfilter_driver.c (nwfilterOpen): Likewise. * src/secret/secret_driver.c (secretOpen, secretDefineXML) (secretGetXMLDesc, secretSetValue): Likewise. * src/util/logging.c (virLogDefineFilter, virLogDefineOutput) (virLogMessage): Likewise; also use unsigned flags. * src/util/logging.h (virLogDefineFilter, virLogDefineOutput) (virLogMessage): Change signature. * src/util/command.c (virExecWithHook): Likewise. ---
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/node_device/node_device_driver.c (nodeNumOfDevices) (nodeListDevices, nodeDeviceGetXMLDesc, nodeDeviceCreateXML): Reject unknown flags. * src/node_device/node_device_hal.c (halNodeDrvOpen): Likewise. * src/node_device/node_device_udev.c (udevNodeDrvOpen): Likewise. --- src/node_device/node_device_driver.c | 18 +++++++++++++----- src/node_device/node_device_hal.c | 4 +++- src/node_device/node_device_udev.c | 4 +++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 842f903..681655e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1,7 +1,7 @@ /* * node_device.c: node device enumeration * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright (C) 2008 Virtual Iron Software, Inc. * Copyright (C) 2008 David F. Lively * @@ -125,12 +125,14 @@ void nodeDeviceUnlock(virDeviceMonitorStatePtr driver) int nodeNumOfDevices(virConnectPtr conn, const char *cap, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDeviceMonitorStatePtr driver = conn->devMonPrivateData; int ndevs = 0; unsigned int i; + virCheckFlags(0, -1); + nodeDeviceLock(driver); for (i = 0; i < driver->devs.count; i++) { virNodeDeviceObjLock(driver->devs.objs[i]); @@ -148,12 +150,14 @@ int nodeListDevices(virConnectPtr conn, const char *cap, char **const names, int maxnames, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDeviceMonitorStatePtr driver = conn->devMonPrivateData; int ndevs = 0; unsigned int i; + virCheckFlags(0, -1); + nodeDeviceLock(driver); for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) { virNodeDeviceObjLock(driver->devs.objs[i]); @@ -254,12 +258,14 @@ out: char * nodeDeviceGetXMLDesc(virNodeDevicePtr dev, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; virNodeDeviceObjPtr obj; char *ret = NULL; + virCheckFlags(0, NULL); + nodeDeviceLock(driver); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(driver); @@ -545,7 +551,7 @@ find_new_device(virConnectPtr conn, const char *wwnn, const char *wwpn) virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDeviceMonitorStatePtr driver = conn->devMonPrivateData; virNodeDeviceDefPtr def = NULL; @@ -553,6 +559,8 @@ nodeDeviceCreateXML(virConnectPtr conn, int parent_host = -1; virNodeDevicePtr dev = NULL; + virCheckFlags(0, NULL); + nodeDeviceLock(driver); def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE); diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index d1dedfe..421f5ad 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -862,8 +862,10 @@ static int halDeviceMonitorActive(void) static virDrvOpenStatus halNodeDrvOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (driverState == NULL) return VIR_DRV_OPEN_DECLINED; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index db26c6b..a6b5b2e 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1721,8 +1721,10 @@ static int udevDeviceMonitorActive(void) static virDrvOpenStatus udevNodeDrvOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (driverState == NULL) { return VIR_DRV_OPEN_DECLINED; } -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/node_device/node_device_driver.c (nodeNumOfDevices) (nodeListDevices, nodeDeviceGetXMLDesc, nodeDeviceCreateXML): Reject unknown flags. * src/node_device/node_device_hal.c (halNodeDrvOpen): Likewise. * src/node_device/node_device_udev.c (udevNodeDrvOpen): Likewise. --- src/node_device/node_device_driver.c | 18 +++++++++++++----- src/node_device/node_device_hal.c | 4 +++- src/node_device/node_device_udev.c | 4 +++- 3 files changed, 19 insertions(+), 7 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom) (virStorageBackendCreateQemuImg) (virStorageBackendCreateQcowCreate): Reject unknown flags. * src/storage/storage_backend_disk.c (virStorageBackendDiskBuildPool) (virStorageBackendDiskDeleteVol): Likewise. * src/storage/storage_backend_fs.c (virStorageBackendFileSystemNetFindPoolSources) (virStorageBackendFileSystemBuild) (virStorageBackendFileSystemDelete, createFileDir) (virStorageBackendFileSystemVolBuildFrom) (virStorageBackendFileSystemVolDelete): Likewise. * src/storage/storage_backend_iscsi.c (virStorageBackendISCSIFindPoolSources): Likewise. * src/storage/storage_backend_logical.c (virStorageBackendLogicalFindPoolSources) (virStorageBackendLogicalBuildPool) (virStorageBackendLogicalDeletePool) (virStorageBackendLogicalDeleteVol): Likewise. * src/storage/storage_driver.c (storageOpen, storagePoolCreate) (storagePoolDefine, storagePoolRefresh, storagePoolGetXMLDesc) (storageVolumeCreateXML, storageVolumeCreateXMLFrom) (storageVolumeGetXMLDesc): Likewise. --- src/storage/storage_backend.c | 12 ++++++-- src/storage/storage_backend_disk.c | 10 +++++-- src/storage/storage_backend_fs.c | 26 ++++++++++++++---- src/storage/storage_backend_iscsi.c | 4 ++- src/storage/storage_backend_logical.c | 18 +++++++++--- src/storage/storage_driver.c | 45 ++++++++++++++++++++++++++------ 6 files changed, 88 insertions(+), 27 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 671b88e..f632edd 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -233,7 +233,7 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int fd = -1; int ret = -1; @@ -242,6 +242,8 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED, gid_t gid; uid_t uid; + virCheckFlags(0, -1); + if ((fd = open(vol->target.path, O_RDWR)) < 0) { virReportSystemError(errno, _("cannot create path '%s'"), @@ -643,7 +645,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int ret = -1; char *create_tool; @@ -652,6 +654,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, bool do_encryption = (vol->target.encryption != NULL); unsigned long long int size_arg; + virCheckFlags(0, -1); + const char *type = virStorageFileFormatTypeToString(vol->target.format); const char *backingType = vol->backingStore.path ? virStorageFileFormatTypeToString(vol->backingStore.format) : NULL; @@ -847,12 +851,14 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int ret; char *size; virCommandPtr cmd; + virCheckFlags(0, -1); + if (inputvol) { virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot copy from volume with qcow-create")); diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 0b10d36..82b41ef 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -1,7 +1,7 @@ /* * storage_backend_disk.c: storage backend for disk handling * - * Copyright (C) 2007-2008, 2010 Red Hat, Inc. + * Copyright (C) 2007-2008, 2010-2011 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -334,7 +334,7 @@ virStorageBackendDiskRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { /* eg parted /dev/sda mklabel msdos */ const char *prog[] = { @@ -347,6 +347,8 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, NULL, }; + virCheckFlags(0, -1); + if (virRun(prog, NULL) < 0) return -1; @@ -643,7 +645,7 @@ static int virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { char *part_num = NULL; char *devpath = NULL; @@ -652,6 +654,8 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, bool isDevMapperDevice; int rc = -1; + virCheckFlags(0, -1); + if (virFileResolveLink(vol->target.path, &devpath) < 0) { virReportSystemError(errno, _("Couldn't read volume target path '%s'"), diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index d87401f..b30e01e 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -212,7 +212,7 @@ cleanup: static char * virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { /* * # showmount --no-headers -e HOSTNAME @@ -241,6 +241,8 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE char *retval = NULL; unsigned int i; + virCheckFlags(0, NULL); + source = virStoragePoolDefParseSourceString(srcSpec, VIR_STORAGE_POOL_NETFS); if (!source) @@ -538,12 +540,14 @@ virStorageBackendFileSystemStart(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int err, ret = -1; char *parent; char *p; + virCheckFlags(0, -1); + if ((parent = strdup(pool->def->target.path)) == NULL) { virReportOOMError(); goto error; @@ -755,8 +759,10 @@ virStorageBackendFileSystemStop(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendFileSystemDelete(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + /* XXX delete all vols first ? */ if (rmdir(pool->def->target.path) < 0) { @@ -806,9 +812,12 @@ static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ int err; + virCheckFlags(0, -1); + if (inputvol) { virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -896,7 +905,10 @@ virStorageBackendFileSystemVolBuildFrom(virConnectPtr conn, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(0, -1); + return _virStorageBackendFileSystemVolBuild(conn, pool, vol, inputvol); } @@ -907,8 +919,10 @@ static int virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + if (unlink(vol->target.path) < 0) { /* Silently ignore failures where the vol has already gone away */ if (errno != ENOENT) { diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index 72887e3..7b8dc97 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -550,7 +550,7 @@ virStorageBackendISCSIScanTargets(const char *portal, static char * virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virStoragePoolSourcePtr source = NULL; size_t ntargets = 0; @@ -564,6 +564,8 @@ virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, }; char *portal = NULL; + virCheckFlags(0, NULL); + if (!(source = virStoragePoolDefParseSourceString(srcSpec, list.type))) return NULL; diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 4de5442..5fe9a1f 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -1,7 +1,7 @@ /* * storage_backend_logical.c: storage backend for logical volume handling * - * Copyright (C) 2007-2009 Red Hat, Inc. + * Copyright (C) 2007-2009, 2011 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -294,7 +294,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_ static char * virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { /* * # pvs --noheadings -o pv_name,vg_name @@ -313,6 +313,8 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolSourceList sourceList; int i; + virCheckFlags(0, NULL); + /* * NOTE: ignoring errors here; this is just to "touch" any logical volumes * that might be hanging around, so if this fails for some reason, the @@ -382,13 +384,15 @@ virStorageBackendLogicalStartPool(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { const char **vgargv; const char *pvargv[3]; int n = 0, i, fd; char zeros[PV_BLANK_SECTOR_SIZE]; + virCheckFlags(0, -1); + memset(zeros, 0, sizeof(zeros)); if (VIR_ALLOC_N(vgargv, 3 + pool->def->source.ndevice) < 0) { @@ -518,7 +522,7 @@ virStorageBackendLogicalStopPool(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendLogicalDeletePool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { const char *cmdargv[] = { VGREMOVE, "-f", pool->def->source.name, NULL @@ -526,6 +530,8 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn ATTRIBUTE_UNUSED, const char *pvargv[3]; int i, error; + virCheckFlags(0, -1); + /* first remove the volume group */ if (virRun(cmdargv, NULL) < 0) return -1; @@ -665,12 +671,14 @@ static int virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { const char *cmdargv[] = { LVREMOVE, "-f", vol->target.path, NULL }; + virCheckFlags(0, -1); + if (virRun(cmdargv, NULL) < 0) return -1; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index d1fef92..4f35be0 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -322,7 +322,10 @@ storagePoolLookupByVolume(virStorageVolPtr vol) { static virDrvOpenStatus storageOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (!driverState) return VIR_DRV_OPEN_DECLINED; @@ -516,13 +519,16 @@ cleanup: static virStoragePoolPtr storagePoolCreate(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = conn->storagePrivateData; virStoragePoolDefPtr def; virStoragePoolObjPtr pool = NULL; virStoragePoolPtr ret = NULL; virStorageBackendPtr backend; + virCheckFlags(0, NULL); + storageDriverLock(driver); if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; @@ -567,12 +573,15 @@ cleanup: static virStoragePoolPtr storagePoolDefine(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = conn->storagePrivateData; virStoragePoolDefPtr def; virStoragePoolObjPtr pool = NULL; virStoragePoolPtr ret = NULL; + virCheckFlags(0, NULL); + storageDriverLock(driver); if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; @@ -657,12 +666,15 @@ cleanup: static int storagePoolStart(virStoragePoolPtr obj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; virStorageBackendPtr backend; int ret = -1; + virCheckFlags(0, -1); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); storageDriverUnlock(driver); @@ -848,12 +860,15 @@ cleanup: static int storagePoolRefresh(virStoragePoolPtr obj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; virStorageBackendPtr backend; int ret = -1; + virCheckFlags(0, -1); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); @@ -940,11 +955,14 @@ cleanup: static char * storagePoolGetXMLDesc(virStoragePoolPtr obj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; char *ret = NULL; + virCheckFlags(0, NULL); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); storageDriverUnlock(driver); @@ -1261,13 +1279,16 @@ static int storageVolumeDelete(virStorageVolPtr obj, unsigned int flags); static virStorageVolPtr storageVolumeCreateXML(virStoragePoolPtr obj, const char *xmldesc, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; virStorageBackendPtr backend; virStorageVolDefPtr voldef = NULL; virStorageVolPtr ret = NULL, volobj = NULL; + virCheckFlags(0, NULL); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); storageDriverUnlock(driver); @@ -1383,7 +1404,8 @@ static virStorageVolPtr storageVolumeCreateXMLFrom(virStoragePoolPtr obj, const char *xmldesc, virStorageVolPtr vobj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool, origpool = NULL; virStorageBackendPtr backend; @@ -1391,6 +1413,8 @@ storageVolumeCreateXMLFrom(virStoragePoolPtr obj, virStorageVolPtr ret = NULL, volobj = NULL; int buildret; + virCheckFlags(0, NULL); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); if (pool && STRNEQ(obj->name, vobj->pool)) { @@ -2010,13 +2034,16 @@ cleanup: static char * storageVolumeGetXMLDesc(virStorageVolPtr obj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; virStorageBackendPtr backend; virStorageVolDefPtr vol; char *ret = NULL; + virCheckFlags(0, NULL); + storageDriverLock(driver); pool = virStoragePoolObjFindByName(&driver->pools, obj->pool); storageDriverUnlock(driver); -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom) (virStorageBackendCreateQemuImg) (virStorageBackendCreateQcowCreate): Reject unknown flags. * src/storage/storage_backend_disk.c (virStorageBackendDiskBuildPool) (virStorageBackendDiskDeleteVol): Likewise. * src/storage/storage_backend_fs.c (virStorageBackendFileSystemNetFindPoolSources) (virStorageBackendFileSystemBuild) (virStorageBackendFileSystemDelete, createFileDir) (virStorageBackendFileSystemVolBuildFrom) (virStorageBackendFileSystemVolDelete): Likewise. * src/storage/storage_backend_iscsi.c (virStorageBackendISCSIFindPoolSources): Likewise. * src/storage/storage_backend_logical.c (virStorageBackendLogicalFindPoolSources) (virStorageBackendLogicalBuildPool) (virStorageBackendLogicalDeletePool) (virStorageBackendLogicalDeleteVol): Likewise. * src/storage/storage_driver.c (storageOpen, storagePoolCreate) (storagePoolDefine, storagePoolRefresh, storagePoolGetXMLDesc) (storageVolumeCreateXML, storageVolumeCreateXMLFrom) (storageVolumeGetXMLDesc): Likewise. --- src/storage/storage_backend.c | 12 ++++++-- src/storage/storage_backend_disk.c | 10 +++++-- src/storage/storage_backend_fs.c | 26 ++++++++++++++---- src/storage/storage_backend_iscsi.c | 4 ++- src/storage/storage_backend_logical.c | 18 +++++++++--- src/storage/storage_driver.c | 45 ++++++++++++++++++++++++++------ 6 files changed, 88 insertions(+), 27 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 05:34 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom) (virStorageBackendCreateQemuImg) (virStorageBackendCreateQcowCreate): Reject unknown flags.
ACK.
I've pushed 5, 6, and 7. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Silently ignored flags get in the way of new features that use those flags. * src/esx/esx_device_monitor.c (esxDeviceOpen): Reject unknown flags. * src/esx/esx_driver.c (esxOpen, esxDomainReboot) (esxDomainXMLFromNative, esxDomainXMLToNative) (esxDomainMigratePrepare, esxDomainMigratePerform) (esxDomainMigrateFinish): Likewise. * src/esx/esx_interface_driver.c (esxInterfaceOpen): Likewise. * src/esx/esx_network_driver.c (esxNetworkOpen): Likewise. * src/esx/esx_nwfilter_driver.c (esxNWFilterOpen): Likewise. * src/esx/esx_secret_driver.c (esxSecretOpen): Likewise. * src/esx/esx_storage_driver.c (esxStorageOpen): Likewise. --- src/esx/esx_device_monitor.c | 4 +++- src/esx/esx_driver.c | 28 +++++++++++++++++++++------- src/esx/esx_interface_driver.c | 4 +++- src/esx/esx_network_driver.c | 4 +++- src/esx/esx_nwfilter_driver.c | 4 +++- src/esx/esx_secret_driver.c | 4 +++- src/esx/esx_storage_driver.c | 4 +++- 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/esx/esx_device_monitor.c b/src/esx/esx_device_monitor.c index 51b2413..2eba2b0 100644 --- a/src/esx/esx_device_monitor.c +++ b/src/esx/esx_device_monitor.c @@ -42,8 +42,10 @@ static virDrvOpenStatus esxDeviceOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->driver->no != VIR_DRV_ESX) { return VIR_DRV_OPEN_DECLINED; } diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index f68ede0..86dc250 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -935,13 +935,15 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth, */ static virDrvOpenStatus esxOpen(virConnectPtr conn, virConnectAuthPtr auth, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDrvOpenStatus result = VIR_DRV_OPEN_ERROR; esxPrivate *priv = NULL; char *potentialVCenterIpAddress = NULL; char vCenterIpAddress[NI_MAXHOST] = ""; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + /* Decline if the URI is NULL or the scheme is not one of {vpx|esx|gsx} */ if (conn->uri == NULL || conn->uri->scheme == NULL || (STRCASENEQ(conn->uri->scheme, "vpx") && @@ -1890,7 +1892,7 @@ esxDomainShutdown(virDomainPtr domain) static int -esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) +esxDomainReboot(virDomainPtr domain, unsigned int flags) { int result = -1; esxPrivate *priv = domain->conn->privateData; @@ -1898,6 +1900,8 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) esxVI_String *propertyNameList = NULL; esxVI_VirtualMachinePowerState powerState; + virCheckFlags(0, -1); + if (esxVI_EnsureSession(priv->primary) < 0) { return -1; } @@ -2796,7 +2800,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) static char * esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, const char *nativeConfig, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { esxPrivate *priv = conn->privateData; virVMXContext ctx; @@ -2804,6 +2808,8 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, virDomainDefPtr def = NULL; char *xml = NULL; + virCheckFlags(0, NULL); + if (STRNEQ(nativeFormat, "vmware-vmx")) { ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unsupported config format '%s'"), nativeFormat); @@ -2834,7 +2840,7 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, static char * esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, const char *domainXml, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { esxPrivate *priv = conn->privateData; int virtualHW_version; @@ -2843,6 +2849,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, virDomainDefPtr def = NULL; char *vmx = NULL; + virCheckFlags(0, NULL); + if (STRNEQ(nativeFormat, "vmware-vmx")) { ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unsupported config format '%s'"), nativeFormat); @@ -3829,12 +3837,14 @@ esxDomainMigratePrepare(virConnectPtr dconn, int *cookielen ATTRIBUTE_UNUSED, const char *uri_in ATTRIBUTE_UNUSED, char **uri_out, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname ATTRIBUTE_UNUSED, unsigned long resource ATTRIBUTE_UNUSED) { esxPrivate *priv = dconn->privateData; + virCheckFlags(0, -1); + if (uri_in == NULL) { if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s", priv->vCenter->ipAddress, @@ -3855,7 +3865,7 @@ esxDomainMigratePerform(virDomainPtr domain, const char *cookie ATTRIBUTE_UNUSED, int cookielen ATTRIBUTE_UNUSED, const char *uri, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname, unsigned long bandwidth ATTRIBUTE_UNUSED) { @@ -3873,6 +3883,8 @@ esxDomainMigratePerform(virDomainPtr domain, esxVI_TaskInfoState taskInfoState; char *taskInfoErrorMessage = NULL; + virCheckFlags(0, -1); + if (priv->vCenter == NULL) { ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Migration not possible without a vCenter")); @@ -4001,8 +4013,10 @@ esxDomainMigrateFinish(virConnectPtr dconn, const char *dname, const char *cookie ATTRIBUTE_UNUSED, int cookielen ATTRIBUTE_UNUSED, const char *uri ATTRIBUTE_UNUSED, - unsigned long flags ATTRIBUTE_UNUSED) + unsigned long flags) { + virCheckFlags(0, NULL); + return esxDomainLookupByName(dconn, dname); } diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index 3d23d0f..5713137 100644 --- a/src/esx/esx_interface_driver.c +++ b/src/esx/esx_interface_driver.c @@ -42,8 +42,10 @@ static virDrvOpenStatus esxInterfaceOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->driver->no != VIR_DRV_ESX) { return VIR_DRV_OPEN_DECLINED; } diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index f8a3ede..224c764 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -42,8 +42,10 @@ static virDrvOpenStatus esxNetworkOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->driver->no != VIR_DRV_ESX) { return VIR_DRV_OPEN_DECLINED; } diff --git a/src/esx/esx_nwfilter_driver.c b/src/esx/esx_nwfilter_driver.c index d7fa15a..6056d6d 100644 --- a/src/esx/esx_nwfilter_driver.c +++ b/src/esx/esx_nwfilter_driver.c @@ -42,8 +42,10 @@ static virDrvOpenStatus esxNWFilterOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->driver->no != VIR_DRV_ESX) { return VIR_DRV_OPEN_DECLINED; } diff --git a/src/esx/esx_secret_driver.c b/src/esx/esx_secret_driver.c index 820f4b1..c37b62d 100644 --- a/src/esx/esx_secret_driver.c +++ b/src/esx/esx_secret_driver.c @@ -40,8 +40,10 @@ static virDrvOpenStatus esxSecretOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->driver->no != VIR_DRV_ESX) { return VIR_DRV_OPEN_DECLINED; } diff --git a/src/esx/esx_storage_driver.c b/src/esx/esx_storage_driver.c index 528159a..a56536d 100644 --- a/src/esx/esx_storage_driver.c +++ b/src/esx/esx_storage_driver.c @@ -104,8 +104,10 @@ esxStoragePoolLookupType(esxVI_Context *ctx, const char *poolName, static virDrvOpenStatus esxStorageOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->driver->no != VIR_DRV_ESX) { return VIR_DRV_OPEN_DECLINED; } -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
Silently ignored flags get in the way of new features that use those flags.
* src/esx/esx_device_monitor.c (esxDeviceOpen): Reject unknown flags. * src/esx/esx_driver.c (esxOpen, esxDomainReboot) (esxDomainXMLFromNative, esxDomainXMLToNative) (esxDomainMigratePrepare, esxDomainMigratePerform) (esxDomainMigrateFinish): Likewise. * src/esx/esx_interface_driver.c (esxInterfaceOpen): Likewise. * src/esx/esx_network_driver.c (esxNetworkOpen): Likewise. * src/esx/esx_nwfilter_driver.c (esxNWFilterOpen): Likewise. * src/esx/esx_secret_driver.c (esxSecretOpen): Likewise. * src/esx/esx_storage_driver.c (esxStorageOpen): Likewise. --- src/esx/esx_device_monitor.c | 4 +++- src/esx/esx_driver.c | 28 +++++++++++++++++++++------- src/esx/esx_interface_driver.c | 4 +++- src/esx/esx_network_driver.c | 4 +++- src/esx/esx_nwfilter_driver.c | 4 +++- src/esx/esx_secret_driver.c | 4 +++- src/esx/esx_storage_driver.c | 4 +++- 7 files changed, 39 insertions(+), 13 deletions(-)
@@ -3829,12 +3837,14 @@ esxDomainMigratePrepare(virConnectPtr dconn, int *cookielen ATTRIBUTE_UNUSED, const char *uri_in ATTRIBUTE_UNUSED, char **uri_out, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname ATTRIBUTE_UNUSED, unsigned long resource ATTRIBUTE_UNUSED) { esxPrivate *priv = dconn->privateData;
+ virCheckFlags(0, -1); + if (uri_in == NULL) { if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s", priv->vCenter->ipAddress, @@ -3855,7 +3865,7 @@ esxDomainMigratePerform(virDomainPtr domain, const char *cookie ATTRIBUTE_UNUSED, int cookielen ATTRIBUTE_UNUSED, const char *uri, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname, unsigned long bandwidth ATTRIBUTE_UNUSED) { @@ -3873,6 +3883,8 @@ esxDomainMigratePerform(virDomainPtr domain, esxVI_TaskInfoState taskInfoState; char *taskInfoErrorMessage = NULL;
+ virCheckFlags(0, -1); + if (priv->vCenter == NULL) { ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Migration not possible without a vCenter")); @@ -4001,8 +4013,10 @@ esxDomainMigrateFinish(virConnectPtr dconn, const char *dname, const char *cookie ATTRIBUTE_UNUSED, int cookielen ATTRIBUTE_UNUSED, const char *uri ATTRIBUTE_UNUSED, - unsigned long flags ATTRIBUTE_UNUSED) + unsigned long flags) { + virCheckFlags(0, NULL); + return esxDomainLookupByName(dconn, dname); }
Actually this is wrong. This was implemented before libvirt knew about VIR_MIGRATE_PERSIST_DEST VIR_MIGRATE_UNDEFINE_SOURCE But an ESX migration has exactly the semantic implied by those two flags. So actually those two flags have to be passed always. I should have fixed that ages ago. Also if the domain is running ESX does a live migration always, so VIR_MIGRATE_LIVE has to passed too. ESX supports migration of inactive domains. It seems that migration in libvirt is only meant for active domains, but this isn't documented well. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 06:15 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
Silently ignored flags get in the way of new features that use those flags.
@@ -3829,12 +3837,14 @@ esxDomainMigratePrepare(virConnectPtr dconn, int *cookielen ATTRIBUTE_UNUSED, const char *uri_in ATTRIBUTE_UNUSED, char **uri_out, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname ATTRIBUTE_UNUSED, unsigned long resource ATTRIBUTE_UNUSED) { esxPrivate *priv = dconn->privateData;
+ virCheckFlags(0, -1); +
Actually this is wrong. This was implemented before libvirt knew about
VIR_MIGRATE_PERSIST_DEST VIR_MIGRATE_UNDEFINE_SOURCE
But an ESX migration has exactly the semantic implied by those two flags. So actually those two flags have to be passed always. I should have fixed that ages ago.
So, do we fix that now, or do we push this patch as-is (with the semantic change of rejecting the flags that are currently useful) along with your cleanup as a followup (with requiring the two flags)? I'm leaning a bit towards the latter (fix the flags to require the bits that must be present), so I'll post a v2.
Also if the domain is running ESX does a live migration always, so VIR_MIGRATE_LIVE has to passed too. ESX supports migration of inactive domains. It seems that migration in libvirt is only meant for active domains, but this isn't documented well.
Right now, qemu domains only get migrated if the domain is active, but I could totally see enhancing that to support migration of persistent but inactive domains (and it's a lot simpler - dumpxml on the source, and define on the destination, without having to do any handshaking between qemu processes). In fact, I'd love that as a feature addition! -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

* src/libxl/libxl_driver.c (libxlOpen, libxlDomainReboot) (libxlDomainXMLFromNative, libxlDomainXMLToNative) (libxlDomainCreateWithFlags): Reject unknown flags. --- src/libxl/libxl_driver.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 586d562..57497cb 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1059,8 +1059,10 @@ libxlActive(void) static virDrvOpenStatus libxlOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->uri == NULL) { if (libxl_driver == NULL) return VIR_DRV_OPEN_DECLINED; @@ -1477,13 +1479,15 @@ cleanup: } static int -libxlDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) +libxlDomainReboot(virDomainPtr dom, unsigned int flags) { libxlDriverPrivatePtr driver = dom->conn->privateData; virDomainObjPtr vm; int ret = -1; libxlDomainObjPrivatePtr priv; + virCheckFlags(0, -1); + libxlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { @@ -2506,7 +2510,7 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) static char * libxlDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat, const char * nativeConfig, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { libxlDriverPrivatePtr driver = conn->privateData; const libxl_version_info *ver_info; @@ -2514,6 +2518,8 @@ libxlDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat, virConfPtr conf = NULL; char *xml = NULL; + virCheckFlags(0, NULL); + if (STRNEQ(nativeFormat, LIBXL_CONFIG_FORMAT_XM)) { libxlError(VIR_ERR_INVALID_ARG, _("unsupported config type %s"), nativeFormat); @@ -2546,7 +2552,7 @@ cleanup: static char * libxlDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, const char * domainXml, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { libxlDriverPrivatePtr driver = conn->privateData; const libxl_version_info *ver_info; @@ -2555,6 +2561,8 @@ libxlDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, int len = MAX_CONFIG_SIZE; char *ret = NULL; + virCheckFlags(0, NULL); + if (STRNEQ(nativeFormat, LIBXL_CONFIG_FORMAT_XM)) { libxlError(VIR_ERR_INVALID_ARG, _("unsupported config type %s"), nativeFormat); @@ -2617,7 +2625,7 @@ libxlNumDefinedDomains(virConnectPtr conn) static int libxlDomainCreateWithFlags(virDomainPtr dom, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { libxlDriverPrivatePtr driver = dom->conn->privateData; virDomainObjPtr vm; -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/libxl/libxl_driver.c (libxlOpen, libxlDomainReboot) (libxlDomainXMLFromNative, libxlDomainXMLToNative) (libxlDomainCreateWithFlags): Reject unknown flags. --- src/libxl/libxl_driver.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/lxc/lxc_driver.c (lxcOpen, lxcDomainSetMemoryParameters) (lxcDomainGetMemoryParameters): Reject unknown flags. * src/lxc/lxc_container.c (lxcContainerStart): Use unsigned flags. --- src/lxc/lxc_container.c | 4 ++-- src/lxc/lxc_driver.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index ef8469c..ffa2f34 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2010 Red Hat, Inc. + * Copyright (C) 2008-2011 Red Hat, Inc. * Copyright (C) 2008 IBM Corp. * * lxc_container.c: file description @@ -889,7 +889,7 @@ int lxcContainerStart(virDomainDefPtr def, char *ttyPath) { pid_t pid; - int flags; + unsigned int flags; int stacksize = getpagesize() * 4; char *stack, *stacktop; lxc_child_argv_t args = { def, nveths, veths, control, ttyPath, diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 799a5e7..4624e21 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -110,8 +110,10 @@ static void lxcDomainEventQueue(lxc_driver_t *driver, static virDrvOpenStatus lxcOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + /* Verify uri was specified */ if (conn->uri == NULL) { if (lxc_driver == NULL) @@ -746,7 +748,7 @@ cleanup: static int lxcDomainSetMemoryParameters(virDomainPtr dom, virTypedParameterPtr params, int nparams, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { lxc_driver_t *driver = dom->conn->privateData; int i; @@ -754,6 +756,8 @@ static int lxcDomainSetMemoryParameters(virDomainPtr dom, virDomainObjPtr vm = NULL; int ret = -1; + virCheckFlags(0, -1); + lxcDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); @@ -843,7 +847,7 @@ cleanup: static int lxcDomainGetMemoryParameters(virDomainPtr dom, virTypedParameterPtr params, int *nparams, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { lxc_driver_t *driver = dom->conn->privateData; int i; @@ -853,6 +857,8 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom, int ret = -1; int rc; + virCheckFlags(0, -1); + lxcDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/lxc/lxc_driver.c (lxcOpen, lxcDomainSetMemoryParameters) (lxcDomainGetMemoryParameters): Reject unknown flags. * src/lxc/lxc_container.c (lxcContainerStart): Use unsigned flags. --- src/lxc/lxc_container.c | 4 ++-- src/lxc/lxc_driver.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index ef8469c..ffa2f34 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2010 Red Hat, Inc. + * Copyright (C) 2008-2011 Red Hat, Inc. * Copyright (C) 2008 IBM Corp. * * lxc_container.c: file description @@ -889,7 +889,7 @@ int lxcContainerStart(virDomainDefPtr def, char *ttyPath) { pid_t pid; - int flags; + unsigned int flags;
flags is passed to clone that takes int, so rename this to cflags (in line with oflags and fflags) and keep it as int. ACK, with the clone flags as int. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 06:21 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
* src/lxc/lxc_driver.c (lxcOpen, lxcDomainSetMemoryParameters) (lxcDomainGetMemoryParameters): Reject unknown flags. * src/lxc/lxc_container.c (lxcContainerStart): Use unsigned flags. @@ -889,7 +889,7 @@ int lxcContainerStart(virDomainDefPtr def, char *ttyPath) { pid_t pid; - int flags; + unsigned int flags;
flags is passed to clone that takes int, so rename this to cflags (in line with oflags and fflags) and keep it as int.
ACK, with the clone flags as int.
Good idea. I squashed this in, then pushed 9 and 10 (8 will be saved for my round 3 posting, since you had more comments on the esx migration flag handling). Slowly making my way through this series... diff --git i/src/lxc/lxc_container.c w/src/lxc/lxc_container.c index ffa2f34..8e1860b 100644 --- i/src/lxc/lxc_container.c +++ w/src/lxc/lxc_container.c @@ -889,7 +889,7 @@ int lxcContainerStart(virDomainDefPtr def, char *ttyPath) { pid_t pid; - unsigned int flags; + int cflags; int stacksize = getpagesize() * 4; char *stack, *stacktop; lxc_child_argv_t args = { def, nveths, veths, control, ttyPath, @@ -902,19 +902,19 @@ int lxcContainerStart(virDomainDefPtr def, } stacktop = stack + stacksize; - flags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|SIGCHLD; + cflags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|SIGCHLD; if (userns_supported()) { VIR_DEBUG("Enable user namespaces"); - flags |= CLONE_NEWUSER; + cflags |= CLONE_NEWUSER; } if (def->nets != NULL) { VIR_DEBUG("Enable network namespaces"); - flags |= CLONE_NEWNET; + cflags |= CLONE_NEWNET; } - pid = clone(lxcContainerChild, stacktop, flags, &args); + pid = clone(lxcContainerChild, stacktop, cflags, &args); VIR_FREE(stack); VIR_DEBUG("clone() completed, new container PID is %d", pid); -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

* src/openvz/openvz_driver.c (openvzDomainReboot, openvzOpen): Reject unknown flags. --- src/openvz/openvz_driver.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 2c6c870..0563a4c 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -613,12 +613,15 @@ cleanup: } static int openvzDomainReboot(virDomainPtr dom, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ struct openvz_driver *driver = dom->conn->privateData; virDomainObjPtr vm; const char *prog[] = {VZCTL, "--quiet", "restart", PROGRAM_SENTINAL, NULL}; int ret = -1; + virCheckFlags(0, -1); + openvzDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); openvzDriverUnlock(driver); @@ -1281,10 +1284,12 @@ openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) static virDrvOpenStatus openvzOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct openvz_driver *driver; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->uri == NULL) { if (!virFileExists("/proc/vz")) return VIR_DRV_OPEN_DECLINED; -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/openvz/openvz_driver.c (openvzDomainReboot, openvzOpen): Reject unknown flags. --- src/openvz/openvz_driver.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/phyp/phyp_driver.c (phypOpen, phypDomainReboot) (phypVIOSDriverOpen): Reject unknown flags. --- src/phyp/phyp_driver.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index d1ab5b4..dd5ab85 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1128,7 +1128,7 @@ exit: static virDrvOpenStatus phypOpen(virConnectPtr conn, - virConnectAuthPtr auth, unsigned int flags ATTRIBUTE_UNUSED) + virConnectAuthPtr auth, unsigned int flags) { LIBSSH2_SESSION *session = NULL; ConnectionData *connection_data = NULL; @@ -1138,6 +1138,8 @@ phypOpen(virConnectPtr conn, char *char_ptr; char *managed_system = NULL; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (!conn || !conn->uri) return VIR_DRV_OPEN_DECLINED; @@ -3389,7 +3391,7 @@ cleanup: } static int -phypDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) +phypDomainReboot(virDomainPtr dom, unsigned int flags) { int result = -1; ConnectionData *connection_data = dom->conn->networkPrivateData; @@ -3402,6 +3404,8 @@ phypDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) char *ret = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; + virCheckFlags(0, -1); + virBufferAddLit(&buf, "chsysstate"); if (system_type == HMC) virBufferAsprintf(&buf, " -m %s", managed_system); @@ -3725,8 +3729,10 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) static virDrvOpenStatus phypVIOSDriverOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->driver->no != VIR_DRV_PHYP) return VIR_DRV_OPEN_DECLINED; -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/phyp/phyp_driver.c (phypOpen, phypDomainReboot) (phypVIOSDriverOpen): Reject unknown flags. --- src/phyp/phyp_driver.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/qemu/qemu_driver.c (qemudOpen, qemuDomainScreenshot) (qemuDomainXMLFromNative, qemuDomainXMLToNative) (qemudDomainBlockPeek, qemuCPUCompare, qemuCPUBaseline): Reject unknown flags. * src/qemu/qemu_migration.c (qemuMigrationConfirm): Likewise. (_qemuMigrationCookie, qemuMigrationCookieXMLParse) (qemuMigrationCookieXMLParseStr, qemuMigrationBakeCookie) (qemuMigrationEatCookie): Make flags unsigned. * src/qemu/qemu_domain.h: (qemuDomainDefFormatXML) (qemuDomainFormatXML): Prefer unsigned flags. * src/qemu/qemu_domain.c (qemuDomainDefFormatXML) (qemuDomainFormatXML): Likewise. (qemuDomainOpenLogHelper, qemuDomainCreateLog): Rename variable. --- src/qemu/qemu_domain.c | 21 +++++++++++---------- src/qemu/qemu_domain.h | 4 ++-- src/qemu/qemu_driver.c | 30 +++++++++++++++++++++++------- src/qemu/qemu_migration.c | 16 +++++++++------- 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 4b65d87..91be0df 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -703,7 +703,7 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver, char *qemuDomainDefFormatXML(struct qemud_driver *driver, virDomainDefPtr def, - int flags) + unsigned int flags) { char *ret = NULL; virCPUDefPtr cpu = NULL; @@ -735,7 +735,7 @@ cleanup: char *qemuDomainFormatXML(struct qemud_driver *driver, virDomainObjPtr vm, - int flags) + unsigned int flags) { virDomainDefPtr def; @@ -835,7 +835,7 @@ void qemuDomainObjCheckNetTaint(struct qemud_driver *driver, static int qemuDomainOpenLogHelper(struct qemud_driver *driver, virDomainObjPtr vm, - int flags, + int oflags, mode_t mode) { char *logfile; @@ -846,7 +846,7 @@ qemuDomainOpenLogHelper(struct qemud_driver *driver, return -1; } - if ((fd = open(logfile, flags, mode)) < 0) { + if ((fd = open(logfile, oflags, mode)) < 0) { virReportSystemError(errno, _("failed to create logfile %s"), logfile); goto cleanup; @@ -865,18 +865,19 @@ cleanup: int -qemuDomainCreateLog(struct qemud_driver *driver, virDomainObjPtr vm, bool append) +qemuDomainCreateLog(struct qemud_driver *driver, virDomainObjPtr vm, + bool append) { - int flags; + int oflags; - flags = O_CREAT | O_WRONLY; + oflags = O_CREAT | O_WRONLY; /* Only logrotate files in /var/log, so only append if running privileged */ if (driver->privileged || append) - flags |= O_APPEND; + oflags |= O_APPEND; else - flags |= O_TRUNC; + oflags |= O_TRUNC; - return qemuDomainOpenLogHelper(driver, vm, flags, S_IRUSR | S_IWUSR); + return qemuDomainOpenLogHelper(driver, vm, oflags, S_IRUSR | S_IWUSR); } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f282df2..794eef7 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -127,11 +127,11 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver, char *qemuDomainDefFormatXML(struct qemud_driver *driver, virDomainDefPtr vm, - int flags); + unsigned int flags); char *qemuDomainFormatXML(struct qemud_driver *driver, virDomainObjPtr vm, - int flags); + unsigned int flags); void qemuDomainObjTaint(struct qemud_driver *driver, virDomainObjPtr obj, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a05a1ee..dd5d918 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -800,8 +800,10 @@ static int qemuDomainSnapshotSetCurrentInactive(virDomainObjPtr vm, static virDrvOpenStatus qemudOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->uri == NULL) { if (qemu_driver == NULL) return VIR_DRV_OPEN_DECLINED; @@ -2685,7 +2687,7 @@ static char * qemuDomainScreenshot(virDomainPtr dom, virStreamPtr st, unsigned int screen, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct qemud_driver *driver = dom->conn->privateData; virDomainObjPtr vm; @@ -2694,6 +2696,8 @@ qemuDomainScreenshot(virDomainPtr dom, int tmp_fd = -1; char *ret = NULL; + virCheckFlags(0, NULL); + qemuDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); qemuDriverUnlock(driver); @@ -3880,11 +3884,14 @@ cleanup: static char *qemuDomainXMLFromNative(virConnectPtr conn, const char *format, const char *config, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ struct qemud_driver *driver = conn->privateData; virDomainDefPtr def = NULL; char *xml = NULL; + virCheckFlags(0, NULL); + if (STRNEQ(format, QEMU_CONFIG_FORMAT_ARGV)) { qemuReportError(VIR_ERR_INVALID_ARG, _("unsupported config type %s"), format); @@ -3907,7 +3914,8 @@ cleanup: static char *qemuDomainXMLToNative(virConnectPtr conn, const char *format, const char *xmlData, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ struct qemud_driver *driver = conn->privateData; virDomainDefPtr def = NULL; virDomainChrSourceDef monConfig; @@ -3916,6 +3924,8 @@ static char *qemuDomainXMLToNative(virConnectPtr conn, char *ret = NULL; int i; + virCheckFlags(0, NULL); + qemuDriverLock(driver); if (STRNEQ(format, QEMU_CONFIG_FORMAT_ARGV)) { @@ -6163,12 +6173,14 @@ qemudDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long offset, size_t size, void *buffer, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct qemud_driver *driver = dom->conn->privateData; virDomainObjPtr vm; int fd = -1, ret = -1, i; + virCheckFlags(0, -1); + qemuDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); qemuDriverUnlock(driver); @@ -7239,11 +7251,13 @@ out: static int qemuCPUCompare(virConnectPtr conn, const char *xmlDesc, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct qemud_driver *driver = conn->privateData; int ret = VIR_CPU_COMPARE_ERROR; + virCheckFlags(0, VIR_CPU_COMPARE_ERROR); + qemuDriverLock(driver); if (!driver->caps || !driver->caps->host.cpu) { @@ -7263,10 +7277,12 @@ static char * qemuCPUBaseline(virConnectPtr conn ATTRIBUTE_UNUSED, const char **xmlCPUs, unsigned int ncpus, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { char *cpu; + virCheckFlags(0, NULL); + cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0); return cpu; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 48fc0c0..fcfa828 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -76,8 +76,8 @@ struct _qemuMigrationCookieGraphics { typedef struct _qemuMigrationCookie qemuMigrationCookie; typedef qemuMigrationCookie *qemuMigrationCookiePtr; struct _qemuMigrationCookie { - int flags; - int flagsMandatory; + unsigned int flags; + unsigned int flagsMandatory; /* Host properties */ unsigned char localHostuuid[VIR_UUID_BUFLEN]; @@ -446,7 +446,7 @@ error: static int qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, xmlXPathContextPtr ctxt, - int flags) + unsigned int flags) { char uuidstr[VIR_UUID_STRING_BUFLEN]; char *tmp; @@ -580,7 +580,7 @@ error: static int qemuMigrationCookieXMLParseStr(qemuMigrationCookiePtr mig, const char *xml, - int flags) + unsigned int flags) { xmlDocPtr doc = NULL; xmlXPathContextPtr ctxt = NULL; @@ -614,7 +614,7 @@ qemuMigrationBakeCookie(qemuMigrationCookiePtr mig, virDomainObjPtr dom, char **cookieout, int *cookieoutlen, - int flags) + unsigned int flags) { if (!cookieout || !cookieoutlen) return 0; @@ -645,7 +645,7 @@ qemuMigrationEatCookie(struct qemud_driver *driver, virDomainObjPtr dom, const char *cookiein, int cookieinlen, - int flags) + unsigned int flags) { qemuMigrationCookiePtr mig = NULL; @@ -2605,7 +2605,7 @@ int qemuMigrationConfirm(struct qemud_driver *driver, virDomainObjPtr vm, const char *cookiein, int cookieinlen, - unsigned int flags ATTRIBUTE_UNUSED, + unsigned int flags, int retcode) { qemuMigrationCookiePtr mig; @@ -2616,6 +2616,8 @@ int qemuMigrationConfirm(struct qemud_driver *driver, driver, conn, vm, NULLSTR(cookiein), cookieinlen, flags, retcode); + virCheckFlags(0, -1); + if (!(mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen, 0))) return -1; -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/qemu/qemu_driver.c (qemudOpen, qemuDomainScreenshot) (qemuDomainXMLFromNative, qemuDomainXMLToNative) (qemudDomainBlockPeek, qemuCPUCompare, qemuCPUBaseline): Reject unknown flags. * src/qemu/qemu_migration.c (qemuMigrationConfirm): Likewise. (_qemuMigrationCookie, qemuMigrationCookieXMLParse) (qemuMigrationCookieXMLParseStr, qemuMigrationBakeCookie) (qemuMigrationEatCookie): Make flags unsigned. * src/qemu/qemu_domain.h: (qemuDomainDefFormatXML) (qemuDomainFormatXML): Prefer unsigned flags. * src/qemu/qemu_domain.c (qemuDomainDefFormatXML) (qemuDomainFormatXML): Likewise. (qemuDomainOpenLogHelper, qemuDomainCreateLog): Rename variable. --- src/qemu/qemu_domain.c | 21 +++++++++++---------- src/qemu/qemu_domain.h | 4 ++-- src/qemu/qemu_driver.c | 30 +++++++++++++++++++++++------- src/qemu/qemu_migration.c | 16 +++++++++------- 4 files changed, 45 insertions(+), 26 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/test/test_driver.c (testOpen, testDomainCoreDump) (testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface) (testInterfaceChangeBegin, testInterfaceChangeCommit) (testInterfaceChangeRollback, testInterfaceGetXMLDesc) (testInterfaceDefineXML, testInterfaceCreate) (testInterfaceDestroy, testStorageOpen, testStoragePoolStart) (testStorageFindPoolSources, testStoragePoolCreate) (testStoragePoolDefine, testStoragePoolBuild) (testStoragePoolDelete, testStoragePoolRefresh) (testStoragePoolGetXMLDesc, testStorageVolumeCreateXML) (testStorageVolumeCreateXMLFrom, testStorageVolumeDelete) (testStorageVolumeGetXMLDesc, testDevMonOpen) (testNodeNumOfDevices, testNodeListDevices) (testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML) (testSecretOpen, testNWFilterOpen): Reject unknown flags. --- src/test/test_driver.c | 144 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 112 insertions(+), 32 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 98daca8..5ff01a3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1099,11 +1099,13 @@ static int testOpenFromFile(virConnectPtr conn, static virDrvOpenStatus testOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int ret; testConnPtr privconn; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (!conn->uri) return VIR_DRV_OPEN_DECLINED; @@ -1904,7 +1906,7 @@ cleanup: static int testDomainCoreDump(virDomainPtr domain, const char *to, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = domain->conn->privateData; int fd = -1; @@ -1912,6 +1914,8 @@ static int testDomainCoreDump(virDomainPtr domain, virDomainEventPtr event = NULL; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); privdom = virDomainFindByName(&privconn->domains, domain->name); @@ -2843,7 +2847,10 @@ error: static virDrvOpenStatus testOpenNetwork(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (STRNEQ(conn->driver->name, "Test")) return VIR_DRV_OPEN_DECLINED; @@ -3178,12 +3185,14 @@ cleanup: } static char *testNetworkGetXMLDesc(virNetworkPtr network, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; char *ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); privnet = virNetworkFindByName(&privconn->networks, network->name); @@ -3292,8 +3301,10 @@ cleanup: static virDrvOpenStatus testOpenInterface(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (STRNEQ(conn->driver->name, "Test")) return VIR_DRV_OPEN_DECLINED; @@ -3476,11 +3487,13 @@ cleanup: } static int testInterfaceChangeBegin(virConnectPtr conn, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = conn->privateData; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); if (privconn->transaction_running) { testError(VIR_ERR_OPERATION_INVALID, @@ -3501,11 +3514,13 @@ cleanup: } static int testInterfaceChangeCommit(virConnectPtr conn, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = conn->privateData; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); if (!privconn->transaction_running) { @@ -3526,11 +3541,13 @@ cleanup: } static int testInterfaceChangeRollback(virConnectPtr conn, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = conn->privateData; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); if (!privconn->transaction_running) { @@ -3555,12 +3572,14 @@ cleanup: } static char *testInterfaceGetXMLDesc(virInterfacePtr iface, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = iface->conn->privateData; virInterfaceObjPtr privinterface; char *ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); privinterface = virInterfaceFindByName(&privconn->ifaces, iface->name); @@ -3581,13 +3600,15 @@ cleanup: static virInterfacePtr testInterfaceDefineXML(virConnectPtr conn, const char *xmlStr, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = conn->privateData; virInterfaceDefPtr def; virInterfaceObjPtr iface = NULL; virInterfacePtr ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); if ((def = virInterfaceDefParseString(xmlStr)) == NULL) goto cleanup; @@ -3631,12 +3652,14 @@ cleanup: } static int testInterfaceCreate(virInterfacePtr iface, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = iface->conn->privateData; virInterfaceObjPtr privinterface; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); privinterface = virInterfaceFindByName(&privconn->ifaces, iface->name); @@ -3662,12 +3685,14 @@ cleanup: } static int testInterfaceDestroy(virInterfacePtr iface, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = iface->conn->privateData; virInterfaceObjPtr privinterface; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); privinterface = virInterfaceFindByName(&privconn->ifaces, iface->name); @@ -3716,7 +3741,10 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) { static virDrvOpenStatus testStorageOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (STRNEQ(conn->driver->name, "Test")) return VIR_DRV_OPEN_DECLINED; @@ -3921,11 +3949,14 @@ cleanup: static int testStoragePoolStart(virStoragePoolPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, pool->name); @@ -3955,12 +3986,14 @@ static char * testStorageFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type, const char *srcSpec, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virStoragePoolSourcePtr source = NULL; int pool_type; char *ret = NULL; + virCheckFlags(0, NULL); + pool_type = virStoragePoolTypeFromString(type); if (!pool_type) { testError(VIR_ERR_INTERNAL_ERROR, @@ -4009,12 +4042,15 @@ cleanup: static virStoragePoolPtr testStoragePoolCreate(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = conn->privateData; virStoragePoolDefPtr def; virStoragePoolObjPtr pool = NULL; virStoragePoolPtr ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; @@ -4052,12 +4088,15 @@ cleanup: static virStoragePoolPtr testStoragePoolDefine(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = conn->privateData; virStoragePoolDefPtr def; virStoragePoolObjPtr pool = NULL; virStoragePoolPtr ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; @@ -4119,11 +4158,14 @@ cleanup: static int testStoragePoolBuild(virStoragePoolPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, pool->name); @@ -4187,11 +4229,14 @@ cleanup: static int testStoragePoolDelete(virStoragePoolPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, pool->name); @@ -4219,11 +4264,14 @@ cleanup: static int testStoragePoolRefresh(virStoragePoolPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, pool->name); @@ -4283,11 +4331,14 @@ cleanup: static char * testStoragePoolGetXMLDesc(virStoragePoolPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; char *ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, pool->name); @@ -4562,12 +4613,15 @@ testStorageVolumeLookupByPath(virConnectPtr conn, static virStorageVolPtr testStorageVolumeCreateXML(virStoragePoolPtr pool, const char *xmldesc, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol = NULL; virStorageVolPtr ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, pool->name); @@ -4643,12 +4697,15 @@ static virStorageVolPtr testStorageVolumeCreateXMLFrom(virStoragePoolPtr pool, const char *xmldesc, virStorageVolPtr clonevol, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = pool->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol = NULL, origvol = NULL; virStorageVolPtr ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, pool->name); @@ -4732,13 +4789,16 @@ cleanup: static int testStorageVolumeDelete(virStorageVolPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = vol->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol; int i; int ret = -1; + virCheckFlags(0, -1); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, vol->pool); @@ -4857,12 +4917,15 @@ cleanup: static char * testStorageVolumeGetXMLDesc(virStorageVolPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ testConnPtr privconn = vol->conn->privateData; virStoragePoolObjPtr privpool; virStorageVolDefPtr privvol; char *ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); privpool = virStoragePoolObjFindByName(&privconn->pools, vol->pool); @@ -4942,7 +5005,10 @@ cleanup: /* Node device implementations */ static virDrvOpenStatus testDevMonOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (STRNEQ(conn->driver->name, "Test")) return VIR_DRV_OPEN_DECLINED; @@ -4958,12 +5024,14 @@ static int testDevMonClose(virConnectPtr conn) { static int testNodeNumOfDevices(virConnectPtr conn, const char *cap, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr driver = conn->privateData; int ndevs = 0; unsigned int i; + virCheckFlags(0, -1); + testDriverLock(driver); for (i = 0; i < driver->devs.count; i++) if ((cap == NULL) || @@ -4979,12 +5047,14 @@ testNodeListDevices(virConnectPtr conn, const char *cap, char **const names, int maxnames, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr driver = conn->privateData; int ndevs = 0; unsigned int i; + virCheckFlags(0, -1); + testDriverLock(driver); for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) { virNodeDeviceObjLock(driver->devs.objs[i]); @@ -5035,12 +5105,14 @@ cleanup: static char * testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr driver = dev->conn->privateData; virNodeDeviceObjPtr obj; char *ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(driver); obj = virNodeDeviceFindByName(&driver->devs, dev->name); testDriverUnlock(driver); @@ -5166,7 +5238,7 @@ cleanup: static virNodeDevicePtr testNodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr driver = conn->privateData; virNodeDeviceDefPtr def = NULL; @@ -5176,6 +5248,8 @@ testNodeDeviceCreateXML(virConnectPtr conn, virNodeDevicePtr dev = NULL; virNodeDevCapsDefPtr caps; + virCheckFlags(0, NULL); + testDriverLock(driver); def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE); @@ -5396,7 +5470,10 @@ static void testDomainEventQueue(testConnPtr driver, static virDrvOpenStatus testSecretOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (STRNEQ(conn->driver->name, "Test")) return VIR_DRV_OPEN_DECLINED; @@ -5412,7 +5489,10 @@ static int testSecretClose(virConnectPtr conn) { static virDrvOpenStatus testNWFilterOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (STRNEQ(conn->driver->name, "Test")) return VIR_DRV_OPEN_DECLINED; -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/test/test_driver.c (testOpen, testDomainCoreDump) (testOpenNetwork, testNetworkGetXMLDesc, testOpenInterface) (testInterfaceChangeBegin, testInterfaceChangeCommit) (testInterfaceChangeRollback, testInterfaceGetXMLDesc) (testInterfaceDefineXML, testInterfaceCreate) (testInterfaceDestroy, testStorageOpen, testStoragePoolStart) (testStorageFindPoolSources, testStoragePoolCreate) (testStoragePoolDefine, testStoragePoolBuild) (testStoragePoolDelete, testStoragePoolRefresh) (testStoragePoolGetXMLDesc, testStorageVolumeCreateXML) (testStorageVolumeCreateXMLFrom, testStorageVolumeDelete) (testStorageVolumeGetXMLDesc, testDevMonOpen) (testNodeNumOfDevices, testNodeListDevices) (testNodeDeviceGetXMLDesc, testNodeDeviceCreateXML) (testSecretOpen, testNWFilterOpen): Reject unknown flags. --- src/test/test_driver.c | 144 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 112 insertions(+), 32 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 98daca8..5ff01a3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1099,11 +1099,13 @@ static int testOpenFromFile(virConnectPtr conn,
static virDrvOpenStatus testOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int ret; testConnPtr privconn;
+ virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (!conn->uri) return VIR_DRV_OPEN_DECLINED;
@@ -1904,7 +1906,7 @@ cleanup:
static int testDomainCoreDump(virDomainPtr domain, const char *to, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = domain->conn->privateData; int fd = -1; @@ -1912,6 +1914,8 @@ static int testDomainCoreDump(virDomainPtr domain, virDomainEventPtr event = NULL; int ret = -1;
+ virCheckFlags(0, -1);
testDomainCoreDump understands VIR_DUMP_CRASH. Don't get fooled by the ATTRIBUTE_UNUSED :) ACK, with testDomainCoreDump fixed. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 06:35 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
static int testDomainCoreDump(virDomainPtr domain, const char *to, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { testConnPtr privconn = domain->conn->privateData; int fd = -1; @@ -1912,6 +1914,8 @@ static int testDomainCoreDump(virDomainPtr domain, virDomainEventPtr event = NULL; int ret = -1;
+ virCheckFlags(0, -1);
testDomainCoreDump understands VIR_DUMP_CRASH. Don't get fooled by the ATTRIBUTE_UNUSED :)
Good catch.
ACK, with testDomainCoreDump fixed.
I've pushed 11-14, with this squashed in. diff --git i/src/test/test_driver.c w/src/test/test_driver.c index 5412bff..f3fb320 100644 --- i/src/test/test_driver.c +++ w/src/test/test_driver.c @@ -1919,7 +1919,7 @@ static int testDomainCoreDump(virDomainPtr domain, virDomainEventPtr event = NULL; int ret = -1; - virCheckFlags(0, -1); + virCheckFlags(VIR_DUMP_CRASH, -1); testDriverLock(privconn); privdom = virDomainFindByName(&privconn->domains, -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

* src/uml/uml_driver.c (umlOpen, umlDomainGetXMLDesc) (umlDomainBlockPeek): Reject unknown flags. --- src/uml/uml_driver.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 6a396e4..9f66aee 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -946,7 +946,10 @@ static void umlShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED, static virDrvOpenStatus umlOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->uri == NULL) { if (uml_driver == NULL) return VIR_DRV_OPEN_DECLINED; @@ -1559,11 +1562,14 @@ cleanup: static char *umlDomainGetXMLDesc(virDomainPtr dom, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ struct uml_driver *driver = dom->conn->privateData; virDomainObjPtr vm; char *ret = NULL; + virCheckFlags(0, NULL); + umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); umlDriverUnlock(driver); @@ -2045,12 +2051,14 @@ umlDomainBlockPeek(virDomainPtr dom, const char *path, unsigned long long offset, size_t size, void *buffer, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct uml_driver *driver = dom->conn->privateData; virDomainObjPtr vm; int fd = -1, ret = -1, i; + virCheckFlags(0, -1); + umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); umlDriverUnlock(driver); -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/uml/uml_driver.c (umlOpen, umlDomainGetXMLDesc) (umlDomainBlockPeek): Reject unknown flags. --- src/uml/uml_driver.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)
@@ -1559,11 +1562,14 @@ cleanup:
static char *umlDomainGetXMLDesc(virDomainPtr dom, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ struct uml_driver *driver = dom->conn->privateData; virDomainObjPtr vm; char *ret = NULL;
+ virCheckFlags(0, NULL); + umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); umlDriverUnlock(driver);
Don't get fooled by the ATTRIBUTE_UNUSED again. All *DomainGetXMLDesc use virDomainDefFormat and have to accept all flags that virDomainDefFormat accepts. I suggest to recheck your series for this pattern, here it's just the first time that I notice it. ACK, with that virCheckFlags loosened correctly. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 06:41 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
* src/uml/uml_driver.c (umlOpen, umlDomainGetXMLDesc) (umlDomainBlockPeek): Reject unknown flags. --- src/uml/uml_driver.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)
@@ -1559,11 +1562,14 @@ cleanup:
static char *umlDomainGetXMLDesc(virDomainPtr dom, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ struct uml_driver *driver = dom->conn->privateData; virDomainObjPtr vm; char *ret = NULL;
+ virCheckFlags(0, NULL); + umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); umlDriverUnlock(driver);
Don't get fooled by the ATTRIBUTE_UNUSED again. All *DomainGetXMLDesc use virDomainDefFormat and have to accept all flags that virDomainDefFormat accepts. I suggest to recheck your series for this pattern, here it's just the first time that I notice it.
Ouch. Good catch, and I'll have to fix that shortly. I'll post the patch before I commit it, but it should be considered a trivial regression fix, so I'll commit it without waiting for review.
ACK, with that virCheckFlags loosened correctly.
I squashed this in for this patch, and now I'm working on using the same fix for the regression committed in all the prior pushed patches. diff --git i/src/uml/uml_driver.c w/src/uml/uml_driver.c index 132aef1..da91687 100644 --- i/src/uml/uml_driver.c +++ w/src/uml/uml_driver.c @@ -1599,7 +1599,9 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom, virDomainObjPtr vm; char *ret = NULL; - virCheckFlags(0, NULL); + virCheckFlags(VIR_DOMAIN_XML_SECURE | + VIR_DOMAIN_XML_INACTIVE | + VIR_DOMAIN_XML_UPDATE_CPU, NULL); umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 07/13/2011 03:14 PM, Eric Blake wrote:
Don't get fooled by the ATTRIBUTE_UNUSED again. All *DomainGetXMLDesc use virDomainDefFormat and have to accept all flags that virDomainDefFormat accepts. I suggest to recheck your series for this pattern, here it's just the first time that I notice it.
Ouch. Good catch, and I'll have to fix that shortly. I'll post the patch before I commit it, but it should be considered a trivial regression fix, so I'll commit it without waiting for review.
Thanks for making me audit all the drivers one more time. It turns out that none of the other drivers committed thus far had this problem (rather, their problem was that virDomainGetXMLDesc didn't have any virCheckFlags in the first place) - for example, libxlDomainGetXMLDesc. So without a regression, I can't claim the trivial rule any more, and will just add the new patch to my v3 series. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2011/7/13 Eric Blake <eblake@redhat.com>:
On 07/13/2011 06:41 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
* src/uml/uml_driver.c (umlOpen, umlDomainGetXMLDesc) (umlDomainBlockPeek): Reject unknown flags. --- src/uml/uml_driver.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)
@@ -1559,11 +1562,14 @@ cleanup:
static char *umlDomainGetXMLDesc(virDomainPtr dom, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ struct uml_driver *driver = dom->conn->privateData; virDomainObjPtr vm; char *ret = NULL;
+ virCheckFlags(0, NULL); + umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); umlDriverUnlock(driver);
Don't get fooled by the ATTRIBUTE_UNUSED again. All *DomainGetXMLDesc use virDomainDefFormat and have to accept all flags that virDomainDefFormat accepts. I suggest to recheck your series for this pattern, here it's just the first time that I notice it.
Ouch. Good catch, and I'll have to fix that shortly. I'll post the patch before I commit it, but it should be considered a trivial regression fix, so I'll commit it without waiting for review.
ACK, with that virCheckFlags loosened correctly.
I squashed this in for this patch, and now I'm working on using the same fix for the regression committed in all the prior pushed patches.
diff --git i/src/uml/uml_driver.c w/src/uml/uml_driver.c index 132aef1..da91687 100644 --- i/src/uml/uml_driver.c +++ w/src/uml/uml_driver.c @@ -1599,7 +1599,9 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom, virDomainObjPtr vm; char *ret = NULL;
- virCheckFlags(0, NULL); + virCheckFlags(VIR_DOMAIN_XML_SECURE | + VIR_DOMAIN_XML_INACTIVE | + VIR_DOMAIN_XML_UPDATE_CPU, NULL);
umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
I'm not sure if it's a good idea to add the flags check for this set of flags at the driver level. Maybe it should be moved one level down into virDomainDefFormat. This avoids touching all drivers should we ever add a new VIR_DOMAIN_XML_* flag. -- Matthias Bolte http://photron.blogspot.com

On 07/14/2011 01:21 AM, Matthias Bolte wrote:
+++ w/src/uml/uml_driver.c @@ -1599,7 +1599,9 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom, virDomainObjPtr vm; char *ret = NULL;
- virCheckFlags(0, NULL); + virCheckFlags(VIR_DOMAIN_XML_SECURE | + VIR_DOMAIN_XML_INACTIVE | + VIR_DOMAIN_XML_UPDATE_CPU, NULL);
umlDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
I'm not sure if it's a good idea to add the flags check for this set of flags at the driver level. Maybe it should be moved one level down into virDomainDefFormat. This avoids touching all drivers should we ever add a new VIR_DOMAIN_XML_* flag.
Interesting thought. I guess that means a bit more work on my side (I'd already made the change to make all the drivers duplicate the check, but I like the idea of having all drivers defer the check down to the common helper). -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

* src/vbox/vbox_driver.c (vboxOpenDummy): Reject unknown flags. * src/vbox/vbox_tmpl.c (vboxOpen, vboxDomainReboot) (vboxNetworkOpen, vboxNetworkGetXMLDesc, vboxStorageOpen) (vboxStorageVolCreateXML, vboxStorageVolDelete) (vboxStorageVolGetXMLDesc, vboxDomainScreenshot): Likewise. --- src/vbox/vbox_driver.c | 5 ++++- src/vbox/vbox_tmpl.c | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index b20998a..430ab40 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -142,9 +142,12 @@ int vboxRegister(void) { static virDrvOpenStatus vboxOpenDummy(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ uid_t uid = getuid(); + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->uri == NULL || conn->uri->scheme == NULL || STRNEQ (conn->uri->scheme, "vbox") || diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 4a0858f..6bf0950 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -961,10 +961,13 @@ static void vboxUninitialize(vboxGlobalData *data) { static virDrvOpenStatus vboxOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ vboxGlobalData *data = NULL; uid_t uid = getuid(); + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->uri == NULL) { conn->uri = xmlParseURI(uid ? "vbox:///session" : "vbox:///system"); if (conn->uri == NULL) { @@ -1637,7 +1640,8 @@ cleanup: return ret; } -static int vboxDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) { +static int vboxDomainReboot(virDomainPtr dom, unsigned int flags) +{ VBOX_OBJECT_CHECK(dom->conn, int, -1); IMachine *machine = NULL; vboxIID iid = VBOX_IID_INITIALIZER; @@ -1646,6 +1650,8 @@ static int vboxDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSE PRBool isAccessible = PR_FALSE; nsresult rc; + virCheckFlags(0, -1); + vboxIIDFromUUID(&iid, dom->uuid); rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine); if (NS_FAILED(rc)) { @@ -6938,9 +6944,12 @@ static int vboxDomainEventDeregisterAny(virConnectPtr conn, */ static virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ vboxGlobalData *data = conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (STRNEQ(conn->driver->name, "VBOX")) goto cleanup; @@ -7575,7 +7584,8 @@ static int vboxNetworkDestroy(virNetworkPtr network) { } static char *vboxNetworkGetXMLDesc(virNetworkPtr network, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ VBOX_OBJECT_HOST_CHECK(network->conn, char *, NULL); virNetworkDefPtr def = NULL; virNetworkIpDefPtr ipdef = NULL; @@ -7583,6 +7593,8 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, PRUnichar *networkInterfaceNameUtf16 = NULL; IHostNetworkInterface *networkInterface = NULL; + virCheckFlags(0, NULL); + if (VIR_ALLOC(def) < 0) { virReportOOMError(); goto cleanup; @@ -7750,9 +7762,12 @@ cleanup: static virDrvOpenStatus vboxStorageOpen (virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ vboxGlobalData *data = conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (STRNEQ(conn->driver->name, "VBOX")) goto cleanup; @@ -8098,7 +8113,8 @@ static virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const cha static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ VBOX_OBJECT_CHECK(pool->conn, virStorageVolPtr, NULL); virStorageVolDefPtr def = NULL; PRUnichar *hddFormatUtf16 = NULL; @@ -8106,6 +8122,8 @@ static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool, virStoragePoolDef poolDef; nsresult rc; + virCheckFlags(0, NULL); + /* since there is currently one default pool now * and virStorageVolDefFormat() just checks it type * so just assign it for now, change the behaviour @@ -8191,7 +8209,8 @@ cleanup: } static int vboxStorageVolDelete(virStorageVolPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ VBOX_OBJECT_CHECK(vol->conn, int, -1); vboxIID hddIID = VBOX_IID_INITIALIZER; unsigned char uuid[VIR_UUID_BUFLEN]; @@ -8201,6 +8220,8 @@ static int vboxStorageVolDelete(virStorageVolPtr vol, int i = 0; int j = 0; + virCheckFlags(0, -1); + if (virUUIDParse(vol->key, uuid) < 0) { vboxError(VIR_ERR_INVALID_ARG, _("Could not parse UUID from '%s'"), vol->key); @@ -8424,7 +8445,8 @@ static int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info return ret; } -static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags ATTRIBUTE_UNUSED) { +static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) +{ VBOX_OBJECT_CHECK(vol->conn, char *, NULL); IHardDisk *hardDisk = NULL; unsigned char uuid[VIR_UUID_BUFLEN]; @@ -8434,6 +8456,8 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags A int defOk = 0; nsresult rc; + virCheckFlags(0, NULL); + memset(&pool, 0, sizeof(pool)); memset(&def, 0, sizeof(def)); @@ -8597,7 +8621,7 @@ static char * vboxDomainScreenshot(virDomainPtr dom, virStreamPtr st, unsigned int screen, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { VBOX_OBJECT_CHECK(dom->conn, char *, NULL); IConsole *console = NULL; @@ -8608,6 +8632,8 @@ vboxDomainScreenshot(virDomainPtr dom, int tmp_fd = -1; unsigned int max_screen; + virCheckFlags(0, NULL); + vboxIIDFromUUID(&iid, dom->uuid); rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine); if (NS_FAILED(rc)) { -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/vbox/vbox_driver.c (vboxOpenDummy): Reject unknown flags. * src/vbox/vbox_tmpl.c (vboxOpen, vboxDomainReboot) (vboxNetworkOpen, vboxNetworkGetXMLDesc, vboxStorageOpen) (vboxStorageVolCreateXML, vboxStorageVolDelete) (vboxStorageVolGetXMLDesc, vboxDomainScreenshot): Likewise. --- src/vbox/vbox_driver.c | 5 ++++- src/vbox/vbox_tmpl.c | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/vmware/vmware_driver.c (vmwareOpen, vmwareDomainReboot) (vmwareDomainCreateXML, vmwareDomainCreateWithFlags): Reject unknown flags. --- src/vmware/vmware_driver.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 3f0cfae..55694ef 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -74,11 +74,13 @@ vmwareDataFreeFunc(void *data) static virDrvOpenStatus vmwareOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct vmware_driver *driver; char * vmrun = NULL; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->uri == NULL) { /* @TODO accept */ return VIR_DRV_OPEN_DECLINED; @@ -446,11 +448,10 @@ vmwareDomainResume(virDomainPtr dom) } static int -vmwareDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) +vmwareDomainReboot(virDomainPtr dom, unsigned int flags) { struct vmware_driver *driver = dom->conn->privateData; const char * vmxPath = NULL; - virDomainObjPtr vm; const char *cmd[] = { VMRUN, "-T", PROGRAM_SENTINAL, @@ -458,6 +459,8 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) }; int ret = -1; + virCheckFlags(0, -1); + vmwareDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); vmwareDriverUnlock(driver); @@ -492,7 +495,7 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) static virDomainPtr vmwareDomainCreateXML(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct vmware_driver *driver = conn->privateData; virDomainDefPtr vmdef = NULL; @@ -503,6 +506,8 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, vmwareDomainPtr pDomain = NULL; virVMXContext ctx; + virCheckFlags(0, NULL); + ctx.formatFileName = vmwareCopyVMXFileName; vmwareDriverLock(driver); @@ -562,12 +567,14 @@ cleanup: static int vmwareDomainCreateWithFlags(virDomainPtr dom, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { struct vmware_driver *driver = dom->conn->privateData; virDomainObjPtr vm; int ret = -1; + virCheckFlags(0, -1); + vmwareDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/vmware/vmware_driver.c (vmwareOpen, vmwareDomainReboot) (vmwareDomainCreateXML, vmwareDomainCreateWithFlags): Reject unknown flags. --- src/vmware/vmware_driver.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/xen/xen_driver.c (xenUnifiedDomainXMLFromNative) (xenUnifiedDomainXMLToNative, xenUnifiedDomainBlockPeek): Reject unknown flags. * src/xen/xen_hypervisor.c (xenHypervisorOpen) (xenHypervisorGetDomainState): Likewise. * src/xen/xen_inotify.c (xenInotifyOpen): Likewise. * src/xen/xs_internal.c (xenStoreOpen, xenStoreDomainGetState) (xenStoreDomainReboot): Likewise. * src/xen/xend_internal.c (xenDaemonOpen, xenDaemonDomainReboot) (xenDaemonDomainCoreDump, xenDaemonDomainGetState) (xenDaemonDomainMigratePrepare): Likewise. (xenDaemonDomainGetXMLDesc): Prefer unsigned flags. * src/xen/xend_internal.h (xenDaemonDomainGetXMLDesc): Likewise. * src/xen/xm_internal.h (xenXMDomainGetXMLDesc): Likewise. * src/xen/xm_internal.c (xenXMDomainGetXMLDesc): Likewise. (xenXMOpen, xenXMDomainGetState): Reject unknown flags. --- src/xen/xen_driver.c | 12 +++++++++--- src/xen/xen_hypervisor.c | 8 ++++++-- src/xen/xen_inotify.c | 4 +++- src/xen/xend_internal.c | 23 +++++++++++++++++------ src/xen/xend_internal.h | 3 ++- src/xen/xm_internal.c | 11 ++++++++--- src/xen/xm_internal.h | 2 +- src/xen/xs_internal.c | 12 +++++++++--- 8 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 0f66395..2cdb6c4 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1261,7 +1261,7 @@ static char * xenUnifiedDomainXMLFromNative(virConnectPtr conn, const char *format, const char *config, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDomainDefPtr def = NULL; char *ret = NULL; @@ -1271,6 +1271,8 @@ xenUnifiedDomainXMLFromNative(virConnectPtr conn, int vncport; GET_PRIVATE(conn); + virCheckFlags(0, NULL); + if (STRNEQ(format, XEN_CONFIG_FORMAT_XM) && STRNEQ(format, XEN_CONFIG_FORMAT_SEXPR)) { xenUnifiedError(VIR_ERR_INVALID_ARG, @@ -1311,13 +1313,15 @@ static char * xenUnifiedDomainXMLToNative(virConnectPtr conn, const char *format, const char *xmlData, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDomainDefPtr def = NULL; char *ret = NULL; virConfPtr conf = NULL; GET_PRIVATE(conn); + virCheckFlags(0, NULL); + if (STRNEQ(format, XEN_CONFIG_FORMAT_XM) && STRNEQ(format, XEN_CONFIG_FORMAT_SEXPR)) { xenUnifiedError(VIR_ERR_INVALID_ARG, @@ -1766,11 +1770,13 @@ xenUnifiedDomainInterfaceStats (virDomainPtr dom, const char *path, static int xenUnifiedDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long offset, size_t size, - void *buffer, unsigned int flags ATTRIBUTE_UNUSED) + void *buffer, unsigned int flags) { int r; GET_PRIVATE (dom->conn); + virCheckFlags(0, -1); + if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) { r = xenDaemonDomainBlockPeek (dom, path, offset, size, buffer); if (r != -2) return r; diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index a92b743..543dfb1 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -2201,11 +2201,13 @@ xenHypervisorInit(void) virDrvOpenStatus xenHypervisorOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int ret; xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (initialized == 0) if (xenHypervisorInit() == -1) return -1; @@ -3272,11 +3274,13 @@ int xenHypervisorGetDomainState(virDomainPtr domain, int *state, int *reason, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { xenUnifiedPrivatePtr priv = domain->conn->privateData; virDomainInfo info; + virCheckFlags(0, -1); + if (domain->conn == NULL) return -1; diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c index 2d7207c..241dbc7 100644 --- a/src/xen/xen_inotify.c +++ b/src/xen/xen_inotify.c @@ -383,13 +383,15 @@ cleanup: virDrvOpenStatus xenInotifyOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { DIR *dh; struct dirent *ent; char *path; xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (priv->configDir) { priv->useXenConfigCache = 1; } else { diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 6c2f051..17be97e 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -1323,11 +1323,13 @@ error: virDrvOpenStatus xenDaemonOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { char *port = NULL; int ret = VIR_DRV_OPEN_ERROR; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + /* Switch on the scheme, which we expect to be NULL (file), * "http" or "xen". */ @@ -1488,8 +1490,10 @@ xenDaemonDomainShutdown(virDomainPtr domain) * Returns 0 in case of success, -1 (with errno) in case of error. */ int -xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) +xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags) { + virCheckFlags(0, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); return(-1); @@ -1629,8 +1633,10 @@ xenDaemonDomainSave(virDomainPtr domain, const char *filename) */ static int xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) || (filename == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); @@ -1837,7 +1843,8 @@ cleanup: * the caller must free() the returned value. */ char * -xenDaemonDomainGetXMLDesc(virDomainPtr domain, int flags, const char *cpus) +xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags, + const char *cpus) { xenUnifiedPrivatePtr priv; virDomainDefPtr def; @@ -1921,11 +1928,13 @@ int xenDaemonDomainGetState(virDomainPtr domain, int *state, int *reason, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { xenUnifiedPrivatePtr priv = domain->conn->privateData; struct sexpr *root; + virCheckFlags(0, -1); + if (domain->id < 0 && priv->xendConfigVersion < 3) return -1; @@ -3151,10 +3160,12 @@ xenDaemonDomainMigratePrepare (virConnectPtr dconn, int *cookielen ATTRIBUTE_UNUSED, const char *uri_in, char **uri_out, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname ATTRIBUTE_UNUSED, unsigned long resource ATTRIBUTE_UNUSED) { + virCheckFlags(0, -1); + /* If uri_in is NULL, get the current hostname as a best guess * of how the source host should connect to us. Note that caller * deallocates this string. diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h index 5d324da..c4ed9ba 100644 --- a/src/xen/xend_internal.h +++ b/src/xen/xend_internal.h @@ -115,7 +115,8 @@ int xenDaemonDomainGetState(virDomainPtr domain, int *state, int *reason, unsigned int flags); -char *xenDaemonDomainGetXMLDesc(virDomainPtr domain, int flags, const char *cpus); +char *xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags, + const char *cpus); unsigned long xenDaemonDomainGetMaxMemory(virDomainPtr domain); char **xenDaemonListDomainsOld(virConnectPtr xend); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 01b9c4e..9347e39 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -442,10 +442,12 @@ int xenXMConfigCacheRefresh (virConnectPtr conn) { virDrvOpenStatus xenXMOpen (virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { xenUnifiedPrivatePtr priv = conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + priv->configDir = XM_CONFIG_DIR; priv->configCache = virHashCreate(50, xenXMConfigFree); @@ -485,8 +487,10 @@ int xenXMDomainGetState(virDomainPtr domain, int *state, int *reason, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + if (domain->id != -1) return -1; @@ -543,7 +547,8 @@ error: * Turn a config record into a lump of XML describing the * domain, suitable for later feeding for virDomainCreateXML */ -char *xenXMDomainGetXMLDesc(virDomainPtr domain, int flags) { +char *xenXMDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) +{ xenUnifiedPrivatePtr priv; const char *filename; xenXMConfCachePtr entry; diff --git a/src/xen/xm_internal.h b/src/xen/xm_internal.h index cf315cd..89af23e 100644 --- a/src/xen/xm_internal.h +++ b/src/xen/xm_internal.h @@ -45,7 +45,7 @@ int xenXMDomainGetState(virDomainPtr domain, int *state, int *reason, unsigned int flags); -char *xenXMDomainGetXMLDesc(virDomainPtr domain, int flags); +char *xenXMDomainGetXMLDesc(virDomainPtr domain, unsigned int flags); int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory); int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory); unsigned long xenXMDomainGetMaxMemory(virDomainPtr domain); diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c index 48e450a..f62d716 100644 --- a/src/xen/xs_internal.c +++ b/src/xen/xs_internal.c @@ -267,10 +267,12 @@ virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name) virDrvOpenStatus xenStoreOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (flags & VIR_CONNECT_RO) priv->xshandle = xs_daemon_open_readonly(); else @@ -461,10 +463,12 @@ int xenStoreDomainGetState(virDomainPtr domain, int *state, int *reason, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { char *running; + virCheckFlags(0, -1); + if (domain->id == -1) return -1; @@ -778,11 +782,13 @@ xenStoreDomainShutdown(virDomainPtr domain) * Returns 0 in case of success, -1 in case of error. */ int -xenStoreDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) +xenStoreDomainReboot(virDomainPtr domain, unsigned int flags) { int ret; xenUnifiedPrivatePtr priv; + virCheckFlags(0, -1); + if ((domain == NULL) || (domain->conn == NULL)) { virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__); return(-1); -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/xen/xen_driver.c (xenUnifiedDomainXMLFromNative) (xenUnifiedDomainXMLToNative, xenUnifiedDomainBlockPeek): Reject unknown flags. * src/xen/xen_hypervisor.c (xenHypervisorOpen) (xenHypervisorGetDomainState): Likewise. * src/xen/xen_inotify.c (xenInotifyOpen): Likewise. * src/xen/xs_internal.c (xenStoreOpen, xenStoreDomainGetState) (xenStoreDomainReboot): Likewise. * src/xen/xend_internal.c (xenDaemonOpen, xenDaemonDomainReboot) (xenDaemonDomainCoreDump, xenDaemonDomainGetState) (xenDaemonDomainMigratePrepare): Likewise. (xenDaemonDomainGetXMLDesc): Prefer unsigned flags. * src/xen/xend_internal.h (xenDaemonDomainGetXMLDesc): Likewise. * src/xen/xm_internal.h (xenXMDomainGetXMLDesc): Likewise. * src/xen/xm_internal.c (xenXMDomainGetXMLDesc): Likewise. (xenXMOpen, xenXMDomainGetState): Reject unknown flags. --- src/xen/xen_driver.c | 12 +++++++++--- src/xen/xen_hypervisor.c | 8 ++++++-- src/xen/xen_inotify.c | 4 +++- src/xen/xend_internal.c | 23 +++++++++++++++++------ src/xen/xend_internal.h | 3 ++- src/xen/xm_internal.c | 11 ++++++++--- src/xen/xm_internal.h | 2 +- src/xen/xs_internal.c | 12 +++++++++--- 8 files changed, 55 insertions(+), 20 deletions(-)
@@ -1629,8 +1633,10 @@ xenDaemonDomainSave(virDomainPtr domain, const char *filename) */ static int xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) || (filename == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
Third time fooled by ATTRIBUTE_UNUSED. xenDaemonDomainCoreDump understands VIR_DUMP_LIVE and VIR_DUMP_CRASH.
@@ -3151,10 +3160,12 @@ xenDaemonDomainMigratePrepare (virConnectPtr dconn, int *cookielen ATTRIBUTE_UNUSED, const char *uri_in, char **uri_out, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname ATTRIBUTE_UNUSED, unsigned long resource ATTRIBUTE_UNUSED) { + virCheckFlags(0, -1); + /* If uri_in is NULL, get the current hostname as a best guess * of how the source host should connect to us. Note that caller * deallocates this string.
This breaks virDomainMigrate, because *DomainMigratePrepare is called with the flags passed to virDomainMigrate, even if xenDaemonDomainMigratePrepare doesn't use this flags it has to accept all flags that the Xen driver understand in general form migration. A quick grep for VIR_MIGRATE_ shows that those are at least VIR_MIGRATE_LIVE VIR_MIGRATE_PERSIST_DEST VIR_MIGRATE_UNDEFINE_SOURCE VIR_MIGRATE_PAUSED -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 06:59 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
@@ -1629,8 +1633,10 @@ xenDaemonDomainSave(virDomainPtr domain, const char *filename) */ static int xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) || (filename == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
Third time fooled by ATTRIBUTE_UNUSED. xenDaemonDomainCoreDump understands VIR_DUMP_LIVE and VIR_DUMP_CRASH.
Yep, which is why for v3, I've gone through and looked at every use of virCheckFlags(0, ...) to make sure that the next instance of 'flags' is not until the next function. I'll respin this patch for my v3 series. In the meantime, I've pushed 16 and 17.
@@ -3151,10 +3160,12 @@ xenDaemonDomainMigratePrepare (virConnectPtr dconn, int *cookielen ATTRIBUTE_UNUSED, const char *uri_in, char **uri_out, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname ATTRIBUTE_UNUSED, unsigned long resource ATTRIBUTE_UNUSED) { + virCheckFlags(0, -1); + /* If uri_in is NULL, get the current hostname as a best guess * of how the source host should connect to us. Note that caller * deallocates this string.
This breaks virDomainMigrate, because *DomainMigratePrepare is called with the flags passed to virDomainMigrate, even if xenDaemonDomainMigratePrepare doesn't use this flags it has to accept all flags that the Xen driver understand in general form migration.
Good point, and somewhat relevant to your comments about ESX migration flags in 8/27 as well. I will also double-check that qemu and remote (the only other drivers with a MigratePrepare callback) are not affected. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2011/7/14 Eric Blake <eblake@redhat.com>:
On 07/13/2011 06:59 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
@@ -1629,8 +1633,10 @@ xenDaemonDomainSave(virDomainPtr domain, const char *filename) */ static int xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) || (filename == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
Third time fooled by ATTRIBUTE_UNUSED. xenDaemonDomainCoreDump understands VIR_DUMP_LIVE and VIR_DUMP_CRASH.
Yep, which is why for v3, I've gone through and looked at every use of virCheckFlags(0, ...) to make sure that the next instance of 'flags' is not until the next function. I'll respin this patch for my v3 series. In the meantime, I've pushed 16 and 17.
@@ -3151,10 +3160,12 @@ xenDaemonDomainMigratePrepare (virConnectPtr dconn, int *cookielen ATTRIBUTE_UNUSED, const char *uri_in, char **uri_out, - unsigned long flags ATTRIBUTE_UNUSED, + unsigned long flags, const char *dname ATTRIBUTE_UNUSED, unsigned long resource ATTRIBUTE_UNUSED) { + virCheckFlags(0, -1); + /* If uri_in is NULL, get the current hostname as a best guess * of how the source host should connect to us. Note that caller * deallocates this string.
This breaks virDomainMigrate, because *DomainMigratePrepare is called with the flags passed to virDomainMigrate, even if xenDaemonDomainMigratePrepare doesn't use this flags it has to accept all flags that the Xen driver understand in general form migration.
Good point, and somewhat relevant to your comments about ESX migration flags in 8/27 as well.
I will also double-check that qemu and remote (the only other drivers with a MigratePrepare callback) are not affected.
You should probably double-check all *DomainMigrate* driver functions as they all get the flags from the virDomainMigrate* functions. -- Matthias Bolte http://photron.blogspot.com

On 07/14/2011 01:25 AM, Matthias Bolte wrote:
I will also double-check that qemu and remote (the only other drivers with a MigratePrepare callback) are not affected.
You should probably double-check all *DomainMigrate* driver functions as they all get the flags from the virDomainMigrate* functions.
I did - the only affected hypervisors are qemu (which did the checks correctly, but still could be factored), ESX, and xen (both of which are in my v3 patch). -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

* src/xenapi/xenapi_driver.c (xenapiOpen, xenapiDomainReboot) (xenapiDomainGetXMLDesc): Reject unknown flags. --- src/xenapi/xenapi_driver.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 1c06f75..ba993f2 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -92,12 +92,14 @@ getCapsObject (void) */ static virDrvOpenStatus xenapiOpen (virConnectPtr conn, virConnectAuthPtr auth, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { char *username = NULL; char *password = NULL; struct _xenapiPrivate *privP = NULL; + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (conn->uri == NULL || conn->uri->scheme == NULL || STRCASENEQ(conn->uri->scheme, "XenAPI")) { return VIR_DRV_OPEN_DECLINED; @@ -802,12 +804,15 @@ xenapiDomainShutdown (virDomainPtr dom) * Returns 0 on success or -1 in case of error */ static int -xenapiDomainReboot (virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) +xenapiDomainReboot (virDomainPtr dom, unsigned int flags) { /* vm.clean_reboot */ xen_vm vm; struct xen_vm_set *vms; xen_session *session = ((struct _xenapiPrivate *)(dom->conn->privateData))->session; + + virCheckFlags(0, -1); + if (xen_vm_get_by_name_label(session, &vms, dom->name) && vms->size > 0) { if (vms->size != 1) { xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR, @@ -1295,7 +1300,7 @@ xenapiDomainGetMaxVcpus (virDomainPtr dom) * Returns XML string of the domain configuration on success or -1 in case of error */ static char * -xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) +xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { xen_vm vm=NULL; xen_vm_set *vms; @@ -1309,6 +1314,8 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) struct xen_vif_set *vif_set = NULL; char *xml; + virCheckFlags(0, NULL); + if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL; if (vms->size != 1) { xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR, -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/xenapi/xenapi_driver.c (xenapiOpen, xenapiDomainReboot) (xenapiDomainGetXMLDesc): Reject unknown flags. --- src/xenapi/xenapi_driver.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
@@ -1309,6 +1314,8 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) struct xen_vif_set *vif_set = NULL; char *xml;
+ virCheckFlags(0, NULL); + if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL; if (vms->size != 1) { xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR,
You found a bug, but made it worse instead of fixing it. xenapiDomainGetXMLDesc should pass the flags to virDomainDefFormat instead of passing 0. ACK, with passing flags to virDomainDefFormat instead of ignoring it. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 07:04 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
* src/xenapi/xenapi_driver.c (xenapiOpen, xenapiDomainReboot) (xenapiDomainGetXMLDesc): Reject unknown flags. --- src/xenapi/xenapi_driver.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
@@ -1309,6 +1314,8 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) struct xen_vif_set *vif_set = NULL; char *xml;
+ virCheckFlags(0, NULL); + if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL; if (vms->size != 1) { xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR,
You found a bug, but made it worse instead of fixing it. xenapiDomainGetXMLDesc should pass the flags to virDomainDefFormat instead of passing 0.
ACK, with passing flags to virDomainDefFormat instead of ignoring it.
Pushed with this squashed in: diff --git i/src/xenapi/xenapi_driver.c w/src/xenapi/xenapi_driver.c index 5d5e810..aa616ca 100644 --- i/src/xenapi/xenapi_driver.c +++ w/src/xenapi/xenapi_driver.c @@ -1316,7 +1316,9 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) struct xen_vif_set *vif_set = NULL; char *xml; - virCheckFlags(0, NULL); + virCheckFlags(VIR_DOMAIN_XML_SECURE | + VIR_DOMAIN_XML_INACTIVE | + VIR_DOMAIN_XML_UPDATE_CPU, NULL); if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL; if (vms->size != 1) { @@ -1483,7 +1485,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) xen_vif_set_free(vif_set); } if (vms) xen_vm_set_free(vms); - xml = virDomainDefFormat(defPtr, 0); + xml = virDomainDefFormat(defPtr, flags); virDomainDefFree(defPtr); return xml; -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

* tools/virsh.c (vshCmdDef): Change flags type. * daemon/remote.c (remoteDispatchOpen): Likewise. --- v2: new patch daemon/remote.c | 2 +- tools/virsh.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index a2e79ef..1ade187 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -442,7 +442,7 @@ remoteDispatchOpen(virNetServerPtr server ATTRIBUTE_UNUSED, struct remote_open_args *args) { const char *name; - int flags; + unsigned int flags; struct daemonClientPrivate *priv = virNetServerClientGetPrivateData(client); int rv = -1; diff --git a/tools/virsh.c b/tools/virsh.c index 3cdf043..9c375a4 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -201,7 +201,7 @@ typedef struct { bool (*handler) (vshControl *, const vshCmd *); /* command handler */ const vshCmdOptDef *opts; /* definition of command options */ const vshCmdInfo *info; /* details about command */ - int flags; /* bitwise OR of VSH_CMD_FLAG */ + unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */ } vshCmdDef; /* -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* tools/virsh.c (vshCmdDef): Change flags type. * daemon/remote.c (remoteDispatchOpen): Likewise. ---
v2: new patch
daemon/remote.c | 2 +- tools/virsh.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

'unsigned a' and 'unsigned int a' are synonyms, but we generally always spell out the 'int' in that case. Fixing this will avoid a false positive in the next syntax-check commit. * src/conf/node_device_conf.h (pci_config_address) (_virNodeDevCapsDef): Prefer 'unsigned int' over 'unsigned'. --- v2: new patch. I didn't add a syntax check for implicit int, though, as we have a lot of other cases of that. Rather, this was the only hit when grepping for 'unsigned flags'. src/conf/node_device_conf.h | 58 +++++++++++++++++++++--------------------- 1 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index e90bdc5..cef86d4 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -83,10 +83,10 @@ enum virNodeDevPCICapFlags { }; struct pci_config_address { - unsigned domain; - unsigned bus; - unsigned slot; - unsigned function; + unsigned int domain; + unsigned int bus; + unsigned int slot; + unsigned int function; }; typedef struct _virNodeDevCapsDef virNodeDevCapsDef; @@ -109,55 +109,55 @@ struct _virNodeDevCapsDef { } firmware; } system; struct { - unsigned domain; - unsigned bus; - unsigned slot; - unsigned function; - unsigned product; - unsigned vendor; - unsigned class; + unsigned int domain; + unsigned int bus; + unsigned int slot; + unsigned int function; + unsigned int product; + unsigned int vendor; + unsigned int class; char *product_name; char *vendor_name; struct pci_config_address *physical_function; struct pci_config_address **virtual_functions; - unsigned num_virtual_functions; - unsigned flags; + unsigned int num_virtual_functions; + unsigned int flags; } pci_dev; struct { - unsigned bus; - unsigned device; - unsigned product; - unsigned vendor; + unsigned int bus; + unsigned int device; + unsigned int product; + unsigned int vendor; char *product_name; char *vendor_name; } usb_dev; struct { - unsigned number; - unsigned _class; /* "class" is reserved in C */ - unsigned subclass; - unsigned protocol; + unsigned int number; + unsigned int _class; /* "class" is reserved in C */ + unsigned int subclass; + unsigned int protocol; char *description; } usb_if; struct { char *address; - unsigned address_len; + unsigned int address_len; char *ifname; enum virNodeDevNetCapType subtype; /* LAST -> no subtype */ } net; struct { - unsigned host; + unsigned int host; char *wwnn; char *wwpn; - unsigned flags; + unsigned int flags; } scsi_host; struct { char *name; } scsi_target; struct { - unsigned host; - unsigned bus; - unsigned target; - unsigned lun; + unsigned int host; + unsigned int bus; + unsigned int target; + unsigned int lun; char *type; } scsi; struct { @@ -172,7 +172,7 @@ struct _virNodeDevCapsDef { char *vendor; char *serial; char *media_label; - unsigned flags; /* virNodeDevStorageCapFlags bits */ + unsigned int flags; /* virNodeDevStorageCapFlags bits */ } storage; } data; virNodeDevCapsDefPtr next; /* next capability */ -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
'unsigned a' and 'unsigned int a' are synonyms, but we generally always spell out the 'int' in that case. Fixing this will avoid a false positive in the next syntax-check commit.
* src/conf/node_device_conf.h (pci_config_address) (_virNodeDevCapsDef): Prefer 'unsigned int' over 'unsigned'. ---
v2: new patch. I didn't add a syntax check for implicit int, though, as we have a lot of other cases of that. Rather, this was the only hit when grepping for 'unsigned flags'.
src/conf/node_device_conf.h | 58 +++++++++++++++++++++--------------------- 1 files changed, 29 insertions(+), 29 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* python/libvirt-override.c (libvirt_virConnectOpenAuth) (libvirt_virDomainSnapshotListNames) (libvirt_virDomainRevertToSnapshot): Change flags type. --- v2: new patch python/libvirt-override.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 2b88796..b713b6a 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -791,7 +791,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; virConnectPtr c_retval; char * name; - int flags; + unsigned int flags; PyObject *pyauth; PyObject *pycredcb; PyObject *pycredtype; @@ -991,7 +991,7 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED, int c_retval, i; virDomainPtr dom; PyObject *pyobj_dom; - int flags; + unsigned int flags; if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListNames", &pyobj_dom, &flags)) return(NULL); @@ -1035,7 +1035,7 @@ libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED, virDomainSnapshotPtr snap; PyObject *pyobj_snap; PyObject *pyobj_dom; - int flags; + unsigned int flags; if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainRevertToSnapshot", &pyobj_dom, &pyobj_snap, &flags)) return(NULL); -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* python/libvirt-override.c (libvirt_virConnectOpenAuth) (libvirt_virDomainSnapshotListNames) (libvirt_virDomainRevertToSnapshot): Change flags type. ---
v2: new patch
python/libvirt-override.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/conf/cpu_conf.h (virCPUDefFormat, virCPUDefFormatBuf): Change flags type. * src/conf/cpu_conf.c (virCPUDefFormat, virCPUDefFormatBuf): Likewise. * src/conf/storage_conf.c (_virStoragePoolOptions): Likewise. * src/datatypes.h (_virConnect, _virStream): Likewise. --- v2: new patch src/conf/cpu_conf.c | 6 +++--- src/conf/cpu_conf.h | 6 +++--- src/conf/storage_conf.c | 4 ++-- src/datatypes.h | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 14e93db..5cecda2 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -1,7 +1,7 @@ /* * cpu_conf.h: CPU XML handling * - * Copyright (C) 2009, 2010 Red Hat, Inc. + * Copyright (C) 2009-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -307,7 +307,7 @@ error: char * virCPUDefFormat(virCPUDefPtr def, const char *indent, - int flags) + unsigned int flags) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -331,7 +331,7 @@ int virCPUDefFormatBuf(virBufferPtr buf, virCPUDefPtr def, const char *indent, - int flags) + unsigned int flags) { unsigned int i; diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index ecd4e10..57b85e1 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -1,7 +1,7 @@ /* * cpu_conf.h: CPU XML handling * - * Copyright (C) 2009, 2010 Red Hat, Inc. + * Copyright (C) 2009-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -107,13 +107,13 @@ virCPUDefIsEqual(virCPUDefPtr src, char * virCPUDefFormat(virCPUDefPtr def, const char *indent, - int flags); + unsigned int flags); int virCPUDefFormatBuf(virBufferPtr buf, virCPUDefPtr def, const char *indent, - int flags); + unsigned int flags); int virCPUDefAddFeature(virCPUDefPtr cpu, diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index f6f8be1..cc55b80 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1,7 +1,7 @@ /* * storage_conf.c: config handling for storage driver * - * Copyright (C) 2006-2010 Red Hat, Inc. + * Copyright (C) 2006-2011 Red Hat, Inc. * Copyright (C) 2006-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -117,7 +117,7 @@ enum { typedef struct _virStoragePoolOptions virStoragePoolOptions; typedef virStoragePoolOptions *virStoragePoolOptionsPtr; struct _virStoragePoolOptions { - int flags; + unsigned int flags; int defaultFormat; virStoragePoolFormatToString formatToString; virStoragePoolFormatFromString formatFromString; diff --git a/src/datatypes.h b/src/datatypes.h index f114360..91b1bfd 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -150,7 +150,7 @@ struct _virConnect { * since. Thus no need to lock when accessing them */ unsigned int magic; /* specific value to check */ - int flags; /* a set of connection flags */ + unsigned int flags; /* a set of connection flags */ xmlURIPtr uri; /* connection URI */ /* The underlying hypervisor driver and network driver. */ @@ -297,7 +297,7 @@ struct _virStream { unsigned int magic; virConnectPtr conn; int refs; - int flags; + unsigned int flags; virStreamDriverPtr driver; void *privateData; -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/conf/cpu_conf.h (virCPUDefFormat, virCPUDefFormatBuf): Change flags type. * src/conf/cpu_conf.c (virCPUDefFormat, virCPUDefFormatBuf): Likewise. * src/conf/storage_conf.c (_virStoragePoolOptions): Likewise. * src/datatypes.h (_virConnect, _virStream): Likewise. ---
v2: new patch
src/conf/cpu_conf.c | 6 +++--- src/conf/cpu_conf.h | 6 +++--- src/conf/storage_conf.c | 4 ++-- src/datatypes.h | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

No need to repeat common code. * src/util/bridge.c (brInit): Use virSetCloseExec. (brSetInterfaceUp): Prefer unsigned flags. * src/uml/uml_driver.c (umlSetCloseExec): Delete. (umlStartVMDaemon): Use util version instead. --- v2: new patch src/uml/uml_driver.c | 19 +++---------------- src/util/bridge.c | 19 +++++-------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 9f66aee..801015a 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -113,19 +113,6 @@ static int umlOpenMonitor(struct uml_driver *driver, static int umlReadPidFile(struct uml_driver *driver, virDomainObjPtr vm); -static int umlSetCloseExec(int fd) { - int flags; - if ((flags = fcntl(fd, F_GETFD)) < 0) - goto error; - flags |= FD_CLOEXEC; - if ((fcntl(fd, F_SETFD, flags)) < 0) - goto error; - return 0; - error: - VIR_ERROR(_("Failed to set close-on-exec file descriptor flag")); - return -1; -} - static int umlStartVMDaemon(virConnectPtr conn, struct uml_driver *driver, virDomainObjPtr vm); @@ -862,9 +849,9 @@ static int umlStartVMDaemon(virConnectPtr conn, } VIR_FREE(logfile); - if (umlSetCloseExec(logfd) < 0) { - virReportSystemError(errno, - "%s", _("Unable to set VM logfile close-on-exec flag")); + if (virSetCloseExec(logfd) < 0) { + virReportSystemError(errno, "%s", + _("Unable to set VM logfile close-on-exec flag")); VIR_FORCE_CLOSE(logfd); return -1; } diff --git a/src/util/bridge.c b/src/util/bridge.c index 7204e64..a6b5768 100644 --- a/src/util/bridge.c +++ b/src/util/bridge.c @@ -72,25 +72,16 @@ int brInit(brControl **ctlp) { int fd; - int flags; if (!ctlp || *ctlp) return EINVAL; fd = socket(AF_INET, SOCK_STREAM, 0); - if (fd < 0) - return errno; - - if ((flags = fcntl(fd, F_GETFD)) < 0 || - fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { - int err = errno; - VIR_FORCE_CLOSE(fd); - return err; - } - - if (VIR_ALLOC(*ctlp) < 0) { + if (fd < 0 || + virSetCloseExec(fd) < 0 || + VIR_ALLOC(*ctlp) < 0) { VIR_FORCE_CLOSE(fd); - return ENOMEM; + return errno; } (*ctlp)->fd = fd; @@ -599,7 +590,7 @@ brSetInterfaceUp(brControl *ctl, int up) { struct ifreq ifr; - int flags; + unsigned int flags; if (!ctl || !ifname) return EINVAL; -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
No need to repeat common code.
* src/util/bridge.c (brInit): Use virSetCloseExec. (brSetInterfaceUp): Prefer unsigned flags. * src/uml/uml_driver.c (umlSetCloseExec): Delete. (umlStartVMDaemon): Use util version instead. ---
v2: new patch
src/uml/uml_driver.c | 19 +++---------------- src/util/bridge.c | 19 +++++-------------- 2 files changed, 8 insertions(+), 30 deletions(-)
diff --git a/src/util/bridge.c b/src/util/bridge.c index 7204e64..a6b5768 100644 --- a/src/util/bridge.c +++ b/src/util/bridge.c @@ -72,25 +72,16 @@ int brInit(brControl **ctlp) { int fd; - int flags;
if (!ctlp || *ctlp) return EINVAL;
fd = socket(AF_INET, SOCK_STREAM, 0); - if (fd < 0) - return errno; - - if ((flags = fcntl(fd, F_GETFD)) < 0 || - fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { - int err = errno; - VIR_FORCE_CLOSE(fd); - return err; - } - - if (VIR_ALLOC(*ctlp) < 0) { + if (fd < 0 || + virSetCloseExec(fd) < 0 || + VIR_ALLOC(*ctlp) < 0) { VIR_FORCE_CLOSE(fd); - return ENOMEM; + return errno; }
Is it guaranteed that calloc will set ENOMEM, or do we need some gnulib module to guarantee this?
(*ctlp)->fd = fd; @@ -599,7 +590,7 @@ brSetInterfaceUp(brControl *ctl, int up) { struct ifreq ifr; - int flags; + unsigned int flags;
flags is used used with ifr.ifr_flags that is signed (actually it's a short). So I'd prefer renaming it to ifflags and keep it as int. ACK, with that questions/comments answered/addressed. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 07:22 AM, Matthias Bolte wrote:
2011/7/8 Eric Blake <eblake@redhat.com>:
No need to repeat common code.
* src/util/bridge.c (brInit): Use virSetCloseExec. (brSetInterfaceUp): Prefer unsigned flags. * src/uml/uml_driver.c (umlSetCloseExec): Delete. (umlStartVMDaemon): Use util version instead. ---
v2: new patch
I've pushed 20-23.
- - if (VIR_ALLOC(*ctlp) < 0) { + if (fd < 0 || + virSetCloseExec(fd) < 0 || + VIR_ALLOC(*ctlp) < 0) { VIR_FORCE_CLOSE(fd); - return ENOMEM; + return errno; }
Is it guaranteed that calloc will set ENOMEM, or do we need some gnulib module to guarantee this?
Well what do you know. We need to import 'calloc-posix' to get that to happen on mingw. :)
(*ctlp)->fd = fd; @@ -599,7 +590,7 @@ brSetInterfaceUp(brControl *ctl, int up) { struct ifreq ifr; - int flags; + unsigned int flags;
flags is used used with ifr.ifr_flags that is signed (actually it's a short). So I'd prefer renaming it to ifflags and keep it as int.
ACK, with that questions/comments answered/addressed.
Here's what I squashed in before pushing. diff --git i/bootstrap.conf w/bootstrap.conf index 3c3d0e0..2fc457e 100644 --- i/bootstrap.conf +++ w/bootstrap.conf @@ -27,6 +27,7 @@ byteswap c-ctype c-strcase c-strcasestr +calloc-posix canonicalize-lgpl chown close diff --git i/src/util/bridge.c w/src/util/bridge.c index a6b5768..0f4b639 100644 --- i/src/util/bridge.c +++ w/src/util/bridge.c @@ -590,7 +590,7 @@ brSetInterfaceUp(brControl *ctl, int up) { struct ifreq ifr; - unsigned int flags; + int ifflags; if (!ctl || !ifname) return EINVAL; @@ -603,10 +603,10 @@ brSetInterfaceUp(brControl *ctl, if (ioctl(ctl->fd, SIOCGIFFLAGS, &ifr) < 0) return errno; - flags = up ? (ifr.ifr_flags | IFF_UP) : (ifr.ifr_flags & ~IFF_UP); + ifflags = up ? (ifr.ifr_flags | IFF_UP) : (ifr.ifr_flags & ~IFF_UP); - if (ifr.ifr_flags != flags) { - ifr.ifr_flags = flags; + if (ifr.ifr_flags != ifflags) { + ifr.ifr_flags = ifflags; if (ioctl(ctl->fd, SIOCSIFFLAGS, &ifr) < 0) return errno; -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

For static functions not used as callbacks, there's no need to keep an unused parameter. * src/conf/domain_conf.c (virDomainChrDefParseTargetXML) (virDomainTimerDefParseXML, virDomainHostdevSubsysUsbDefParseXML) (virDomainVcpuPinDefParseXML): Drop unused parameter. (virDomainChrDefParseXML, virDomainDefParseXML) (virDomainHostdevDefParseXML): Update callers. (virDomainNetDefParseXML): Mark flags used. --- v2: new patch src/conf/domain_conf.c | 24 +++++++++--------------- 1 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a680b11..6f20060 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2727,7 +2727,7 @@ virDomainNetDefParseXML(virCapsPtr caps, xmlNodePtr node, xmlXPathContextPtr ctxt, virBitmapPtr bootMap, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virDomainNetDefPtr def; xmlNodePtr cur; @@ -3179,8 +3179,7 @@ out: static int virDomainChrDefParseTargetXML(virCapsPtr caps, virDomainChrDefPtr def, - xmlNodePtr cur, - unsigned int flags ATTRIBUTE_UNUSED) + xmlNodePtr cur) { int ret = -1; unsigned int port; @@ -3562,8 +3561,7 @@ virDomainChrDefParseXML(virCapsPtr caps, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { if (xmlStrEqual(cur->name, BAD_CAST "target")) { - if (virDomainChrDefParseTargetXML(caps, def, cur, - flags) < 0) { + if (virDomainChrDefParseTargetXML(caps, def, cur) < 0) { goto error; } } @@ -3819,8 +3817,7 @@ error: /* Parse the XML definition for a clock timer */ static virDomainTimerDefPtr virDomainTimerDefParseXML(const xmlNodePtr node, - xmlXPathContextPtr ctxt, - unsigned int flags ATTRIBUTE_UNUSED) + xmlXPathContextPtr ctxt) { char *name = NULL; char *present = NULL; @@ -4791,8 +4788,7 @@ error: static int virDomainHostdevSubsysUsbDefParseXML(const xmlNodePtr node, - virDomainHostdevDefPtr def, - unsigned int flags ATTRIBUTE_UNUSED) + virDomainHostdevDefPtr def) { int ret = -1; @@ -5012,7 +5008,7 @@ virDomainHostdevDefParseXML(const xmlNodePtr node, if (xmlStrEqual(cur->name, BAD_CAST "source")) { if (def->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { - if (virDomainHostdevSubsysUsbDefParseXML(cur, def, flags) < 0) + if (virDomainHostdevSubsysUsbDefParseXML(cur, def) < 0) goto error; } if (def->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && @@ -5730,8 +5726,7 @@ cleanup: static virDomainVcpuPinDefPtr virDomainVcpuPinDefParseXML(const xmlNodePtr node, xmlXPathContextPtr ctxt, - int maxvcpus, - unsigned int flags ATTRIBUTE_UNUSED) + int maxvcpus) { virDomainVcpuPinDefPtr def; xmlNodePtr oldnode = ctxt->node; @@ -5976,7 +5971,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, for (i = 0 ; i < n ; i++) { virDomainVcpuPinDefPtr vcpupin = NULL; - vcpupin = virDomainVcpuPinDefParseXML(nodes[i], ctxt, def->maxvcpus, 0); + vcpupin = virDomainVcpuPinDefParseXML(nodes[i], ctxt, def->maxvcpus); if (!vcpupin) goto error; @@ -6106,8 +6101,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, goto no_memory; for (i = 0 ; i < n ; i++) { virDomainTimerDefPtr timer = virDomainTimerDefParseXML(nodes[i], - ctxt, - flags); + ctxt); if (!timer) goto error; -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
For static functions not used as callbacks, there's no need to keep an unused parameter.
* src/conf/domain_conf.c (virDomainChrDefParseTargetXML) (virDomainTimerDefParseXML, virDomainHostdevSubsysUsbDefParseXML) (virDomainVcpuPinDefParseXML): Drop unused parameter. (virDomainChrDefParseXML, virDomainDefParseXML) (virDomainHostdevDefParseXML): Update callers. (virDomainNetDefParseXML): Mark flags used. ---
v2: new patch
src/conf/domain_conf.c | 24 +++++++++--------------- 1 files changed, 9 insertions(+), 15 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

* src/remote/remote_driver.c (call, remoteOpenSecondaryDriver): Prefer unsigned flags. --- v2: new patch src/remote/remote_driver.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 8dff6a8..2bfb15b 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -104,7 +104,7 @@ static void remoteDriverUnlock(struct private_data *driver) } static int call (virConnectPtr conn, struct private_data *priv, - int flags, int proc_nr, + unsigned int flags, int proc_nr, xdrproc_t args_filter, char *args, xdrproc_t ret_filter, char *ret); static int remoteAuthenticate (virConnectPtr conn, struct private_data *priv, @@ -714,7 +714,7 @@ remoteAllocPrivateData(void) static int remoteOpenSecondaryDriver(virConnectPtr conn, virConnectAuthPtr auth, - int flags, + unsigned int flags, struct private_data **priv) { int ret; @@ -3914,7 +3914,7 @@ done: static int call (virConnectPtr conn ATTRIBUTE_UNUSED, struct private_data *priv, - int flags, + unsigned int flags, int proc_nr, xdrproc_t args_filter, char *args, xdrproc_t ret_filter, char *ret) -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
* src/remote/remote_driver.c (call, remoteOpenSecondaryDriver): Prefer unsigned flags. ---
v2: new patch
src/remote/remote_driver.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

Enforce the recent flags cleanups - we want to use 'unsigned int flags' in any of our APIs (except where backwards compatibility is important, in the public migration APIs), and that all flags are checked for validity (except when there are stub functions that completely ignore the flags argument). There are a few minor tweaks done here to avoid false positives: signed arguments passed to open() are renamed oflags, and flags arguments that are legitimately ignored are renamed flags_unused. * cfg.mk (sc_flags_usage): New rule. (exclude_file_name_regexp--sc_flags_usage): And a few exemptions. * src/util/iohelper.c (runIO, main): Rename variable. * src/util/util.c (virSetInherit): Likewise. * src/fdstream.h (virFDStreamOpenFile, virFDStreamCreateFile): Likewise. * src/fdstream.c (virFDStreamOpenFileInternal) (virFDStreamOpenFile, virFDStreamCreateFile): Likewise. * src/util/command.c (virExecWithHook) [WIN32]: Likewise. * src/util/util.c (virFileOpenAs, virDirCreate) [WIN32]: Likewise. * src/locking/lock_manager.c (virLockManagerPluginNew) [!HAVE_DLFCN_H]: Likewise. * src/locking/lock_driver_nop.c (virLockManagerNopNew) (virLockManagerNopAddResource, virLockManagerNopAcquire) (virLockManagerNopRelease, virLockManagerNopInquire): Likewise. --- cfg.mk | 21 ++++++++++++++++++++- src/fdstream.c | 28 ++++++++++++++-------------- src/fdstream.h | 6 +++--- src/locking/lock_driver_nop.c | 10 +++++----- src/locking/lock_manager.c | 7 ++++--- src/util/command.c | 2 +- src/util/iohelper.c | 18 +++++++++--------- src/util/util.c | 14 +++++++------- 8 files changed, 63 insertions(+), 43 deletions(-) diff --git a/cfg.mk b/cfg.mk index 24539b1..a9ee9ea 100644 --- a/cfg.mk +++ b/cfg.mk @@ -278,6 +278,25 @@ sc_flags_debug: halt='debug flag values with %x' \ $(_sc_search_regexp) +# Prefer 'unsigned int flags', along with checks for unknown flags. +# For historical reasons, we are stuck with 'unsigned long flags' in +# migration and in a few other places. +# Three tests in this check: a fixed number of non-int flags in public +# API, no flags marked unused, and 'unsigned' should appear before any +# declaration of a flags variable (hence the prohibit line of [^d]). +# The existence of long long makes the third test slightly harder. +sc_flags_usage: + @test "$$(grep -c 'long flags' \ + $(srcdir)/include/libvirt/libvirt.h.in)" != 4 && \ + { echo '$(ME): new API should use "unsigned int flags"' 1>&2; \ + exit 1; } || : + @prohibit=' flags ''ATTRIBUTE_UNUSED' \ + halt='flags should be checked with virCheckFlags' \ + $(_sc_search_regexp) + @prohibit='^[^@]*([^d] (int|long long)|[^dg] long) flags[;,)]' \ + halt='flags should be unsigned' \ + $(_sc_search_regexp) + # Avoid functions that can lead to double-close bugs. sc_prohibit_close: @prohibit='([^>.]|^)\<[fp]?close *\(' \ @@ -632,7 +651,7 @@ exclude_file_name_regexp--sc_avoid_write = \ exclude_file_name_regexp--sc_bindtextdomain = ^(tests|examples)/ -exclude_file_name_regexp--sc_flags_debug = ^docs/ +exclude_file_name_regexp--sc_flags_usage = ^docs/ exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics = \ ^src/rpc/gendispatch\.pl$$ diff --git a/src/fdstream.c b/src/fdstream.c index c9fe2f3..73545c7 100644 --- a/src/fdstream.c +++ b/src/fdstream.c @@ -505,7 +505,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, const char *path, unsigned long long offset, unsigned long long length, - int flags, + int oflags, int mode, bool delete) { @@ -516,13 +516,13 @@ virFDStreamOpenFileInternal(virStreamPtr st, int errfd = -1; pid_t pid = 0; - VIR_DEBUG("st=%p path=%s flags=%x offset=%llu length=%llu mode=%o delete=%d", - st, path, flags, offset, length, mode, delete); + VIR_DEBUG("st=%p path=%s oflags=%x offset=%llu length=%llu mode=%o delete=%d", + st, path, oflags, offset, length, mode, delete); - if (flags & O_CREAT) - fd = open(path, flags, mode); + if (oflags & O_CREAT) + fd = open(path, oflags, mode); else - fd = open(path, flags); + fd = open(path, oflags); if (fd < 0) { virReportSystemError(errno, _("Unable to open stream for '%s'"), @@ -547,7 +547,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, !S_ISFIFO(sb.st_mode))) { int childfd; - if ((flags & O_RDWR) == O_RDWR) { + if ((oflags & O_RDWR) == O_RDWR) { streamsReportError(VIR_ERR_INTERNAL_ERROR, _("%s: Cannot request read and write flags together"), path); @@ -564,7 +564,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, cmd = virCommandNewArgList(LIBEXECDIR "/libvirt_iohelper", path, NULL); - virCommandAddArgFormat(cmd, "%d", flags); + virCommandAddArgFormat(cmd, "%d", oflags); virCommandAddArgFormat(cmd, "%d", mode); virCommandAddArgFormat(cmd, "%llu", offset); virCommandAddArgFormat(cmd, "%llu", length); @@ -577,7 +577,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, */ delete = false; - if (flags == O_RDONLY) { + if (oflags == O_RDONLY) { childfd = fds[1]; fd = fds[0]; virCommandSetOutputFD(cmd, &childfd); @@ -626,10 +626,10 @@ int virFDStreamOpenFile(virStreamPtr st, const char *path, unsigned long long offset, unsigned long long length, - int flags, + int oflags, bool delete) { - if (flags & O_CREAT) { + if (oflags & O_CREAT) { streamsReportError(VIR_ERR_INTERNAL_ERROR, _("Attempt to create %s without specifying mode"), path); @@ -637,19 +637,19 @@ int virFDStreamOpenFile(virStreamPtr st, } return virFDStreamOpenFileInternal(st, path, offset, length, - flags, 0, delete); + oflags, 0, delete); } int virFDStreamCreateFile(virStreamPtr st, const char *path, unsigned long long offset, unsigned long long length, - int flags, + int oflags, mode_t mode, bool delete) { return virFDStreamOpenFileInternal(st, path, offset, length, - flags | O_CREAT, + oflags | O_CREAT, mode, delete); } diff --git a/src/fdstream.h b/src/fdstream.h index a66902b..76f0cd0 100644 --- a/src/fdstream.h +++ b/src/fdstream.h @@ -1,7 +1,7 @@ /* * fdstream.h: generic streams impl for file descriptors * - * Copyright (C) 2009-2010 Red Hat, Inc. + * Copyright (C) 2009-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -37,13 +37,13 @@ int virFDStreamOpenFile(virStreamPtr st, const char *path, unsigned long long offset, unsigned long long length, - int flags, + int oflags, bool delete); int virFDStreamCreateFile(virStreamPtr st, const char *path, unsigned long long offset, unsigned long long length, - int flags, + int oflags, mode_t mode, bool delete); diff --git a/src/locking/lock_driver_nop.c b/src/locking/lock_driver_nop.c index 0dcd794..4f35afa 100644 --- a/src/locking/lock_driver_nop.c +++ b/src/locking/lock_driver_nop.c @@ -49,7 +49,7 @@ static int virLockManagerNopNew(virLockManagerPtr lock ATTRIBUTE_UNUSED, unsigned int type ATTRIBUTE_UNUSED, size_t nparams ATTRIBUTE_UNUSED, virLockManagerParamPtr params ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags_unused ATTRIBUTE_UNUSED) { return 0; } @@ -59,7 +59,7 @@ static int virLockManagerNopAddResource(virLockManagerPtr lock ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED, size_t nparams ATTRIBUTE_UNUSED, virLockManagerParamPtr params ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags_unused ATTRIBUTE_UNUSED) { return 0; @@ -68,7 +68,7 @@ static int virLockManagerNopAddResource(virLockManagerPtr lock ATTRIBUTE_UNUSED, static int virLockManagerNopAcquire(virLockManagerPtr lock ATTRIBUTE_UNUSED, const char *state ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED, + unsigned int flags_unused ATTRIBUTE_UNUSED, int *fd ATTRIBUTE_UNUSED) { return 0; @@ -76,7 +76,7 @@ static int virLockManagerNopAcquire(virLockManagerPtr lock ATTRIBUTE_UNUSED, static int virLockManagerNopRelease(virLockManagerPtr lock ATTRIBUTE_UNUSED, char **state, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags_unused ATTRIBUTE_UNUSED) { if (state) *state = NULL; @@ -86,7 +86,7 @@ static int virLockManagerNopRelease(virLockManagerPtr lock ATTRIBUTE_UNUSED, static int virLockManagerNopInquire(virLockManagerPtr lock ATTRIBUTE_UNUSED, char **state, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags_unused ATTRIBUTE_UNUSED) { if (state) *state = NULL; diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c index d27cf8f..f07f9d7 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -190,9 +190,10 @@ cleanup: return NULL; } #else /* !HAVE_DLFCN_H */ -virLockManagerPluginPtr virLockManagerPluginNew(const char *name ATTRIBUTE_UNUSED, - const char *configFile ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) +virLockManagerPluginPtr +virLockManagerPluginNew(const char *name ATTRIBUTE_UNUSED, + const char *configFile ATTRIBUTE_UNUSED, + unsigned int flags_unused ATTRIBUTE_UNUSED) { virLockError(VIR_ERR_INTERNAL_ERROR, "%s", _("this platform is missing dlopen")); diff --git a/src/util/command.c b/src/util/command.c index 6c19cd1..8b01bcb 100644 --- a/src/util/command.c +++ b/src/util/command.c @@ -617,7 +617,7 @@ virExecWithHook(const char *const*argv ATTRIBUTE_UNUSED, int infd ATTRIBUTE_UNUSED, int *outfd ATTRIBUTE_UNUSED, int *errfd ATTRIBUTE_UNUSED, - int flags ATTRIBUTE_UNUSED, + int flags_unused ATTRIBUTE_UNUSED, virExecHook hook ATTRIBUTE_UNUSED, void *data ATTRIBUTE_UNUSED, char *pidfile ATTRIBUTE_UNUSED) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index f519d5a..0368eba 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -43,7 +43,7 @@ #define VIR_FROM_THIS VIR_FROM_STORAGE static int runIO(const char *path, - int flags, + int oflags, int mode, unsigned long long offset, unsigned long long length) @@ -56,10 +56,10 @@ static int runIO(const char *path, const char *fdinname, *fdoutname; unsigned long long total = 0; - if (flags & O_CREAT) { - fd = open(path, flags, mode); + if (oflags & O_CREAT) { + fd = open(path, oflags, mode); } else { - fd = open(path, flags); + fd = open(path, oflags); } if (fd < 0) { virReportSystemError(errno, _("Unable to open %s"), path); @@ -79,7 +79,7 @@ static int runIO(const char *path, goto cleanup; } - switch (flags & O_ACCMODE) { + switch (oflags & O_ACCMODE) { case O_RDONLY: fdin = fd; fdinname = path; @@ -97,7 +97,7 @@ static int runIO(const char *path, default: virReportSystemError(EINVAL, _("Unable to process file with flags %d"), - (flags & O_ACCMODE)); + (oflags & O_ACCMODE)); goto cleanup; } @@ -144,7 +144,7 @@ int main(int argc, char **argv) virErrorPtr err; unsigned long long offset; unsigned long long length; - int flags; + int oflags; int mode; unsigned int delete; @@ -169,7 +169,7 @@ int main(int argc, char **argv) path = argv[1]; - if (virStrToLong_i(argv[2], NULL, 10, &flags) < 0) { + if (virStrToLong_i(argv[2], NULL, 10, &oflags) < 0) { fprintf(stderr, _("%s: malformed file flags %s"), argv[0], argv[2]); exit(EXIT_FAILURE); } @@ -192,7 +192,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - if (runIO(path, flags, mode, offset, length) < 0) + if (runIO(path, oflags, mode, offset, length) < 0) goto error; if (delete) diff --git a/src/util/util.c b/src/util/util.c index 2165f26..4bd37ad 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -252,14 +252,14 @@ virArgvToString(const char *const *argv) #ifndef WIN32 int virSetInherit(int fd, bool inherit) { - int flags; - if ((flags = fcntl(fd, F_GETFD)) < 0) + int fflags; + if ((fflags = fcntl(fd, F_GETFD)) < 0) return -1; if (inherit) - flags &= ~FD_CLOEXEC; + fflags &= ~FD_CLOEXEC; else - flags |= FD_CLOEXEC; - if ((fcntl(fd, F_SETFD, flags)) < 0) + fflags |= FD_CLOEXEC; + if ((fcntl(fd, F_SETFD, fflags)) < 0) return -1; return 0; } @@ -997,7 +997,7 @@ int virFileOpenAs(const char *path ATTRIBUTE_UNUSED, mode_t mode ATTRIBUTE_UNUSED, uid_t uid ATTRIBUTE_UNUSED, gid_t gid ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags_unused ATTRIBUTE_UNUSED) { virUtilError(VIR_ERR_INTERNAL_ERROR, "%s", _("virFileOpenAs is not implemented for WIN32")); @@ -1009,7 +1009,7 @@ int virDirCreate(const char *path ATTRIBUTE_UNUSED, mode_t mode ATTRIBUTE_UNUSED, uid_t uid ATTRIBUTE_UNUSED, gid_t gid ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags_unused ATTRIBUTE_UNUSED) { virUtilError(VIR_ERR_INTERNAL_ERROR, "%s", _("virDirCreate is not implemented for WIN32")); -- 1.7.4.4

2011/7/8 Eric Blake <eblake@redhat.com>:
Enforce the recent flags cleanups - we want to use 'unsigned int flags' in any of our APIs (except where backwards compatibility is important, in the public migration APIs), and that all flags are checked for validity (except when there are stub functions that completely ignore the flags argument).
There are a few minor tweaks done here to avoid false positives: signed arguments passed to open() are renamed oflags, and flags arguments that are legitimately ignored are renamed flags_unused.
* cfg.mk (sc_flags_usage): New rule. (exclude_file_name_regexp--sc_flags_usage): And a few exemptions. * src/util/iohelper.c (runIO, main): Rename variable. * src/util/util.c (virSetInherit): Likewise. * src/fdstream.h (virFDStreamOpenFile, virFDStreamCreateFile): Likewise. * src/fdstream.c (virFDStreamOpenFileInternal) (virFDStreamOpenFile, virFDStreamCreateFile): Likewise. * src/util/command.c (virExecWithHook) [WIN32]: Likewise. * src/util/util.c (virFileOpenAs, virDirCreate) [WIN32]: Likewise. * src/locking/lock_manager.c (virLockManagerPluginNew) [!HAVE_DLFCN_H]: Likewise. * src/locking/lock_driver_nop.c (virLockManagerNopNew) (virLockManagerNopAddResource, virLockManagerNopAcquire) (virLockManagerNopRelease, virLockManagerNopInquire): Likewise. --- cfg.mk | 21 ++++++++++++++++++++- src/fdstream.c | 28 ++++++++++++++-------------- src/fdstream.h | 6 +++--- src/locking/lock_driver_nop.c | 10 +++++----- src/locking/lock_manager.c | 7 ++++--- src/util/command.c | 2 +- src/util/iohelper.c | 18 +++++++++--------- src/util/util.c | 14 +++++++------- 8 files changed, 63 insertions(+), 43 deletions(-)
@@ -516,13 +516,13 @@ virFDStreamOpenFileInternal(virStreamPtr st, int errfd = -1; pid_t pid = 0;
- VIR_DEBUG("st=%p path=%s flags=%x offset=%llu length=%llu mode=%o delete=%d", - st, path, flags, offset, length, mode, delete); + VIR_DEBUG("st=%p path=%s oflags=%x offset=%llu length=%llu mode=%o delete=%d", + st, path, oflags, offset, length, mode, delete);
In 02/27 you added a syntax-check rule to enforce flags=%x. Does this automatically cover oflags too, or does this need a change in the rule?
@@ -564,7 +564,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, cmd = virCommandNewArgList(LIBEXECDIR "/libvirt_iohelper", path, NULL); - virCommandAddArgFormat(cmd, "%d", flags); + virCommandAddArgFormat(cmd, "%d", oflags);
In 02/27 you changed the printing of flags from %d to %x in debug output. Maybe we should do that here too for consistence and adapt libvirt_iohelper? Or is there any possibility for a version mismatch between libvirt and libvirt_iohelper and we cannot change this anymore without breaking backwards compatibility?
virCommandAddArgFormat(cmd, "%d", mode);
Same comment applies here about mode and switching from %d to %o. ACK. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 07:35 AM, Matthias Bolte wrote:
@@ -516,13 +516,13 @@ virFDStreamOpenFileInternal(virStreamPtr st, int errfd = -1; pid_t pid = 0;
- VIR_DEBUG("st=%p path=%s flags=%x offset=%llu length=%llu mode=%o delete=%d", - st, path, flags, offset, length, mode, delete); + VIR_DEBUG("st=%p path=%s oflags=%x offset=%llu length=%llu mode=%o delete=%d", + st, path, oflags, offset, length, mode, delete);
In 02/27 you added a syntax-check rule to enforce flags=%x. Does this automatically cover oflags too, or does this need a change in the rule?
Hmm, as committed in 2/27, it checked '\<flags=%...'. If we remove the \< then it would also cover oflags, and that's probably a good change to make. I'll do it, and see what fallout it causes.
@@ -564,7 +564,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, cmd = virCommandNewArgList(LIBEXECDIR "/libvirt_iohelper", path, NULL); - virCommandAddArgFormat(cmd, "%d", flags); + virCommandAddArgFormat(cmd, "%d", oflags);
In 02/27 you changed the printing of flags from %d to %x in debug output. Maybe we should do that here too for consistence and adapt libvirt_iohelper? Or is there any possibility for a version mismatch between libvirt and libvirt_iohelper and we cannot change this anymore without breaking backwards compatibility?
I thought about this (independently, because I'm working on an O_DIRECT patch for iohelper), and my conclusion was that normally libvirtd and libvirt_iohelper are installed at the same time. However, there is indeed a window where: Older libvirtd is running, and you install the newer executables. Then the older libvirtd calls out to libvirt_iohelper, and executes the new one. That is, if you install a new libvirtd package, but don't restart the libvirtd daemon, then the new libvirt_iohelper must understand the syntax that will be handed it by the older still-running libvirtd. Therefore, my conclusion is that we can't change any existing command lines, but can only add new ones. Adding new could include using "0x" or "0" prefixes (the old code output decimal, so it is distinguishable, and the new iohelper command line would then be that much easier to understand if you browse /proc/nnn/ to learn the command line that iohelper is using).
virCommandAddArgFormat(cmd, "%d", mode);
Same comment applies here about mode and switching from %d to %o.
I'll look into that, as a separate patch.
ACK.
I already have to post a v2, so we'll get another round of review on this commit as well as the couple of fallout suggestions raised here. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 07/13/2011 09:23 AM, Eric Blake wrote:
Therefore, my conclusion is that we can't change any existing command lines, but can only add new ones. Adding new could include using "0x" or "0" prefixes (the old code output decimal, so it is distinguishable, and the new iohelper command line would then be that much easier to understand if you browse /proc/nnn/ to learn the command line that iohelper is using).
virCommandAddArgFormat(cmd, "%d", mode);
Same comment applies here about mode and switching from %d to %o.
I'll look into that, as a separate patch.
I ended up deleting that line instead: https://www.redhat.com/archives/libvir-list/2011-July/msg00837.html -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 07/08/2011 01:26 PM, Eric Blake wrote:
Enforce the recent flags cleanups - we want to use 'unsigned int flags' in any of our APIs (except where backwards compatibility is important, in the public migration APIs), and that all flags are checked for validity (except when there are stub functions that completely ignore the flags argument).
There are a few minor tweaks done here to avoid false positives: signed arguments passed to open() are renamed oflags, and flags arguments that are legitimately ignored are renamed flags_unused.
* cfg.mk (sc_flags_usage): New rule. (exclude_file_name_regexp--sc_flags_usage): And a few exemptions.
+sc_flags_usage: + @test "$$(grep -c 'long flags' \ + $(srcdir)/include/libvirt/libvirt.h.in)" != 4 && \ + { echo '$(ME): new API should use "unsigned int flags"' 1>&2; \ + exit 1; } || :
As mentioned in 4/27, this doesn't cover all public APIs. I'm thinking of squashing this in (I'll post a full v2 once I actually rebase it on top of all ACK'd posts, but will start the review now): diff --git i/cfg.mk w/cfg.mk index 4ab5752..2e177ff 100644 --- i/cfg.mk +++ w/cfg.mk @@ -280,14 +280,17 @@ sc_flags_debug: # Prefer 'unsigned int flags', along with checks for unknown flags. # For historical reasons, we are stuck with 'unsigned long flags' in -# migration and in a few other places. -# Three tests in this check: a fixed number of non-int flags in public -# API, no flags marked unused, and 'unsigned' should appear before any -# declaration of a flags variable (hence the prohibit line of [^d]). -# The existence of long long makes the third test slightly harder. +# migration, so check for those known 4 instances and no more in public +# API. Also check that no flags are marked unused, and 'unsigned' should +# appear before any declaration of a flags variable (acheived by +# prohibiting the word prior to the type from ending in anything other +# than d). The existence of long long, and of documentation about +# flags, makes the regex in the third test slightly harder. sc_flags_usage: - @test "$$(grep -c 'long flags' \ - $(srcdir)/include/libvirt/libvirt.h.in)" != 4 && \ + @test "$$(cat $(srcdir)/include/libvirt/libvirt.h.in \ + $(srcdir)/include/libvirt/virterror.h \ + $(srcdir)/include/libvirt/libvirt-qemu.h \ + | grep -c '\(long\|unsigned\) flags')" != 4 && \ { echo '$(ME): new API should use "unsigned int flags"' 1>&2; \ exit 1; } || : @prohibit=' flags ''ATTRIBUTE_UNUSED' \ -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

The compiler might optimize based on our declaration that something is unused. Putting that declaration in the header risks getting out of sync with the actual implementation, so it belongs better only in the .c files. We were mostly compliant, and a new syntax check will help us in the future. * cfg.mk (sc_avoic_attribute_unused_in_header): New syntax check. * src/nodeinfo.h (nodeGetCPUStats, nodeGetMemoryStats): Delete attribute already present in .c file. * src/qemu/qemu_domain.h (qemuDomainEventFlush): Likewise. * src/util/virterror_internal.h (virReportErrorHelper): Parameters are actually used by .c file. * src/xenxs/xen_sxpr.h (xenFormatSxprDisk): Adjust prototype. * src/xenxs/xen_sxpr.c (xenFormatSxprDisk): Delete unused argument. (xenFormatSxpr): Adjust caller. * src/xen/xend_internal.c (xenDaemonAttachDeviceFlags) (xenDaemonUpdateDeviceFlags): Likewise. Suggested by Daniel Veillard. --- As suggested here: https://www.redhat.com/archives/libvir-list/2011-July/msg00501.html cfg.mk | 8 ++++++++ src/nodeinfo.h | 4 ++-- src/qemu/qemu_domain.h | 2 +- src/util/virterror_internal.h | 8 ++++---- src/xen/xend_internal.c | 12 +++++------- src/xenxs/xen_sxpr.c | 5 ++--- src/xenxs/xen_sxpr.h | 3 +-- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/cfg.mk b/cfg.mk index a9ee9ea..ffecc50 100644 --- a/cfg.mk +++ b/cfg.mk @@ -432,6 +432,14 @@ sc_prohibit_xmlGetProp: halt='use virXMLPropString, not xmlGetProp' \ $(_sc_search_regexp) +# ATTRIBUTE_UNUSED should only be applied in implementations, not +# header declarations +sc_avoid_attribute_unused_in_header: + @prohibit='^[^#]*ATTRIBUTE_UNUSED([^:]|$$)' \ + in_vc_files='\.h$$' \ + halt='use ATTRIBUTE_UNUSED in .c rather than .h files' \ + $(_sc_search_regexp) + # Many of the function names below came from this filter: # git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$' \ # |sed 's/.*\.c- *//'|perl -pe 's/ ?\(.*//'|sort -u \ diff --git a/src/nodeinfo.h b/src/nodeinfo.h index e5ac1e0..4766152 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -30,12 +30,12 @@ int nodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo); int nodeCapsInitNUMA(virCapsPtr caps); -int nodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED, +int nodeGetCPUStats(virConnectPtr conn, int cpuNum, virNodeCPUStatsPtr params, int *nparams, unsigned int flags); -int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, +int nodeGetMemoryStats(virConnectPtr conn, int cellNum, virNodeMemoryStatsPtr params, int *nparams, diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 794eef7..ba3afc5 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -101,7 +101,7 @@ struct qemuDomainWatchdogEvent int action; }; -void qemuDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque); +void qemuDomainEventFlush(int timer, void *opaque); /* driver must be locked before calling */ void qemuDomainEventQueue(struct qemud_driver *driver, diff --git a/src/util/virterror_internal.h b/src/util/virterror_internal.h index df4b1d2..d61ea0d 100644 --- a/src/util/virterror_internal.h +++ b/src/util/virterror_internal.h @@ -1,7 +1,7 @@ /* * virterror.h: internal error handling * - * Copyright (C) 2006-2009 Red Hat, Inc. + * Copyright (C) 2006-2009, 2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -56,9 +56,9 @@ void virRaiseErrorFull(const char *filename, const char *virErrorMsg(virErrorNumber error, const char *info); void virReportErrorHelper(int domcode, int errcode, - const char *filename ATTRIBUTE_UNUSED, - const char *funcname ATTRIBUTE_UNUSED, - size_t linenr ATTRIBUTE_UNUSED, + const char *filename, + const char *funcname, + size_t linenr, const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7); diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 17be97e..0cb36bb 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -2726,11 +2726,10 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml, switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: - if (xenFormatSxprDisk(domain->conn, - dev->data.disk, - &buf, - STREQ(def->os.type, "hvm") ? 1 : 0, - priv->xendConfigVersion, 1) < 0) + if (xenFormatSxprDisk(dev->data.disk, + &buf, + STREQ(def->os.type, "hvm") ? 1 : 0, + priv->xendConfigVersion, 1) < 0) goto cleanup; if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) { @@ -2896,8 +2895,7 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml, switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: - if (xenFormatSxprDisk(domain->conn, - dev->data.disk, + if (xenFormatSxprDisk(dev->data.disk, &buf, STREQ(def->os.type, "hvm") ? 1 : 0, priv->xendConfigVersion, 1) < 0) diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 13ca015..0b0267c 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -1605,8 +1605,7 @@ xenFormatSxprChr(virDomainChrDefPtr def, * Returns 0 in case of success, -1 in case of error. */ int -xenFormatSxprDisk(virConnectPtr conn ATTRIBUTE_UNUSED, - virDomainDiskDefPtr def, +xenFormatSxprDisk(virDomainDiskDefPtr def, virBufferPtr buf, int hvm, int xendConfigVersion, @@ -2264,7 +2263,7 @@ xenFormatSxpr(virConnectPtr conn, } for (i = 0 ; i < def->ndisks ; i++) - if (xenFormatSxprDisk(conn, def->disks[i], + if (xenFormatSxprDisk(def->disks[i], &buf, hvm, xendConfigVersion, 0) < 0) goto error; diff --git a/src/xenxs/xen_sxpr.h b/src/xenxs/xen_sxpr.h index b2f8790..a66c60a 100644 --- a/src/xenxs/xen_sxpr.h +++ b/src/xenxs/xen_sxpr.h @@ -46,8 +46,7 @@ int xenParseSxprSound(virDomainDefPtr def, const char *str); virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty); -int xenFormatSxprDisk(virConnectPtr conn ATTRIBUTE_UNUSED, - virDomainDiskDefPtr def, virBufferPtr buf, int hvm, +int xenFormatSxprDisk(virDomainDiskDefPtr def, virBufferPtr buf, int hvm, int xendConfigVersion, int isAttach); int xenFormatSxprNet(virConnectPtr conn, -- 1.7.4.4

2011/7/9 Eric Blake <eblake@redhat.com>:
The compiler might optimize based on our declaration that something is unused.
Can this actually happen? The unused marker only says that something _might_ be unused. I don't think that a compiler can optimize something based on this when it cannot actually prove that it is really unused.
Putting that declaration in the header risks getting out of sync with the actual implementation, so it belongs better only in the .c files. We were mostly compliant, and a new syntax check will help us in the future.
This is a valid point.
* cfg.mk (sc_avoic_attribute_unused_in_header): New syntax check. * src/nodeinfo.h (nodeGetCPUStats, nodeGetMemoryStats): Delete attribute already present in .c file. * src/qemu/qemu_domain.h (qemuDomainEventFlush): Likewise. * src/util/virterror_internal.h (virReportErrorHelper): Parameters are actually used by .c file. * src/xenxs/xen_sxpr.h (xenFormatSxprDisk): Adjust prototype. * src/xenxs/xen_sxpr.c (xenFormatSxprDisk): Delete unused argument. (xenFormatSxpr): Adjust caller. * src/xen/xend_internal.c (xenDaemonAttachDeviceFlags) (xenDaemonUpdateDeviceFlags): Likewise. Suggested by Daniel Veillard. ---
As suggested here: https://www.redhat.com/archives/libvir-list/2011-July/msg00501.html
cfg.mk | 8 ++++++++ src/nodeinfo.h | 4 ++-- src/qemu/qemu_domain.h | 2 +- src/util/virterror_internal.h | 8 ++++---- src/xen/xend_internal.c | 12 +++++------- src/xenxs/xen_sxpr.c | 5 ++--- src/xenxs/xen_sxpr.h | 3 +-- 7 files changed, 23 insertions(+), 19 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

On 07/13/2011 07:42 AM, Matthias Bolte wrote:
2011/7/9 Eric Blake <eblake@redhat.com>:
The compiler might optimize based on our declaration that something is unused.
Can this actually happen? The unused marker only says that something _might_ be unused. I don't think that a compiler can optimize something based on this when it cannot actually prove that it is really unused.
Hmm, given gcc's documentation that it is a 'might' be unused, then yeah, gcc shouldn't do premature optimizations on the caller side. But better safe than sorry.
Putting that declaration in the header risks getting out of sync with the actual implementation, so it belongs better only in the .c files. We were mostly compliant, and a new syntax check will help us in the future.
This is a valid point.
Consistency is a good argument, even if the argument for (lack of) compiler optimizations is weak in this case :)
ACK.
I've now applied 25, 26, and 28. Expect a v3 later today which fixes the fallout comments on the remaining patches. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Matthias Bolte