Subject: Re: xen 3.2 stable branch opened / xen-unstable heads to Xen 3.3
To: Manuel Bouyer <bouyer@antioche.eu.org>
From: Christoph Egger <Christoph_Egger@gmx.de>
List: port-xen
Date: 01/16/2008 15:02:30
--Boundary-00=_35gjHzkJfJwTPLx
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Wednesday 16 January 2008 14:42:41 Manuel Bouyer wrote:
> On Tue, Jan 15, 2008 at 05:52:57PM +0100, Christoph Egger wrote:
> > Hi!
> >
> > XenSource opened the Xen 3.2 stable branch:
> >
> > http://xenbits.xensource.com/staging/xen-3.2-testing.hg
> >
> > Xen-unstable heads to Xen 3.3.
> >
> >
> > Just for your information.
>
> That's valuable information, thanks.
> For some reason It seems I don't get announcements from xen-announce
> any more ...

Neither did I.
Yes, they seem to become lazy... they even did not create tarballs for Xen 
3.1.1 and Xen 3.1.2 releases. I hope, they will do for Xen 3.1.3 and Xen 
3.2.0.

Manuel: Is there a chance that you can package a snapshot from the 
xen-3.2-testing tree in pkgsrc/pkgsrc-wip for testing purpose, please?
I would like to get some feedback in order to get missing fixes for NetBSD 
upstream before 3.2.0 final is out.

When you are about it, please apply attached patch. It factors linux
specific code out into a separate file in blktap. So there is no longer a need
to disable blktap in tools/Makefile.
The patch went upstream into xen-unstable right after xen-3.2 branch has been 
opened.

Christoph

--Boundary-00=_35gjHzkJfJwTPLx
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="tools_blktap.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="tools_blktap.diff"

diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/Makefile
--- a/tools/blktap/drivers/Makefile	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/Makefile	Tue Jan 15 14:17:22 2008 +0000
@@ -28,28 +28,29 @@ LIBS      += -L$(XEN_XENSTORE) -lxenstor
 
 AIOLIBS   := $(LIBAIO_DIR)/libaio.a
 
-BLK-OBJS  := block-aio.o
-BLK-OBJS  += block-sync.o
-BLK-OBJS  += block-vmdk.o
-BLK-OBJS  += block-ram.o
-BLK-OBJS  += block-qcow.o
-BLK-OBJS  += aes.o
-BLK-OBJS  += tapaio.o
+BLK-OBJS-y  := block-aio.o
+BLK-OBJS-y  += block-sync.o
+BLK-OBJS-y  += block-vmdk.o
+BLK-OBJS-y  += block-ram.o
+BLK-OBJS-y  += block-qcow.o
+BLK-OBJS-y  += aes.o
+BLK-OBJS-y  += tapaio.o
+BLK-OBJS-$(CONFIG_Linux) += blk_linux.c
 
 all: $(IBIN) qcow-util
 
 blktapctrl: blktapctrl.c
 	$(CC) $(CFLAGS) -o blktapctrl $(LIBS) blktapctrl.c
 
-tapdisk: $(BLK-OBJS) tapdisk.c
-	$(CC) $(CFLAGS) -o tapdisk $(BLK-OBJS) tapdisk.c \
+tapdisk: $(BLK-OBJS-y) tapdisk.c
+	$(CC) $(CFLAGS) -o tapdisk $(BLK-OBJS-y) tapdisk.c \
 		$(AIOLIBS) $(LIBS)
 
 .PHONY: qcow-util
 qcow-util: img2qcow qcow2raw qcow-create
 
