libvirt/src/util
Daniel P. Berrange 633b699bfd iohelper: avoid calling read() with misaligned buffers for O_DIRECT
The iohelper currently calls saferead() to get data from the
underlying file. This has a problem with O_DIRECT when hitting
end-of-file. saferead() is asked to read 1MB, but the first
read() it does may return only a few KB, so it'll try another
read() to fill the remaining buffer. Unfortunately the buffer
pointer passed into this 2nd read() is likely not aligned
to the extent that O_DIRECT requires, so rather than seeing
'0' for end-of-file, we'll get -1 + EINVAL due to misaligned
buffer.

The way the iohelper is currently written, it already handles
getting short reads, so there is actually no need to use
saferead() at all. We can simply call read() directly. The
benefit of this is that we can now write() the data immediately
so when we go into the subsequent reads() we'll always have a
correctly aligned buffer.

Technically the file position ought to be aligned for O_DIRECT
too, but this does not appear to matter when at end-of-file.

Tested-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-09-21 08:52:13 +01:00
..
iohelper.c iohelper: avoid calling read() with misaligned buffers for O_DIRECT 2017-09-21 08:52:13 +01:00
viralloc.c Use explicit boolean comparison in OOM check 2017-02-23 10:11:16 +00:00
viralloc.h util: Remove need for STATIC_ANALYSIS check 2016-05-19 16:30:04 -04:00
virarch.c
virarch.h
viratomic.c
viratomic.h
viraudit.c
viraudit.h
virauth.c
virauth.h
virauthconfig.c util: Fix broken syntax-check 2016-06-16 06:17:58 -04:00
virauthconfig.h
virbitmap.c util: Use virBufferCheckError to its full potential. 2017-08-29 11:17:16 +02:00
virbitmap.h util: bitmap: Modify virBitmapSubtract to virBitmapIntersect 2017-07-20 16:14:50 +02:00
virbuffer.c util: buffer: Add virBufferStrcatVArgs 2017-07-27 09:31:14 +02:00
virbuffer.h util: Umark virBufferCheckErrorInternal as ATTRIBUTE_RETURN_CHECK 2017-08-29 11:17:16 +02:00
vircgroup.c virCgroupValidateMachineGroup: Don't free @machinename 2017-08-01 11:37:51 +02:00
vircgroup.h Move machineName generation from virsystemd into domain_conf 2017-07-25 17:02:27 +02:00
vircgrouppriv.h
virclosecallbacks.c util: Fix domain object leaks on closecallbacks 2017-02-03 19:38:39 -05:00
virclosecallbacks.h Disallow inclusion of files from src/conf into src/utils 2017-02-20 15:12:07 +01:00
vircommand.c util: share code between virExec and virCommandExec 2017-07-11 10:41:24 +02:00
vircommand.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
vircommandpriv.h
virconf.c introduce virConfReadString 2017-08-08 12:19:17 +02:00
virconf.h introduce virConfReadString 2017-08-08 12:19:17 +02:00
vircrypto.c Fix padding of encrypted data 2017-05-02 17:27:13 +01:00
vircrypto.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virdbus.c Fix typos and grammar 2016-11-23 12:08:15 -05:00
virdbus.h
virdbuspriv.h
virdnsmasq.c dnsmasq: disable IPv6 default gateway in RA for isolated networks 2016-07-13 13:49:03 +03:00
virdnsmasq.h dnsmasq: disable IPv6 default gateway in RA for isolated networks 2016-07-13 13:49:03 +03:00
virebtables.c
virebtables.h
virendian.h util: Introduce virReadBufInt16LE and virReadBufInt16BE 2016-06-24 13:23:02 -04:00
virerror.c util: error: Add helpers for saving and restoring of last error 2017-09-15 05:28:21 +02:00
virerror.h util: error: Add helpers for saving and restoring of last error 2017-09-15 05:28:21 +02:00
virevent.c event: ignore attempts to replace the event loop impl 2017-09-04 13:06:24 +01:00
virevent.h
vireventpoll.c util: remove redundant comments 2016-06-16 13:09:19 -04:00
vireventpoll.h THREADS.txt: fix typos 2017-01-25 09:18:49 +01:00
virfcp.c util: fix virfcp build on non-Linux 2017-05-26 20:00:51 +04:00
virfcp.h util: helper functions for fibre channel devices 2017-05-26 10:44:05 -04:00
virfdstream.c fdstream: Report error from the I/O thread 2017-07-11 08:41:01 +02:00
virfdstream.h fdstream: Implement sparse stream 2017-05-18 07:42:13 +02:00
virfile.c iohelper: drop unused operation length limit 2017-09-19 11:37:15 +02:00
virfile.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virfilecache.c util: introduce virFileCache 2017-07-26 15:31:25 +02:00
virfilecache.h util: introduce virFileCache 2017-07-26 15:31:25 +02:00
virfirewall.c util: Turn virFirewallAddRule() into a macro 2017-01-04 11:14:56 +01:00
virfirewall.h util: Fix syntax-check 2017-01-04 12:47:01 +01:00
virfirewallpriv.h
virfirmware.c virstring: Unify string list function names 2016-11-25 13:54:05 +01:00
virfirmware.h driver config: Introduce virFirmware object 2016-06-13 14:13:16 -06:00
virgettext.c util: Add virGettextInitialize, convert the code 2016-04-14 13:22:40 -04:00
virgettext.h util: Add virGettextInitialize, convert the code 2016-04-14 13:22:40 -04:00
virgic.c
virgic.h gic: Remove VIR_GIC_VERSION_DEFAULT 2017-05-16 16:48:30 +02:00
virhash.c util/virhash: add name parameter to virHashSearch 2017-07-20 14:02:14 +02:00
virhash.h util: hash: Include stdbool.h in the header file 2017-08-03 09:49:15 +02:00
virhashcode.c Use ATTRIBUTE_FALLTHROUGH 2017-06-12 19:11:30 -04:00
virhashcode.h util: hash: Make virHashCodeGen mockable 2017-08-03 09:49:15 +02:00
virhook.c libxl: add hooks support 2016-08-02 14:20:31 +02:00
virhook.h libxl: add hooks support 2016-08-02 14:20:31 +02:00
virhostcpu.c util: hostcpu: Correctly report total number of vcpus in virHostCPUGetMap 2017-05-30 10:42:28 +02:00
virhostcpu.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virhostcpupriv.h util: Adapt virhostcpu to the new virsysfs 2017-03-27 13:13:29 +02:00
virhostdev.c util: fix improper assignment of return value in virHostdevReadNetConfig() 2017-08-13 23:07:13 -04:00
virhostdev.h util: Remove NONNULL from virHostdevReAttachMediatedDevices 2017-03-27 12:41:24 -04:00
virhostmem.c lib: Fix c99 style comments 2017-04-27 14:13:19 +02:00
virhostmem.h nodeinfo: move host memory APIs out into virhostmem file 2016-06-09 18:43:18 +01:00
viridentity.c src: Treat PID as signed 2016-10-13 17:58:56 +08:00
viridentity.h
virinitctl.c
virinitctl.h
viriptables.c Drop paths.h include 2016-03-18 09:43:45 +01:00
viriptables.h
viriscsi.c virISCSIGetSession: Don't leak memory 2017-04-05 15:18:30 +02:00
viriscsi.h util: Introduce virISCSINodeNew 2016-07-28 08:27:13 -04:00
virjson.c util: json: Recursively deflatten objects virJSONValueObjectDeflatten 2017-07-11 14:20:05 +02:00
virjson.h util: Move JSON object deflattening code to json utility file 2017-07-11 14:02:28 +02:00
virkeycode.c util: switch over to use keycodemapdb GIT submodule 2017-04-25 21:14:18 +01:00
virkeycode.h
virkeyfile.c
virkeyfile.h
virkmod.c
virkmod.h
virlease.c Don't drop expired lease while reading custom leases file 2016-10-05 08:33:59 +02:00
virlease.h Export virLease* functions for leases file handling 2016-03-18 17:29:53 +01:00
virlockspace.c
virlockspace.h
virlog.c daemon: logging: Fix --verbose option being ignored by the daemon 2017-08-28 16:42:13 +02:00
virlog.h admin: Allow passing NULL to virLogSetOutputs 2016-12-15 10:36:23 +01:00
virmacaddr.c util: make virMacAddrParse more versatile 2017-03-24 00:37:01 -04:00
virmacaddr.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virmacmap.c network: Move and rename networkMacMgrFileName 2017-08-16 14:17:57 -04:00
virmacmap.h network: Move and rename networkMacMgrFileName 2017-08-16 14:17:57 -04:00
virmdev.c mdev: Pass a uuidstr rather than an mdev object to some util functions 2017-05-18 12:20:15 +02:00
virmdev.h mdev: Pass a uuidstr rather than an mdev object to some util functions 2017-05-18 12:20:15 +02:00
virnetdev.c configure: fix check for DEVLINK_CMD_ESWITCH_GET 2017-09-19 15:25:10 +02:00
virnetdev.h nodedev: add switchdev to NIC capabilities 2017-09-18 08:32:24 -04:00
virnetdevbandwidth.c
virnetdevbandwidth.h util: Remove NONNULL(2) for virNetDevBandwidthPlug 2017-03-22 13:50:00 -04:00
virnetdevbridge.c util: netdevbridge: Refactor error handling in virNetDevBridgeCreate 2017-06-28 15:27:17 +02:00
virnetdevbridge.h
virnetdevip.c IPv6 route check: list devices only once 2017-04-26 18:59:24 +02:00
virnetdevip.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virnetdevmacvlan.c util: restructure virNetDevReadNetConfig() to eliminate false error logs 2017-08-11 19:09:49 -04:00
virnetdevmacvlan.h util: make macvtap/macvlan generated name #defines available to other files 2017-04-28 09:43:52 -04:00
virnetdevmidonet.c
virnetdevmidonet.h
virnetdevopenvswitch.c Handle hotplug change on VLAN configuration using OVS 2017-07-20 15:15:03 +02:00
virnetdevopenvswitch.h Handle hotplug change on VLAN configuration using OVS 2017-07-20 15:15:03 +02:00
virnetdevtap.c qemu: Allow live-updates of coalesce settings 2017-06-16 10:18:35 +02:00
virnetdevtap.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virnetdevveth.c
virnetdevveth.h
virnetdevvlan.c
virnetdevvlan.h
virnetdevvportprofile.c util: move virNetDevLinkDump to virnetlink.c 2016-06-26 19:33:07 -04:00
virnetdevvportprofile.h util: Remove NONNULL's for virNetDevVPortProfile[Associate|Disassociate] 2017-03-22 13:50:00 -04:00
virnetlink.c util: Do not leak @handles in stop netlink event service 2017-05-18 07:26:05 -04:00
virnetlink.h util: add virNetlinkDumpCommand() 2017-03-22 09:01:32 +01:00
virnodesuspend.c util: Fix naming in util/virnodesuspend 2017-03-27 13:13:29 +02:00
virnodesuspend.h util: Fix naming in util/virnodesuspend 2017-03-27 13:13:29 +02:00
virnuma.c numa: Rename virNumaGetHostNodeset and make it return only nodes with memory 2016-09-14 08:41:41 +02:00
virnuma.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virobject.c util: Add object checking for virObject{Ref|Unref} 2017-08-14 21:41:59 -04:00
virobject.h util: Introduce and use virObjectRWUnlock 2017-08-14 21:41:59 -04:00
virpci.c util: virPCIGetNetName(): use first netdev name when phys_port_id isn't matched 2017-09-19 20:41:21 -04:00
virpci.h util: save the correct VF's info when using a dual port SRIOV NIC in single port mode 2017-08-11 19:05:20 -04:00
virperf.c virPerfEventIsEnabled: Accept NULL @perf 2017-05-04 16:42:25 +02:00
virperf.h perf: add emulation_faults software perf event support 2017-03-07 13:51:05 -05:00
virpidfile.c
virpidfile.h
virpolkit.c virstring: Unify string list function names 2016-11-25 13:54:05 +01:00
virpolkit.h
virportallocator.c
virportallocator.h
virprobe.h
virprocess.c process: Translate "unlimited" correctly 2017-03-28 10:54:49 +02:00
virprocess.h lxc: Move lxcContainerAvailable to virprocess 2017-01-11 18:02:35 +01:00
virqemu.c Revert "util: virqemu: introduce virQEMUBuildBufferEscape" 2017-06-12 12:45:42 +02:00
virqemu.h Revert "util: virqemu: introduce virQEMUBuildBufferEscape" 2017-06-12 12:45:42 +02:00
virrandom.c util: Perform proper virRandomBytes return value checking 2016-06-07 10:18:36 -04:00
virrandom.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virresctrl.c util: Rename virResctrl to virResctrlInfo 2017-08-14 10:01:12 +02:00
virresctrl.h util: Rename virResctrl to virResctrlInfo 2017-08-14 10:01:12 +02:00
virrotatingfile.c util: Fix resource leak 2017-04-13 08:14:54 -04:00
virrotatingfile.h
virscsi.c util: Create a new virvhba module and move/rename API's 2017-02-19 06:45:09 -05:00
virscsi.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virscsihost.c util: Move scsi_host specific functions from virutil 2017-02-19 06:45:09 -05:00
virscsihost.h util: Move scsi_host specific functions from virutil 2017-02-19 06:45:09 -05:00
virscsivhost.c virscsivhost: Introduce virSCSIVHostDeviceGetPath 2016-12-15 09:25:16 +01:00
virscsivhost.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virseclabel.c
virseclabel.h
virsecret.c util: Introduce virSecretLookupFormatSecret 2016-06-23 12:30:28 -04:00
virsecret.h util: Introduce virSecretLookupFormatSecret 2016-06-23 12:30:28 -04:00
virsexpr.c
virsexpr.h
virsocketaddr.c util: fix memory leak in virSocketAddrFormatFull 2017-05-26 12:15:13 +02:00
virsocketaddr.h Remove network constants out of internal.h 2017-07-11 13:57:11 +01:00
virstorageencryption.c virStorageEncryptionSecretFree: Don't leak secret lookup definition 2016-07-11 14:21:01 +02:00
virstorageencryption.h storage: Fix capacity value for LUKS encrypted volumes 2017-04-03 16:15:29 -04:00
virstoragefile.c util: storage: Add JSON backing volume parse for VxHS 2017-09-19 21:10:21 -04:00
virstoragefile.h storage: Introduce VIR_STORAGE_NET_PROTOCOL_VXHS 2017-09-19 21:10:21 -04:00
virstring.c util: string: Introduce virStringHasChars 2017-08-18 14:20:37 +02:00
virstring.h util: string: Introduce virStringHasChars 2017-08-18 14:20:37 +02:00
virsysinfo.c src: fix multiple resource leaks in loops 2017-04-11 13:23:00 +02:00
virsysinfo.h
virsysinfopriv.h tests: sysinfo: Export virSysinfoSetup via the private header 2017-03-07 10:44:26 +01:00
virsystemd.c Move machineName generation from virsystemd into domain_conf 2017-07-25 17:02:27 +02:00
virsystemd.h Move machineName generation from virsystemd into domain_conf 2017-07-25 17:02:27 +02:00
virsystemdpriv.h Cache the presence of machine1 service 2017-03-06 15:44:33 +01:00
virthread.c Revert "virthread: Introduce virRWLockInitPreferWriter" 2017-07-25 10:56:03 +02:00
virthread.h Revert "virthread: Introduce virRWLockInitPreferWriter" 2017-07-25 10:56:03 +02:00
virthreadjob.c
virthreadjob.h
virthreadpool.c admin: Introduce virAdmServerSetThreadPoolParameters 2016-04-18 17:07:46 +02:00
virthreadpool.h admin: Introduce virAdmServerSetThreadPoolParameters 2016-04-18 17:07:46 +02:00
virtime.c virTimeBackOffWait: Avoid long periods of sleep 2017-03-16 09:21:39 +01:00
virtime.h Add functions for handling exponential backoff loops. 2016-04-15 16:54:28 +01:00
virtpm.c tpm: Use /dev/null for cancel path if none was found 2017-09-07 14:00:46 +02:00
virtpm.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virtypedparam.c Fix typos and grammar 2016-11-23 12:08:15 -05:00
virtypedparam.h util: Remove NONNULL(1,3,4) from virTypedParamsFilter 2017-03-22 13:50:00 -04:00
viruri.c virstring: Unify string list function names 2016-11-25 13:54:05 +01:00
viruri.h util: uri: Convert port number to unsigned integer 2017-07-24 10:55:43 +02:00
virusb.c util: display leading zeros of USB vendor/product id's in log messages 2017-05-24 12:23:59 -04:00
virusb.h virusb: Introduce virUSBDeviceGetPath 2016-12-15 09:25:16 +01:00
virutil.c Remove network constants out of internal.h 2017-07-11 13:57:11 +01:00
virutil.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
viruuid.c util: factor out reading file into preallocated buffer 2016-05-03 08:58:30 -04:00
viruuid.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virvhba.c util: virvhba: fix typo that breaks build on non-linux systems 2017-02-19 15:47:27 +01:00
virvhba.h util: Create a new virvhba module and move/rename API's 2017-02-19 06:45:09 -05:00
virxdrdefs.h
virxml.c util: introduce virXMLFormatElement helper 2017-08-28 14:02:44 +02:00
virxml.h util: introduce virXMLFormatElement helper 2017-08-28 14:02:44 +02:00