xcp-1.6-updates/xen-4.1.hg

changeset 23297:35248be669e7

blktap2: Fix naked unchecked uses of read/write/chdir.

These cause warnings under warn_unused_result, and for read/write we
ought to deal with partial io results.

Signed-off-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 25299:01d64a3dea71
xen-unstable date: Fri May 11 18:30:29 2012 +0100


blktap2: Fix another uninitialised value error

gcc -O1 -fno-omit-frame-pointer -m32 -march=i686 -g
-fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wdeclaration-after-statement -D__XEN_TOOLS__ -MMD -MF
.block-remus.o.d -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -fno-optimize-sibling-calls
-mno-tls-direct-seg-refs -Werror -g -Wno-unused -fno-strict-aliasing
-I../include -I../drivers
-I/home/osstest/build.12828.build-i386/xen-unstable/tools/blktap2/drivers/../../../tools/libxc
-I/home/osstest/build.12828.build-i386/xen-unstable/tools/blktap2/drivers/../../../tools/include
-D_GNU_SOURCE -DUSE_NFS_LOCKS -c -o block-remus.o block-remus.c

block-remus.c: In function 'ramdisk_flush':
block-remus.c:508: error: 'buf' may be used uninitialized in this
function
make[5]: *** [block-remus.o] Error 1

This is because gcc can see that merge_requests doesn't always set
*mergedbuf but gcc isn't able to prove that it always does so if
merge_requests returns 0 and that in that case the value of
ramdisk_flush::buf isn't used.

This is too useful a warning to disable, despite the occasional false
positive of this form. The conventional approach is to suppress the
warning by explicitly initialising the variable to 0.

This has just come to light because 25275:27d63b9f111a reenabled
optimisation for this area of code, and gcc's data flow analysis
(which is required to trigger the uninitialised variable warning) only
occurs when optimisation is turned on.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
xen-unstable changeset: 25281:60064411a8a9
xen-unstable date: Thu May 10 14:26:14 2012 +0100


blktap2: Do not build with -O0

Signed-off-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 25275:27d63b9f111a
xen-unstable date: Thu May 10 11:22:18 2012 +0100


blktap2: Fix uninitialised value error.

Signed-off-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 25274:cb82b5aa73bd
xen-unstable date: Thu May 10 11:21:59 2012 +0100


tools/blktap2: fix out of bounds access in block-log.c

block-log.c: In function 'ctl_close_sock':
block-log.c:363:23: warning: array subscript is above array bounds
[-Warray-bounds]

Adjust loop condition in ctl_close_sock() to fix warning.
Adjust array acccess in ctl_close() to actually access the array
member.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 25273:83a02f225bde
xen-unstable date: Thu May 10 11:20:04 2012 +0100


tools/blktap2: fix build errors caused by Werror in
vhd_journal_write_entry

-O2 -Wall -Werror triggers these warnings:

libvhd-journal.c: In function 'vhd_journal_write_entry':
libvhd-journal.c:335: warning: statement with no effect

Really return the error from vhd_journal_write() to caller.

