From 985a03b0ce38275c2ea355bf29b6d6b5779dbb56 Mon Sep 17 00:00:00 2001 From: ths Date: Mon, 24 Dec 2007 16:10:43 +0000 Subject: Real SCSI device passthrough (v4), by Laurent Vivier. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3851 c046a42c-6fe2-441c-8c8c-71466251a162 --- block-raw-posix.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'block-raw-posix.c') diff --git a/block-raw-posix.c b/block-raw-posix.c index 8ace5ef746..b50da1f7bf 100644 --- a/block-raw-posix.c +++ b/block-raw-posix.c @@ -151,7 +151,7 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, if (ret < 0) return ret; - if (lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { + if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { ++(s->lseek_err_cnt); if(s->lseek_err_cnt <= 10) { DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 @@ -204,7 +204,7 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, if (ret < 0) return ret; - if (lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { + if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { ++(s->lseek_err_cnt); if(s->lseek_err_cnt) { DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %" PRId64 ", %p, %d) [%" @@ -276,8 +276,8 @@ void qemu_aio_init(void) seems to fix the problem. */ struct aioinit ai; memset(&ai, 0, sizeof(ai)); - ai.aio_threads = 1; - ai.aio_num = 1; + ai.aio_threads = 16; + ai.aio_num = 16; ai.aio_idle_time = 365 * 100000; aio_init(&ai); } @@ -387,7 +387,10 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs, acb->aiocb.aio_sigevent.sigev_signo = aio_sig_num; acb->aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL; acb->aiocb.aio_buf = buf; - acb->aiocb.aio_nbytes = nb_sectors * 512; + if (nb_sectors < 0) + acb->aiocb.aio_nbytes = -nb_sectors; + else + acb->aiocb.aio_nbytes = nb_sectors * 512; acb->aiocb.aio_offset = sector_num * 512; acb->next = first_aio; first_aio = acb; @@ -679,6 +682,8 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) s->fd_open_flags = open_flags; /* open will not fail even if no floppy is inserted */ open_flags |= O_NONBLOCK; + } else if (strstart(filename, "/dev/sg", NULL)) { + bs->sg = 1; } #endif fd = open(filename, open_flags, 0644); @@ -858,6 +863,12 @@ static int raw_set_locked(BlockDriverState *bs, int locked) return 0; } +static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) +{ + BDRVRawState *s = bs->opaque; + + return ioctl(s->fd, req, buf); +} #else static int raw_is_inserted(BlockDriverState *bs) @@ -880,6 +891,10 @@ static int raw_set_locked(BlockDriverState *bs, int locked) return -ENOTSUP; } +static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) +{ + return -ENOTSUP; +} #endif /* !linux */ BlockDriver bdrv_host_device = { @@ -906,4 +921,6 @@ BlockDriver bdrv_host_device = { .bdrv_media_changed = raw_media_changed, .bdrv_eject = raw_eject, .bdrv_set_locked = raw_set_locked, + /* generic scsi device */ + .bdrv_ioctl = raw_ioctl, }; -- cgit v1.2.3