-img2qcow qcow2raw qcow-create: %: $(BLK-OBJS)
-	$(CC) $(CFLAGS) -o $* $(BLK-OBJS) $*.c $(AIOLIBS) $(LIBS)
+img2qcow qcow2raw qcow-create: %: $(BLK-OBJS-y)
+	$(CC) $(CFLAGS) -o $* $(BLK-OBJS-y) $*.c $(AIOLIBS) $(LIBS)
 
 install: all
 	$(INSTALL_PROG) $(IBIN) $(QCOW_UTIL) $(VHD_UTIL) $(DESTDIR)$(INST_DIR)
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/blk.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap/drivers/blk.h	Tue Jan 15 14:17:22 2008 +0000
@@ -0,0 +1,3 @@
+
+int blk_getimagesize(int fd, uint64_t *size);
+int blk_getsectorsize(int fd, uint64_t *sector_size);
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/blk_linux.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap/drivers/blk_linux.c	Tue Jan 15 14:17:22 2008 +0000
@@ -0,0 +1,42 @@
+#include <inttypes.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+#include "tapdisk.h"
+#include "blk.h"
+
+int blk_getimagesize(int fd, uint64_t *size)
+{
+	int rc;
+
+	*size = 0;
+	rc = ioctl(fd, BLKGETSIZE, size);
+	if (rc) {
+		DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int blk_getsectorsize(int fd, uint64_t *sector_size)
+{
+#if defined(BLKSSZGET)
+	int rc;
+
+	*sector_size = DEFAULT_SECTOR_SIZE;
+	rc = ioctl(fd, BLKSSZGET, sector_size);
+	if (rc) {
+		DPRINTF("ERR: BLKSSZGET failed. Falling back to use default sector size");
+		*sector_size = DEFAULT_SECTOR_SIZE;
+	}
+
+	if (*sector_size != DEFAULT_SECTOR_SIZE)
+		DPRINTF("Note: sector size is %"PRIu64" (not %u)\n",
+			*sector_size, DEFAULT_SECTOR_SIZE);
+#else
+	*sector_size = DEFAULT_SECTOR_SIZE;
+#endif
+
+	return 0;
+}
+
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/block-aio.c
--- a/tools/blktap/drivers/block-aio.c	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/block-aio.c	Tue Jan 15 14:17:22 2008 +0000
@@ -41,11 +41,16 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include "tapdisk.h"
 #include "tapaio.h"
+#include "blk.h"
 
 #define MAX_AIO_REQS (MAX_REQUESTS * MAX_SEGMENTS_PER_REQ)
+
+/* *BSD has no O_LARGEFILE */
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
 
 struct pending_aio {
 	td_callback_t cb;
@@ -87,11 +92,8 @@ static int get_image_info(struct td_stat
 
 	if (S_ISBLK(stat.st_mode)) {
 		/*Accessing block device directly*/
-		s->size = 0;
-		if (ioctl(fd,BLKGETSIZE,&s->size)!=0) {
-			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+		if (blk_getimagesize(fd, &s->size) != 0)
 			return -EINVAL;
-		}
 
 		DPRINTF("Image size: \n\tpre sector_shift  [%llu]\n\tpost "
 			"sector_shift [%llu]\n",
@@ -99,19 +101,8 @@ static int get_image_info(struct td_stat
 			(long long unsigned)s->size);
 
 		/*Get the sector size*/
-#if defined(BLKSSZGET)
-		{
-			int arg;
+		if (blk_getsectorsize(fd, &s->sector_size) != 0)
 			s->sector_size = DEFAULT_SECTOR_SIZE;
-			ioctl(fd, BLKSSZGET, &s->sector_size);
-			
-			if (s->sector_size != DEFAULT_SECTOR_SIZE)
-				DPRINTF("Note: sector size is %ld (not %d)\n",
-					s->sector_size, DEFAULT_SECTOR_SIZE);
-		}
-#else
-		s->sector_size = DEFAULT_SECTOR_SIZE;
-#endif
 
 	} else {
 		/*Local file? try fstat instead*/
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/block-qcow.c
--- a/tools/blktap/drivers/block-qcow.c	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/block-qcow.c	Tue Jan 15 14:17:22 2008 +0000
@@ -29,7 +29,6 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include <string.h>
 #include <zlib.h>
 #include <inttypes.h>
@@ -39,6 +38,12 @@
 #include "aes.h"
 #include "tapdisk.h"
 #include "tapaio.h"
+#include "blk.h"
+
+/* *BSD has no O_LARGEFILE */
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
 
 #if 1
 #define ASSERT(_p) \
@@ -284,8 +289,7 @@ static int get_filesize(char *filename, 
 		fd = open(filename, O_RDONLY);
 		if (fd < 0)
 			return -1;
-		if (ioctl(fd,BLKGETSIZE,size)!=0) {
-			printf("Unable to get Block device size\n");
+		if (blk_getimagesize(fd, size) != 0) {
 			close(fd);
 			return -1;
 		}
@@ -990,8 +994,8 @@ int tdqcow_open (struct disk_driver *dd,
 	if (!final_cluster)
 		s->fd_end = s->l1_table_offset + l1_table_size;
 	else {
-		s->fd_end = lseek64(fd, 0, SEEK_END);
-		if (s->fd_end == (off64_t)-1)
+		s->fd_end = lseek(fd, 0, SEEK_END);
+		if (s->fd_end == (off_t)-1)
 			goto fail;
 	}
 
@@ -1230,7 +1234,7 @@ int qcow_create(const char *filename, ui
 	DPRINTF("Qcow_create: size %llu\n",(long long unsigned)total_size);
 
 	fd = open(filename, 
-		  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 
+		  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
 		  0644);
 	if (fd < 0)
 		return -1;
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/block-ram.c
--- a/tools/blktap/drivers/block-ram.c	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/block-ram.c	Tue Jan 15 14:17:22 2008 +0000
@@ -33,15 +33,21 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include <string.h>
 #include "tapdisk.h"
+#include "blk.h"
 
 #define MAX_DISK_SIZE 1024000 /*500MB disk limit*/
+
+/* *BSD has no O_LARGEFILE */
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
 
 char *img;
 long int   disksector_size;
@@ -71,11 +77,8 @@ static int get_image_info(struct td_stat
 
 	if (S_ISBLK(stat.st_mode)) {
 		/*Accessing block device directly*/
-		s->size = 0;
-		if (ioctl(fd,BLKGETSIZE,&s->size)!=0) {
-			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+		if (blk_getimagesize(fd, &s->size) != 0)
 			return -EINVAL;
-		}
 
 		DPRINTF("Image size: \n\tpre sector_shift  [%llu]\n\tpost "
 			"sector_shift [%llu]\n",
@@ -83,19 +86,8 @@ static int get_image_info(struct td_stat
 			(long long unsigned)s->size);
 
 		/*Get the sector size*/
-#if defined(BLKSSZGET)
-		{
-			int arg;
+		if (blk_getsectorsize(fd, &s->sector_size) != 0)
 			s->sector_size = DEFAULT_SECTOR_SIZE;
-			ioctl(fd, BLKSSZGET, &s->sector_size);
-			
-			if (s->sector_size != DEFAULT_SECTOR_SIZE)
-				DPRINTF("Note: sector size is %ld (not %d)\n",
-					s->sector_size, DEFAULT_SECTOR_SIZE);
-		}
-#else
-		s->sector_size = DEFAULT_SECTOR_SIZE;
-#endif
 
 	} else {
 		/*Local file? try fstat instead*/
@@ -117,7 +109,7 @@ static int get_image_info(struct td_stat
 	disksector_size = s->sector_size;
 	disksize        = s->size;
 	diskinfo        = s->info;
-	DPRINTF("Image sector_size: \n\t[%lu]\n",
+	DPRINTF("Image sector_size: \n\t[%"PRIu64"]\n",
 		s->sector_size);
 
 	return 0;
@@ -159,7 +151,7 @@ int tdram_open (struct disk_driver *dd, 
 			"sector_shift [%llu]\n",
 			(long long unsigned)(s->size << SECTOR_SHIFT),
 			(long long unsigned)s->size);
-		DPRINTF("Image sector_size: \n\t[%lu]\n",
+		DPRINTF("Image sector_size: \n\t[%"PRIu64"]\n",
 			s->sector_size);
 
 		prv->fd = -1;
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/block-sync.c
--- a/tools/blktap/drivers/block-sync.c	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/block-sync.c	Tue Jan 15 14:17:22 2008 +0000
@@ -37,8 +37,13 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include "tapdisk.h"
+#include "blk.h"
+
+/* *BSD has no O_LARGEFILE */
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
 
 struct tdsync_state {
 	int fd;
@@ -62,11 +67,8 @@ static int get_image_info(struct td_stat
 
 	if (S_ISBLK(stat.st_mode)) {
 		/*Accessing block device directly*/
-		s->size = 0;
-		if (ioctl(fd,BLKGETSIZE,&s->size)!=0) {
-			DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+		if (blk_getimagesize(fd, &s->size) != 0)
 			return -EINVAL;
-		}
 
 		DPRINTF("Image size: \n\tpre sector_shift  [%llu]\n\tpost "
 			"sector_shift [%llu]\n",
@@ -74,19 +76,8 @@ static int get_image_info(struct td_stat
 			(long long unsigned)s->size);
 
 		/*Get the sector size*/
-#if defined(BLKSSZGET)
-		{
-			int arg;
+		if (blk_getsectorsize(fd, &s->sector_size) != 0)
 			s->sector_size = DEFAULT_SECTOR_SIZE;
-			ioctl(fd, BLKSSZGET, &s->sector_size);
-			
-			if (s->sector_size != DEFAULT_SECTOR_SIZE)
-				DPRINTF("Note: sector size is %ld (not %d)\n",
-					s->sector_size, DEFAULT_SECTOR_SIZE);
-		}
-#else
-		s->sector_size = DEFAULT_SECTOR_SIZE;
-#endif
 
 	} else {
 		/*Local file? try fstat instead*/
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/block-vmdk.c
--- a/tools/blktap/drivers/block-vmdk.c	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/block-vmdk.c	Tue Jan 15 14:17:22 2008 +0000
@@ -42,10 +42,14 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include <string.h>
 #include "tapdisk.h"
 #include "bswap.h"
+
+/* *BSD has no O_LARGEFILE */
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
 
 #define safer_free(_x)       \
   do {                       \
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/img2qcow.c
--- a/tools/blktap/drivers/img2qcow.c	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/img2qcow.c	Tue Jan 15 14:17:22 2008 +0000
@@ -37,15 +37,21 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include <string.h>
 #include "tapdisk.h"
+#include "blk.h"
 
 #if 1
 #define DFPRINTF(_f, _a...) fprintf ( stderr, _f , ## _a )
 #else
 #define DFPRINTF(_f, _a...) ((void)0)
 #endif
+
+/* *BSD has no O_LARGEFILE */
+#ifndef O_LARGEFILE
+#define O_LARGEFILE	0
+#endif
+
 
 #define TAPDISK 1
 #define BLOCK_PROCESSSZ 4096
@@ -109,12 +115,8 @@ static int get_image_info(struct td_stat
 
 	if (S_ISBLK(stat.st_mode)) {
 		/*Accessing block device directly*/
-		s->size = 0;
-		if (ioctl(fd,BLKGETSIZE,&s->size)!=0) {
-			DFPRINTF("ERR: BLKGETSIZE failed, "
-				 "couldn't stat image");
+		if (blk_getimagesize(fd, &s->size) != 0)
 			return -EINVAL;
-		}
 
 		DFPRINTF("Image size: \n\tpre sector_shift  [%llu]\n\tpost "
 			"sector_shift [%llu]\n",
@@ -122,19 +124,8 @@ static int get_image_info(struct td_stat
 			(long long unsigned)s->size);
 
 		/*Get the sector size*/
-#if defined(BLKSSZGET)
-		{
-			int arg;
+		if (blk_getsectorsize(fd, &s->sector_size) != 0)
 			s->sector_size = DEFAULT_SECTOR_SIZE;
-			ioctl(fd, BLKSSZGET, &s->sector_size);
-			
-			if (s->sector_size != DEFAULT_SECTOR_SIZE)
-				DFPRINTF("Note: sector size is %ld (not %d)\n",
-					s->sector_size, DEFAULT_SECTOR_SIZE);
-		}
-#else
-		s->sector_size = DEFAULT_SECTOR_SIZE;
-#endif
 
 	} else {
 		/*Local file? try fstat instead*/
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/qcow2raw.c
--- a/tools/blktap/drivers/qcow2raw.c	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/qcow2raw.c	Tue Jan 15 14:17:22 2008 +0000
@@ -33,18 +33,25 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
 #include <string.h>
 #include "tapdisk.h"
+#include "blk.h"
 
 #if 1
 #define DFPRINTF(_f, _a...) fprintf ( stderr, _f , ## _a )
 #else
 #define DFPRINTF(_f, _a...) ((void)0)
+#endif
+
+
+/* *BSD has no O_LARGEFILE */
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
 #endif
 
 #define TAPDISK 1
@@ -142,7 +149,7 @@ int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 	int ret = -1, fd, len,input;
-	long int size;
+	uint64_t size;
 	fd_set readfds;
 	struct timeval timeout;
 	uint64_t i;
@@ -227,16 +234,15 @@ int main(int argc, char *argv[])
 		}
 
 		if (S_ISBLK(finfo.st_mode)) {
-			if(ioctl(fd,BLKGETSIZE,&size)!=0) {
-				DFPRINTF("ERROR: BLKGETSIZE failed, "
-					"couldn't stat image [%s]\n", 
-					argv[1]);
-				close(fd);
-				exit(-1);
-			}
+			if (blk_getimagesize(fd, &size) != 0) {
+				close(fd);
+				return -1;
+			}
+
 			if (size < ddqcow.td_state->size<<9) {
 				DFPRINTF("ERROR: Not enough space on device "
-					"%s (%lu bytes available, %llu bytes required\n",
+					"%s (%"PRIu64" bytes available, "
+					"%llu bytes required\n",
 					argv[1], size, 
 					(long long unsigned)ddqcow.td_state->size<<9);
 				close(fd);
diff -r 973221f4d9c7 -r b6cc74f275fd tools/blktap/drivers/tapdisk.h
--- a/tools/blktap/drivers/tapdisk.h	Tue Jan 15 11:29:15 2008 +0000
+++ b/tools/blktap/drivers/tapdisk.h	Tue Jan 15 14:17:22 2008 +0000
@@ -108,8 +108,8 @@ struct td_state {
 	void *image;
 	void *ring_info;
 	void *fd_entry;
-	unsigned long      sector_size;
-	unsigned long long size;
+	uint64_t sector_size;
+	uint64_t size;
 	unsigned int       info;
 };
 

--Boundary-00=_35gjHzkJfJwTPLx--