@@ -444,10 +444,15 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
}
bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR);
-
- ret = refresh_total_sectors(bs, bs->total_sectors);
- if (ret < 0) {
- goto free_and_fail;
+ /*
+ * For scsi-generic devices, do not call refresh_total_sectors() -> raw_getlength()
+ * because lseek() will return -ESPIPE.
+ */
+ if (!(bs->sg)) {
+ ret = refresh_total_sectors(bs, bs->total_sectors);
+ if (ret < 0) {
+ goto free_and_fail;
+ }
}
#ifndef _WIN32