Commit fdef621b authored by Anthony Liguori's avatar Anthony Liguori
Browse files

Merge remote-tracking branch 'kwolf/for-anthony' into staging

* kwolf/for-anthony:
  qemu-iotests: Fix 030 after switch to GenericError
  block: Flush parent to OS with cache=unsafe
  iscsi: Fix NULL dereferences / races between task completion and abort
  monitor: Clean up fd sets on monitor disconnect
  block: Enable qemu_open/close to work with fd sets
  block: Convert close calls to qemu_close
  block: Convert open calls to qemu_open
  block: Prevent detection of /dev/fdset/ as floppy
  qapi: Introduce add-fd, remove-fd, query-fdsets
  qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg
parents cc921867 58c8cce2
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -148,9 +148,6 @@ install-libcacard: libcacard.la
	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libcacard V="$(V)" TARGET_DIR="$*/" install-libcacard,)
endif

vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) qemu-timer-common.o libcacard/vscclient.o
	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")

######################################################################

qemu-img.o: qemu-img-cmds.h
@@ -166,6 +163,9 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)

qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o

vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) $(tools-obj-y) qemu-timer-common.o libcacard/vscclient.o
	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")

fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/virtio-9p-marshal.o oslib-posix.o $(trace-obj-y)
fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap

+2 −1
Original line number Diff line number Diff line
@@ -3534,7 +3534,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)

    /* But don't actually force it to the disk with cache=unsafe */
    if (bs->open_flags & BDRV_O_NO_FLUSH) {
        return 0;
        goto flush_parent;
    }

    if (bs->drv->bdrv_co_flush_to_disk) {
@@ -3573,6 +3573,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
    /* Now flush the underlying protocol.  It will also have BDRV_O_NO_FLUSH
     * in the case of cache=unsafe, so there are no useless flushes.
     */
flush_parent:
    return bdrv_co_flush(bs->file);
}

+23 −32
Original line number Diff line number Diff line
@@ -76,6 +76,10 @@ static void
iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
                    void *private_data)
{
    IscsiAIOCB *acb = (IscsiAIOCB *)private_data;

    scsi_free_scsi_task(acb->task);
    acb->task = NULL;
}

static void
@@ -84,15 +88,15 @@ iscsi_aio_cancel(BlockDriverAIOCB *blockacb)
    IscsiAIOCB *acb = (IscsiAIOCB *)blockacb;
    IscsiLun *iscsilun = acb->iscsilun;

    acb->common.cb(acb->common.opaque, -ECANCELED);
    acb->canceled = 1;

    /* send a task mgmt call to the target to cancel the task on the target */
    iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
                                     iscsi_abort_task_cb, NULL);
    acb->common.cb(acb->common.opaque, -ECANCELED);

    /* then also cancel the task locally in libiscsi */
    iscsi_scsi_task_cancel(iscsilun->iscsi, acb->task);
    /* send a task mgmt call to the target to cancel the task on the target
     * this also cancels the task in libiscsi
     */
    iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
                                     iscsi_abort_task_cb, &acb);
}

