Revision 03ff3ca3 block-raw-posix.c
b/block-raw-posix.c | ||
---|---|---|
22 | 22 |
* THE SOFTWARE. |
23 | 23 |
*/ |
24 | 24 |
#include "qemu-common.h" |
25 |
#if !defined(QEMU_IMG) && !defined(QEMU_NBD) |
|
26 | 25 |
#include "qemu-timer.h" |
27 |
#include "exec-all.h" |
|
28 | 26 |
#include "qemu-char.h" |
29 |
#endif |
|
30 | 27 |
#include "block_int.h" |
31 | 28 |
#include "compatfd.h" |
32 | 29 |
#include <assert.h> |
... | ... | |
70 | 67 |
//#define DEBUG_FLOPPY |
71 | 68 |
|
72 | 69 |
//#define DEBUG_BLOCK |
73 |
#if defined(DEBUG_BLOCK) && !defined(QEMU_IMG) && !defined(QEMU_NBD)
|
|
70 |
#if defined(DEBUG_BLOCK) |
|
74 | 71 |
#define DEBUG_BLOCK_PRINT(formatCstr, args...) do { if (loglevel != 0) \ |
75 | 72 |
{ fprintf(logfile, formatCstr, ##args); fflush(logfile); } } while (0) |
76 | 73 |
#else |
... | ... | |
99 | 96 |
int fd_got_error; |
100 | 97 |
int fd_media_changed; |
101 | 98 |
#endif |
102 |
#if defined(O_DIRECT) && !defined(QEMU_IMG)
|
|
99 |
#if defined(O_DIRECT) |
|
103 | 100 |
uint8_t* aligned_buf; |
104 | 101 |
#endif |
105 | 102 |
} BDRVRawState; |
... | ... | |
137 | 134 |
return ret; |
138 | 135 |
} |
139 | 136 |
s->fd = fd; |
140 |
#if defined(O_DIRECT) && !defined(QEMU_IMG)
|
|
137 |
#if defined(O_DIRECT) |
|
141 | 138 |
s->aligned_buf = NULL; |
142 | 139 |
if (flags & BDRV_O_DIRECT) { |
143 | 140 |
s->aligned_buf = qemu_memalign(512, ALIGNED_BUFFER_SIZE); |
... | ... | |
272 | 269 |
} |
273 | 270 |
|
274 | 271 |
|
275 |
#if defined(O_DIRECT) && !defined(QEMU_IMG)
|
|
272 |
#if defined(O_DIRECT) |
|
276 | 273 |
/* |
277 | 274 |
* offset and count are in bytes and possibly not aligned. For files opened |
278 | 275 |
* with O_DIRECT, necessary alignments are ensured before calling |
... | ... | |
525 | 522 |
|
526 | 523 |
fcntl(aio_sig_fd, F_SETFL, O_NONBLOCK); |
527 | 524 |
|
528 |
#if !defined(QEMU_IMG) && !defined(QEMU_NBD) |
|
529 | 525 |
qemu_set_fd_handler2(aio_sig_fd, NULL, qemu_aio_poll, NULL, NULL); |
530 |
#endif |
|
531 | 526 |
|
532 | 527 |
#if defined(__GLIBC__) && defined(__linux__) |
533 | 528 |
{ |
... | ... | |
556 | 551 |
{ |
557 | 552 |
int ret; |
558 | 553 |
|
559 |
#if !defined(QEMU_IMG) && !defined(QEMU_NBD) |
|
560 | 554 |
if (qemu_bh_poll()) |
561 | 555 |
return; |
562 |
#endif |
|
563 | 556 |
|
564 | 557 |
if (!first_aio) |
565 | 558 |
return; |
... | ... | |
605 | 598 |
return acb; |
606 | 599 |
} |
607 | 600 |
|
608 |
#if !defined(QEMU_IMG) && !defined(QEMU_NBD) |
|
609 | 601 |
static void raw_aio_em_cb(void* opaque) |
610 | 602 |
{ |
611 | 603 |
RawAIOCB *acb = opaque; |
612 | 604 |
acb->common.cb(acb->common.opaque, acb->ret); |
613 | 605 |
qemu_aio_release(acb); |
614 | 606 |
} |
615 |
#endif |
|
616 | 607 |
|
617 | 608 |
static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs, |
618 | 609 |
int64_t sector_num, uint8_t *buf, int nb_sectors, |
... | ... | |
624 | 615 |
* If O_DIRECT is used and the buffer is not aligned fall back |
625 | 616 |
* to synchronous IO. |
626 | 617 |
*/ |
627 |
#if defined(O_DIRECT) && !defined(QEMU_IMG) && !defined(QEMU_NBD)
|
|
618 |
#if defined(O_DIRECT) |
|
628 | 619 |
BDRVRawState *s = bs->opaque; |
629 | 620 |
|
630 | 621 |
if (unlikely(s->aligned_buf != NULL && ((uintptr_t) buf % 512))) { |
... | ... | |
657 | 648 |
* If O_DIRECT is used and the buffer is not aligned fall back |
658 | 649 |
* to synchronous IO. |
659 | 650 |
*/ |
660 |
#if defined(O_DIRECT) && !defined(QEMU_IMG) && !defined(QEMU_NBD)
|
|
651 |
#if defined(O_DIRECT) |
|
661 | 652 |
BDRVRawState *s = bs->opaque; |
662 | 653 |
|
663 | 654 |
if (unlikely(s->aligned_buf != NULL && ((uintptr_t) buf % 512))) { |
... | ... | |
719 | 710 |
|
720 | 711 |
void qemu_aio_wait(void) |
721 | 712 |
{ |
722 |
#if !defined(QEMU_IMG) && !defined(QEMU_NBD) |
|
723 | 713 |
qemu_bh_poll(); |
724 |
#endif |
|
725 | 714 |
} |
726 | 715 |
|
727 | 716 |
#endif /* CONFIG_AIO */ |
... | ... | |
732 | 721 |
if (s->fd >= 0) { |
733 | 722 |
close(s->fd); |
734 | 723 |
s->fd = -1; |
735 |
#if defined(O_DIRECT) && !defined(QEMU_IMG)
|
|
724 |
#if defined(O_DIRECT) |
|
736 | 725 |
if (s->aligned_buf != NULL) |
737 | 726 |
qemu_free(s->aligned_buf); |
738 | 727 |
#endif |
... | ... | |
1002 | 991 |
return 0; |
1003 | 992 |
} |
1004 | 993 |
|
1005 |
#if defined(__linux__) && !defined(QEMU_IMG) && !defined(QEMU_NBD)
|
|
994 |
#if defined(__linux__) |
|
1006 | 995 |
|
1007 | 996 |
/* Note: we do not have a reliable method to detect if the floppy is |
1008 | 997 |
present. The current method is to try to open the floppy at every |
... | ... | |
1052 | 1041 |
s->fd_got_error = 0; |
1053 | 1042 |
return 0; |
1054 | 1043 |
} |
1055 |
#else |
|
1056 |
static int fd_open(BlockDriverState *bs) |
|
1057 |
{ |
|
1058 |
return 0; |
|
1059 |
} |
|
1060 |
#endif |
|
1061 |
|
|
1062 |
#if defined(__linux__) |
|
1063 | 1044 |
|
1064 | 1045 |
static int raw_is_inserted(BlockDriverState *bs) |
1065 | 1046 |
{ |
Also available in: Unified diff