From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BUMy3-0002le-E9 for qemu-devel@nongnu.org; Sun, 30 May 2004 05:50:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BUMy2-0002ko-4B for qemu-devel@nongnu.org; Sun, 30 May 2004 05:50:58 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BUMy1-0002kl-OT for qemu-devel@nongnu.org; Sun, 30 May 2004 05:50:57 -0400 Received: from [62.253.162.42] (helo=mta02-svc.ntlworld.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BUMxR-00029n-OC for qemu-devel@nongnu.org; Sun, 30 May 2004 05:50:22 -0400 Received: from [10.10.10.100] ([81.107.87.144]) by mta02-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP id <20040530094913.EMQZ8778.mta02-svc.ntlworld.com@[10.10.10.100]> for ; Sun, 30 May 2004 10:49:13 +0100 Subject: Re: [Qemu-devel] Running QEMU on FreeBSD From: Antony T Curtis In-Reply-To: <20040530102509.0f234b19.markus.niemisto@gmx.net> References: <1085865953.93476.3.camel@pcgem.rdg.cyberkinetica.com> <40B902F5.30809@fabianowski.de> <1085867455.93476.10.camel@pcgem.rdg.cyberkinetica.com> <40B90776.60406@fabianowski.de> <1085868567.93476.13.camel@pcgem.rdg.cyberkinetica.com> <40B90DB2.3040508@fabianowski.de> <1085872155.93476.18.camel@pcgem.rdg.cyberkinetica.com> <20040530102509.0f234b19.markus.niemisto@gmx.net> Content-Type: multipart/mixed; boundary="=-XGJp0EOu3E2NhrItZnE1" Message-Id: <1085910613.94556.3.camel@pcgem.rdg.cyberkinetica.com> Mime-Version: 1.0 Date: Sun, 30 May 2004 10:50:13 +0100 Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --=-XGJp0EOu3E2NhrItZnE1 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit On Sun, 2004-05-30 at 08:25, Markus Niemistö wrote: > On Sun, 30 May 2004 00:09:16 +0100 > Antony T Curtis wrote: > > > Sure... I'll generate some diffs soon... > > Meanwhile, I've done a few more mods so that QEMU can use FreeBSD's > > devices... so that I can specify put "-cdrom /dev/cdrom" on the > > command line - successfully booted off a FreeBSD install cdrom :D > > The patch you sent doesn't deal with these issues, right? Could you > please make a patch and send it to the list. I've occasionally tried to > fix using devices but the patches I've made worked only partially. > > Was the problem with CDs due to qemu not reading 2048 blocks or was > there something else? Here is the diffs I am using... What it fixes is the following... It uses the FreeBSD ioctls to determine the size of the device and when reading the 'header', it reads 2048 bytes. A similar fix has to be done to qemu-mkcow for it to work. -- Antony T Curtis --=-XGJp0EOu3E2NhrItZnE1 Content-Disposition: attachment; filename=qemu-blk-fbsd.patch Content-Type: text/x-patch; name=qemu-blk-fbsd.patch; charset=iso-8859-1 Content-Transfer-Encoding: 7bit diff -BcNpPr -C 4 qemu-0.5.5/block.c qemu-0.5.5-fbsd/block.c *** qemu-0.5.5/block.c Sat May 8 15:51:18 2004 --- qemu-0.5.5-fbsd/block.c Sun May 30 01:03:08 2004 *************** *** 26,33 **** --- 26,40 ---- #ifndef _WIN32 #include #endif + #ifdef __FreeBSD__ + #include + #include + #include + #include + #endif + #include "cow.h" struct BlockDriverState { int fd; /* if -1, only COW mappings */ *************** BlockDriverState *bdrv_new(const char *d *** 80,88 **** int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) { int fd; int64_t size; ! struct cow_header_v2 cow_header; #ifndef _WIN32 char template[] = "/tmp/vl.XXXXXX"; int cow_fd; struct stat st; --- 87,98 ---- int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) { int fd; int64_t size; ! union { ! struct cow_header_v2 header; ! uint8_t buffer[512*4]; ! } cow; #ifndef _WIN32 char template[] = "/tmp/vl.XXXXXX"; int cow_fd; struct stat st; *************** int bdrv_open(BlockDriverState *bs, cons *** 115,169 **** bs->read_only = 1; } bs->fd = fd; /* see if it is a cow image */ ! if (read(fd, &cow_header, sizeof(cow_header)) != sizeof(cow_header)) { fprintf(stderr, "%s: could not read header\n", filename); goto fail; } #ifndef _WIN32 ! if (be32_to_cpu(cow_header.magic) == COW_MAGIC && ! be32_to_cpu(cow_header.version) == COW_VERSION) { /* cow image found */ ! size = cow_header.size; #ifndef WORDS_BIGENDIAN size = bswap64(size); #endif bs->total_sectors = size / 512; bs->cow_fd = fd; bs->fd = -1; ! if (cow_header.backing_file[0] != '\0') { ! if (stat(cow_header.backing_file, &st) != 0) { ! fprintf(stderr, "%s: could not find original disk image '%s'\n", filename, cow_header.backing_file); goto fail; } ! if (st.st_mtime != be32_to_cpu(cow_header.mtime)) { ! fprintf(stderr, "%s: original raw disk image '%s' does not match saved timestamp\n", filename, cow_header.backing_file); goto fail; } ! fd = open(cow_header.backing_file, O_RDONLY | O_LARGEFILE); if (fd < 0) goto fail; bs->fd = fd; } ! /* mmap the bitmap */ ! bs->cow_bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header); bs->cow_bitmap_addr = mmap(get_mmap_addr(bs->cow_bitmap_size), bs->cow_bitmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, bs->cow_fd, 0); if (bs->cow_bitmap_addr == MAP_FAILED) goto fail; ! bs->cow_bitmap = bs->cow_bitmap_addr + sizeof(cow_header); bs->cow_sectors_offset = (bs->cow_bitmap_size + 511) & ~511; snapshot = 0; } else #endif { /* standard raw image */ size = lseek64(fd, 0, SEEK_END); bs->total_sectors = size / 512; bs->fd = fd; } --- 125,189 ---- bs->read_only = 1; } bs->fd = fd; + lseek(fd, 0LL, SEEK_SET); /* see if it is a cow image */ ! if (read(fd, &cow.buffer, sizeof(cow.buffer)) != sizeof(cow.buffer)) { fprintf(stderr, "%s: could not read header\n", filename); goto fail; } #ifndef _WIN32 ! if (be32_to_cpu(cow.header.magic) == COW_MAGIC && ! be32_to_cpu(cow.header.version) == COW_VERSION) { /* cow image found */ ! size = cow.header.size; #ifndef WORDS_BIGENDIAN size = bswap64(size); #endif bs->total_sectors = size / 512; bs->cow_fd = fd; bs->fd = -1; ! if (cow.header.backing_file[0] != '\0') { ! if (stat(cow.header.backing_file, &st) != 0) { ! fprintf(stderr, "%s: could not find original disk image '%s'\n", filename, cow.header.backing_file); goto fail; } ! if (st.st_mtime != be32_to_cpu(cow.header.mtime)) { ! fprintf(stderr, "%s: original raw disk image '%s' does not match saved timestamp\n", filename, cow.header.backing_file); goto fail; } ! fd = open(cow.header.backing_file, O_RDONLY | O_LARGEFILE); if (fd < 0) goto fail; bs->fd = fd; } ! /* mmap thquie bitmap */ ! bs->cow_bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow.header); bs->cow_bitmap_addr = mmap(get_mmap_addr(bs->cow_bitmap_size), bs->cow_bitmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, bs->cow_fd, 0); if (bs->cow_bitmap_addr == MAP_FAILED) goto fail; ! bs->cow_bitmap = bs->cow_bitmap_addr + sizeof(cow.header); bs->cow_sectors_offset = (bs->cow_bitmap_size + 511) & ~511; snapshot = 0; } else #endif { /* standard raw image */ + #ifdef __FreeBSD__ + if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) + size = lseek(fd, 0LL, SEEK_END); + #else size = lseek64(fd, 0, SEEK_END); + #endif + if (size<0) { + fprintf(stderr,"unable to determine size of device\n"); + goto fail; + } bs->total_sectors = size / 512; bs->fd = fd; } --=-XGJp0EOu3E2NhrItZnE1--