static AIOPool iscsi_aio_pool = {
@@ -179,11 +183,18 @@ iscsi_readv_writev_bh_cb(void *p)

    qemu_bh_delete(acb->bh);

    if (acb->canceled == 0) {
    if (!acb->canceled) {
        acb->common.cb(acb->common.opaque, acb->status);
    }

    qemu_aio_release(acb);

    if (acb->canceled) {
        return;
    }

    scsi_free_scsi_task(acb->task);
    acb->task = NULL;
}


@@ -197,10 +208,8 @@ iscsi_aio_write16_cb(struct iscsi_context *iscsi, int status,

    g_free(acb->buf);

    if (acb->canceled != 0) {
    if (acb->canceled) {
        qemu_aio_release(acb);
        scsi_free_scsi_task(acb->task);
        acb->task = NULL;
        return;
    }

@@ -212,8 +221,6 @@ iscsi_aio_write16_cb(struct iscsi_context *iscsi, int status,
    }

    iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
    scsi_free_scsi_task(acb->task);
    acb->task = NULL;
}

static int64_t sector_qemu2lun(int64_t sector, IscsiLun *iscsilun)
@@ -298,10 +305,8 @@ iscsi_aio_read16_cb(struct iscsi_context *iscsi, int status,

    trace_iscsi_aio_read16_cb(iscsi, status, acb, acb->canceled);

    if (acb->canceled != 0) {
    if (acb->canceled) {
        qemu_aio_release(acb);
        scsi_free_scsi_task(acb->task);
        acb->task = NULL;
        return;
    }

@@ -313,8 +318,6 @@ iscsi_aio_read16_cb(struct iscsi_context *iscsi, int status,
    }

    iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
    scsi_free_scsi_task(acb->task);
    acb->task = NULL;
}

static BlockDriverAIOCB *
@@ -414,10 +417,8 @@ iscsi_synccache10_cb(struct iscsi_context *iscsi, int status,
{
    IscsiAIOCB *acb = opaque;

    if (acb->canceled != 0) {
    if (acb->canceled) {
        qemu_aio_release(acb);
        scsi_free_scsi_task(acb->task);
        acb->task = NULL;
        return;
    }

@@ -429,8 +430,6 @@ iscsi_synccache10_cb(struct iscsi_context *iscsi, int status,
    }

    iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
    scsi_free_scsi_task(acb->task);
    acb->task = NULL;
}

static BlockDriverAIOCB *
@@ -468,10 +467,8 @@ iscsi_unmap_cb(struct iscsi_context *iscsi, int status,
{
    IscsiAIOCB *acb = opaque;

    if (acb->canceled != 0) {
    if (acb->canceled) {
        qemu_aio_release(acb);
        scsi_free_scsi_task(acb->task);
        acb->task = NULL;
        return;
    }

@@ -483,8 +480,6 @@ iscsi_unmap_cb(struct iscsi_context *iscsi, int status,
    }

    iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
    scsi_free_scsi_task(acb->task);
    acb->task = NULL;
}

static BlockDriverAIOCB *
@@ -528,10 +523,8 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
{
    IscsiAIOCB *acb = opaque;

    if (acb->canceled != 0) {
    if (acb->canceled) {
        qemu_aio_release(acb);
        scsi_free_scsi_task(acb->task);
        acb->task = NULL;
        return;
    }

@@ -560,8 +553,6 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
    }

    iscsi_schedule_bh(iscsi_readv_writev_bh_cb, acb);
    scsi_free_scsi_task(acb->task);
    acb->task = NULL;
}

static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
+24 −22
Original line number Diff line number Diff line
@@ -271,7 +271,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,
out_free_buf:
    qemu_vfree(s->aligned_buf);
out_close:
    close(fd);
    qemu_close(fd);
    return -errno;
}

@@ -376,7 +376,7 @@ static void raw_close(BlockDriverState *bs)
{
    BDRVRawState *s = bs->opaque;
    if (s->fd >= 0) {
        close(s->fd);
        qemu_close(s->fd);
        s->fd = -1;
        if (s->aligned_buf != NULL)
            qemu_vfree(s->aligned_buf);
@@ -572,7 +572,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
        options++;
    }

    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
    fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
                   0644);
    if (fd < 0) {
        result = -errno;
@@ -580,7 +580,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
        if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
            result = -errno;
        }
        if (close(fd) != 0) {
        if (qemu_close(fd) != 0) {
            result = -errno;
        }
    }
@@ -846,11 +846,11 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
        if ( bsdPath[ 0 ] != '\0' ) {
            strcat(bsdPath,"s0");
            /* some CDs don't have a partition 0 */
            fd = open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE);
            fd = qemu_open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE);
            if (fd < 0) {
                bsdPath[strlen(bsdPath)-1] = '1';
            } else {
                close(fd);
                qemu_close(fd);
            }
            filename = bsdPath;
        }
@@ -889,7 +889,7 @@ static int fd_open(BlockDriverState *bs)
    last_media_present = (s->fd >= 0);
    if (s->fd >= 0 &&
        (get_clock() - s->fd_open_time) >= FD_OPEN_TIMEOUT) {
        close(s->fd);
        qemu_close(s->fd);
        s->fd = -1;
#ifdef DEBUG_FLOPPY
        printf("Floppy closed\n");
@@ -903,7 +903,7 @@ static int fd_open(BlockDriverState *bs)
#endif
            return -EIO;
        }
        s->fd = open(bs->filename, s->open_flags & ~O_NONBLOCK);
        s->fd = qemu_open(bs->filename, s->open_flags & ~O_NONBLOCK);
        if (s->fd < 0) {
            s->fd_error_time = get_clock();
            s->fd_got_error = 1;
@@ -977,7 +977,7 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options)
        options++;
    }

    fd = open(filename, O_WRONLY | O_BINARY);
    fd = qemu_open(filename, O_WRONLY | O_BINARY);
    if (fd < 0)
        return -errno;

@@ -988,7 +988,7 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options)
    else if (lseek(fd, 0, SEEK_END) < total_size * BDRV_SECTOR_SIZE)
        ret = -ENOSPC;

    close(fd);
    qemu_close(fd);
    return ret;
}

@@ -1038,7 +1038,7 @@ static int floppy_open(BlockDriverState *bs, const char *filename, int flags)
        return ret;

    /* close fd so that we can reopen it as needed */
    close(s->fd);
    qemu_close(s->fd);
    s->fd = -1;
    s->fd_media_changed = 1;

@@ -1052,10 +1052,12 @@ static int floppy_probe_device(const char *filename)
    struct floppy_struct fdparam;
    struct stat st;

    if (strstart(filename, "/dev/fd", NULL))
    if (strstart(filename, "/dev/fd", NULL) &&
        !strstart(filename, "/dev/fdset/", NULL)) {
        prio = 50;
    }

    fd = open(filename, O_RDONLY | O_NONBLOCK);
    fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
    if (fd < 0) {
        goto out;
    }
@@ -1070,7 +1072,7 @@ static int floppy_probe_device(const char *filename)
        prio = 100;

outc:
    close(fd);
    qemu_close(fd);
out:
    return prio;
}
@@ -1105,14 +1107,14 @@ static void floppy_eject(BlockDriverState *bs, bool eject_flag)
    int fd;

    if (s->fd >= 0) {
        close(s->fd);
        qemu_close(s->fd);
        s->fd = -1;
    }
    fd = open(bs->filename, s->open_flags | O_NONBLOCK);
    fd = qemu_open(bs->filename, s->open_flags | O_NONBLOCK);
    if (fd >= 0) {
        if (ioctl(fd, FDEJECT, 0) < 0)
            perror("FDEJECT");
        close(fd);
        qemu_close(fd);
    }
}

@@ -1158,7 +1160,7 @@ static int cdrom_probe_device(const char *filename)
    int prio = 0;
    struct stat st;

    fd = open(filename, O_RDONLY | O_NONBLOCK);
    fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
    if (fd < 0) {
        goto out;
    }
@@ -1173,7 +1175,7 @@ static int cdrom_probe_device(const char *filename)
        prio = 100;

outc:
    close(fd);
    qemu_close(fd);
out:
    return prio;
}
@@ -1281,8 +1283,8 @@ static int cdrom_reopen(BlockDriverState *bs)
     * FreeBSD seems to not notice sometimes...
     */
    if (s->fd >= 0)
        close(s->fd);
    fd = open(bs->filename, s->open_flags, 0644);
        qemu_close(s->fd);
    fd = qemu_open(bs->filename, s->open_flags, 0644);
    if (fd < 0) {
        s->fd = -1;
        return -EIO;
+3 −3
Original line number Diff line number Diff line
@@ -255,13 +255,13 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
        options++;
    }

    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
    fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
                   0644);
    if (fd < 0)
        return -EIO;
    set_sparse(fd);
    ftruncate(fd, total_size * 512);
    close(fd);
    qemu_close(fd);
    return 0;
}

Loading