Skip to contentSkip to conversation

Fix block device read for some SLOW file

PATCH In review lepton 3 participants 3 messages Jul 27, 2005

lore
Share & tools
lore

lepton

author
#0 lore raw

PATCH 1/1 Fix block device read for some SLOW file

Hi, I found when I am using qemu, I can't boot from emulated cdrom. After some debug, I found the reason is that my iso file is in a samba file system. When qemu read data from my samba file system. read will be interrupted by signal alarm. So qemu won't boot from it.

The follwing patch will fix it.

block.c +10 -4
@@ -591,10 +591,16 @@ static int raw_read(BlockDriverState *bs
     int ret;
     
     lseek(s->fd, sector_num * 512, SEEK_SET);
-    ret = read(s->fd, buf, nb_sectors * 512);
-    if (ret != nb_sectors * 512) 
-        return -1;
-    return 0;
+    while(1){
+  	ret = read(s->fd, buf, nb_sectors * 512);
+	if (ret != nb_sectors * 512) {
+		if(ret==-1 && errno==EINTR)
+			continue;
+	    	else
+        		return -1;
+	}
+	return 0;
+    }
 }
 
 static int raw_write(BlockDriverState *bs, int64_t sector_num, 
#1 lore raw

Hi,

block.c static int raw_read(BlockDriverState *bs · line 603

Quoted 10 lines · lepton
block.c +10 -0
+    while(1){
+  	ret = read(s->fd, buf, nb_sectors * 512);
+	if (ret != nb_sectors * 512) {
+		if(ret==-1 && errno==EINTR)
+			continue;
+	    	else
+        		return -1;
+	}
+	return 0;
+    }

Why not

do {
	ret = read(s->fd, buf, nb_sectors * 512);
} while(ret==-1 && errno=EINTR);

if (ret != nb_sectors * 512)

	return -1;

return 0;

Ciao,
Dscho

#2 lore raw
In reply to lepton
Quoted 10 lines · lepton

Hi, I found when I am using qemu, I can't boot from emulated cdrom. After some debug, I found the reason is that my iso file is in a samba file system. When qemu read data from my samba file system. read will be interrupted by signal alarm. So qemu won't boot from it.

The follwing patch will fix it.

block.c static int raw_read(BlockDriverState *bs · line 597

Quoted 7 lines
block.c +0 -4
@@ -591,10 +591,16 @@ static int raw_read(BlockDriverState *bs
     int ret;
 
     lseek(s->fd, sector_num * 512, SEEK_SET);
-    ret = read(s->fd, buf, nb_sectors * 512);
-    if (ret != nb_sectors * 512) 
-        return -1;
-    return 0;

There's another error related to this code: qemu won't boot floppy images whose size isn't a multiple of 512, it will drop the last incomplete sector, as the last read will not give 512 bytes. a good testcase is the asmutils linux floppy image.

Jani