v2:
- simplify the patch by just adding the missing return statement

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Committed-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 25272:ca02580986d2
xen-unstable date: Thu May 10 11:19:05 2012 +0100
author Keir Fraser <keir@xen.org>
date Mon May 14 16:59:12 2012 +0100 (2012-05-14)
parents 89c61e66f45f
children 435493696053
files tools/blktap2/drivers/Makefile tools/blktap2/drivers/block-log.c tools/blktap2/drivers/block-qcow.c tools/blktap2/drivers/block-remus.c tools/blktap2/drivers/tapdisk-diff.c tools/blktap2/drivers/tapdisk-log.c tools/blktap2/drivers/tapdisk-queue.c tools/blktap2/drivers/tapdisk-stream.c tools/blktap2/drivers/tapdisk-utils.c tools/blktap2/drivers/tapdisk-utils.h tools/blktap2/drivers/tapdisk2.c tools/blktap2/vhd/lib/libvhd-journal.c
line diff
     1.1 --- a/tools/blktap2/drivers/Makefile	Mon May 14 16:51:27 2012 +0100
     1.2 +++ b/tools/blktap2/drivers/Makefile	Mon May 14 16:59:12 2012 +0100
     1.3 @@ -9,7 +9,7 @@ QCOW_UTIL  = img2qcow qcow-create qcow2r
     1.4  LOCK_UTIL  = lock-util
     1.5  INST_DIR   = $(SBINDIR)
     1.6  
     1.7 -CFLAGS    += -Werror -g -O0
     1.8 +CFLAGS    += -Werror -g
     1.9  CFLAGS    += -Wno-unused
    1.10  CFLAGS    += -fno-strict-aliasing
    1.11  CFLAGS    += -I$(BLKTAP_ROOT)/include -I$(BLKTAP_ROOT)/drivers
     2.1 --- a/tools/blktap2/drivers/block-log.c	Mon May 14 16:51:27 2012 +0100
     2.2 +++ b/tools/blktap2/drivers/block-log.c	Mon May 14 16:59:12 2012 +0100
     2.3 @@ -347,11 +347,11 @@ static int ctl_open(struct tdlog_state* 
     2.4  static int ctl_close(struct tdlog_state* s)
     2.5  {
     2.6    while (s->connected) {
     2.7 +    s->connected--;
     2.8      tapdisk_server_unregister_event(s->connections[s->connected].id);
     2.9      close(s->connections[s->connected].fd);
    2.10      s->connections[s->connected].fd = -1;
    2.11      s->connections[s->connected].id = 0;
    2.12 -    s->connected--;
    2.13    }
    2.14  
    2.15    if (s->ctl.fd >= 0) {
    2.16 @@ -382,7 +382,7 @@ static int ctl_close_sock(struct tdlog_s
    2.17  {
    2.18    int i;
    2.19  
    2.20 -  for (i = 0; i <= s->connected; i++) {
    2.21 +  for (i = 0; i < s->connected; i++) {
    2.22      if (s->connections[i].fd == fd) {
    2.23        tapdisk_server_unregister_event(s->connections[i].id);
    2.24        close(s->connections[i].fd);
     3.1 --- a/tools/blktap2/drivers/block-qcow.c	Mon May 14 16:51:27 2012 +0100
     3.2 +++ b/tools/blktap2/drivers/block-qcow.c	Mon May 14 16:59:12 2012 +0100
     3.3 @@ -1428,7 +1428,7 @@ int tdqcow_get_parent_id(td_driver_t *dr
     3.4  {
     3.5  	off_t off;
     3.6  	char *buf, *filename;
     3.7 -	int len, secs, type, err = -EINVAL;
     3.8 +	int len, secs, type = 0, err = -EINVAL;
     3.9  	struct tdqcow_state *child  = (struct tdqcow_state *)driver->data;
    3.10  
    3.11  	if (!child->backing_file_offset)
     4.1 --- a/tools/blktap2/drivers/block-remus.c	Mon May 14 16:51:27 2012 +0100
     4.2 +++ b/tools/blktap2/drivers/block-remus.c	Mon May 14 16:59:12 2012 +0100
     4.3 @@ -505,7 +505,7 @@ fail:
     4.4  static int ramdisk_flush(td_driver_t *driver, struct tdremus_state* s)
     4.5  {
     4.6  	uint64_t* sectors;
     4.7 -	char* buf;
     4.8 +	char* buf = NULL;
     4.9  	uint64_t base, batchlen;
    4.10  	int i, j, count = 0;
    4.11  
     5.1 --- a/tools/blktap2/drivers/tapdisk-diff.c	Mon May 14 16:51:27 2012 +0100
     5.2 +++ b/tools/blktap2/drivers/tapdisk-diff.c	Mon May 14 16:59:12 2012 +0100
     5.3 @@ -39,6 +39,7 @@
     5.4  #include "tapdisk-vbd.h"
     5.5  #include "tapdisk-server.h"
     5.6  #include "tapdisk-disktype.h"
     5.7 +#include "tapdisk-utils.h"
     5.8  #include "libvhd.h"
     5.9  
    5.10  #define POLL_READ                        0
    5.11 @@ -170,7 +171,7 @@ tapdisk_stream_poll_clear(struct tapdisk
    5.12  {
    5.13  	int dummy;
    5.14  
    5.15 -	read(p->pipe[POLL_READ], &dummy, sizeof(dummy));
    5.16 +	read_exact(p->pipe[POLL_READ], &dummy, sizeof(dummy));
    5.17  	p->set = 0;
    5.18  }
    5.19  
    5.20 @@ -180,7 +181,7 @@ tapdisk_stream_poll_set(struct tapdisk_s
    5.21  	int dummy = 0;
    5.22  
    5.23  	if (!p->set) {
    5.24 -		write(p->pipe[POLL_WRITE], &dummy, sizeof(dummy));
    5.25 +		write_exact(p->pipe[POLL_WRITE], &dummy, sizeof(dummy));
    5.26  		p->set = 1;
    5.27  	}
    5.28  }
     6.1 --- a/tools/blktap2/drivers/tapdisk-log.c	Mon May 14 16:51:27 2012 +0100
     6.2 +++ b/tools/blktap2/drivers/tapdisk-log.c	Mon May 14 16:59:12 2012 +0100
     6.3 @@ -37,6 +37,7 @@
     6.4  #include <sys/time.h>
     6.5  
     6.6  #include "tapdisk-log.h"
     6.7 +#include "tapdisk-utils.h"
     6.8  
     6.9  #define MAX_ENTRY_LEN      512
    6.10  #define MAX_ERROR_MESSAGES 16
    6.11 @@ -247,7 +248,7 @@ tlog_flush(void)
    6.12  	wsize = ((size + 511) & (~511));
    6.13  
    6.14  	memset(tapdisk_log.buf + size, '\n', wsize - size);
    6.15 -	write(fd, tapdisk_log.buf, wsize);
    6.16 +	write_exact(fd, tapdisk_log.buf, wsize);
    6.17  
    6.18  	tapdisk_log.p = tapdisk_log.buf;
    6.19  
     7.1 --- a/tools/blktap2/drivers/tapdisk-queue.c	Mon May 14 16:51:27 2012 +0100
     7.2 +++ b/tools/blktap2/drivers/tapdisk-queue.c	Mon May 14 16:59:12 2012 +0100
     7.3 @@ -435,7 +435,7 @@ tapdisk_lio_ack_event(struct tqueue *que
     7.4  	uint64_t val;
     7.5  
     7.6  	if (lio->flags & LIO_FLAG_EVENTFD)
     7.7 -		read(lio->event_fd, &val, sizeof(val));
     7.8 +		read_exact(lio->event_fd, &val, sizeof(val));
     7.9  }
    7.10  
    7.11  static void
     8.1 --- a/tools/blktap2/drivers/tapdisk-stream.c	Mon May 14 16:51:27 2012 +0100
     8.2 +++ b/tools/blktap2/drivers/tapdisk-stream.c	Mon May 14 16:59:12 2012 +0100
     8.3 @@ -38,6 +38,7 @@
     8.4  #include "tapdisk-vbd.h"
     8.5  #include "tapdisk-server.h"
     8.6  #include "tapdisk-disktype.h"
     8.7 +#include "tapdisk-utils.h"
     8.8  
     8.9  #define POLL_READ                        0
    8.10  #define POLL_WRITE                       1
    8.11 @@ -145,7 +146,7 @@ tapdisk_stream_poll_clear(struct tapdisk
    8.12  {
    8.13  	int dummy;
    8.14  
    8.15 -	read(p->pipe[POLL_READ], &dummy, sizeof(dummy));
    8.16 +	read_exact(p->pipe[POLL_READ], &dummy, sizeof(dummy));
    8.17  	p->set = 0;
    8.18  }
    8.19  
    8.20 @@ -155,7 +156,7 @@ tapdisk_stream_poll_set(struct tapdisk_s
    8.21  	int dummy = 0;
    8.22  
    8.23  	if (!p->set) {
    8.24 -		write(p->pipe[POLL_WRITE], &dummy, sizeof(dummy));
    8.25 +		write_exact(p->pipe[POLL_WRITE], &dummy, sizeof(dummy));
    8.26  		p->set = 1;
    8.27  	}
    8.28  }
    8.29 @@ -203,7 +204,7 @@ tapdisk_stream_print_request(struct tapd
    8.30  {
    8.31  	unsigned long idx = (unsigned long)tapdisk_stream_request_idx(s, sreq);
    8.32  	char *buf = (char *)MMAP_VADDR(s->vbd->ring.vstart, idx, 0);
    8.33 -	write(s->out_fd, buf, sreq->secs << SECTOR_SHIFT);
    8.34 +	write_exact(s->out_fd, buf, sreq->secs << SECTOR_SHIFT);
    8.35  }
    8.36  
    8.37  static void
     9.1 --- a/tools/blktap2/drivers/tapdisk-utils.c	Mon May 14 16:51:27 2012 +0100
     9.2 +++ b/tools/blktap2/drivers/tapdisk-utils.c	Mon May 14 16:59:12 2012 +0100
     9.3 @@ -175,3 +175,40 @@ int tapdisk_linux_version(void)
     9.4  }
     9.5  
     9.6  #endif
     9.7 +int read_exact(int fd, void *data, size_t size)
     9.8 +{
     9.9 +    size_t offset = 0;
    9.10 +    ssize_t len;
    9.11 +
    9.12 +    while ( offset < size )
    9.13 +    {
    9.14 +        len = read(fd, (char *)data + offset, size - offset);
    9.15 +        if ( (len == -1) && (errno == EINTR) )
    9.16 +            continue;
    9.17 +        if ( len == 0 )
    9.18 +            errno = 0;
    9.19 +        if ( len <= 0 )
    9.20 +            return -1;
    9.21 +        offset += len;
    9.22 +    }
    9.23 +
    9.24 +    return 0;
    9.25 +}
    9.26 +
    9.27 +int write_exact(int fd, const void *data, size_t size)
    9.28 +{
    9.29 +    size_t offset = 0;
    9.30 +    ssize_t len;
    9.31 +
    9.32 +    while ( offset < size )
    9.33 +    {
    9.34 +        len = write(fd, (const char *)data + offset, size - offset);
    9.35 +        if ( (len == -1) && (errno == EINTR) )
    9.36 +            continue;
    9.37 +        if ( len <= 0 )
    9.38 +            return -1;
    9.39 +        offset += len;
    9.40 +    }
    9.41 +
    9.42 +    return 0;
    9.43 +}
    10.1 --- a/tools/blktap2/drivers/tapdisk-utils.h	Mon May 14 16:51:27 2012 +0100
    10.2 +++ b/tools/blktap2/drivers/tapdisk-utils.h	Mon May 14 16:59:12 2012 +0100
    10.3 @@ -39,4 +39,7 @@ int tapdisk_namedup(char **, const char 
    10.4  int tapdisk_get_image_size(int, uint64_t *, uint32_t *);
    10.5  int tapdisk_linux_version(void);
    10.6  
    10.7 +int read_exact(int fd, void *data, size_t size); /* EOF => -1, errno=0 */
    10.8 +int write_exact(int fd, const void *data, size_t size);
    10.9 +
   10.10  #endif
    11.1 --- a/tools/blktap2/drivers/tapdisk2.c	Mon May 14 16:51:27 2012 +0100
    11.2 +++ b/tools/blktap2/drivers/tapdisk2.c	Mon May 14 16:59:12 2012 +0100
    11.3 @@ -79,7 +79,12 @@ main(int argc, char *argv[])
    11.4  	if (optind != argc)
    11.5  		usage(argv[0], EINVAL);
    11.6  
    11.7 -	chdir("/");
    11.8 +	if (chdir("/")) {
    11.9 +		DPRINTF("failed to chdir(/): %d\n", errno);
   11.10 +		err = 1;
   11.11 +		goto out;
   11.12 +	}
   11.13 +
   11.14  	tapdisk_start_logging("tapdisk2");
   11.15  
   11.16  	err = tapdisk_server_init();
    12.1 --- a/tools/blktap2/vhd/lib/libvhd-journal.c	Mon May 14 16:51:27 2012 +0100
    12.2 +++ b/tools/blktap2/vhd/lib/libvhd-journal.c	Mon May 14 16:59:12 2012 +0100
    12.3 @@ -332,7 +332,7 @@ vhd_journal_write_entry(vhd_journal_t *j
    12.4  
    12.5  	err = vhd_journal_write(j, &e, sizeof(vhd_journal_entry_t));
    12.6  	if (err)
    12.7 -		err;
    12.8 +		return err;
    12.9  
   12.10  	return 0;
   12.11  }