Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into…
Browse files Browse the repository at this point in the history
… staging

* SCSI scanner support
* fixes to qemu-char and net exit
* FreeBSD fixes
* Other small bugfixes

# gpg: Signature made Wed 13 Jul 2016 12:30:11 BST
# gpg:                using RSA key 0xBFFBD25F78C7AE83
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>"
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>"
# Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4  E2F7 7E15 100C CD36 69B1
#      Subkey fingerprint: F133 3857 4B66 2389 866C  7682 BFFB D25F 78C7 AE83

* remotes/bonzini/tags/for-upstream:
  hostmem: detect host backend memory is being used properly
  hostmem: fix QEMU crash by 'info memdev'
  char: do not use atexit cleanup handler
  net: do not use atexit for cleanup
  slirp: use exit notifier for slirp_smb_cleanup
  tap: use an exit notifier to call down_script
  util: Fix MIN_NON_ZERO
  qemu-sockets: use qapi_free_SocketAddress in cleanup
  disas: avoid including everything in headers compiled from C++
  json-streamer: fix double-free on exiting during a parse
  main-loop: check return value before using pointer
  Use "-s" instead of "--quiet" to resolve non-fatal build error on FreeBSD.
  scsi-bus: Use longer sense buffer with scanners
  scsi-bus: Add SCSI scanner support

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Jul 14, 2016
2 parents 9358450 + 2aece63 commit 190c93c
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -185,7 +185,7 @@ qemu-version.h: FORCE
printf '""\n'; \
fi; \
fi) > $@.tmp)
$(call quiet-command, cmp --quiet $@ $@.tmp || mv $@.tmp $@)
$(call quiet-command, cmp -s $@ $@.tmp || mv $@.tmp $@)

config-host.h: config-host.h-timestamp
config-host.h-timestamp: config-host.mak
Expand Down
37 changes: 25 additions & 12 deletions backends/hostmem.c
Expand Up @@ -64,6 +64,14 @@ host_memory_backend_set_size(Object *obj, Visitor *v, const char *name,
error_propagate(errp, local_err);
}

static uint16List **host_memory_append_node(uint16List **node,
unsigned long value)
{
*node = g_malloc0(sizeof(**node));
(*node)->value = value;
return &(*node)->next;
}

static void
host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
Expand All @@ -74,25 +82,23 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
unsigned long value;

value = find_first_bit(backend->host_nodes, MAX_NODES);

node = host_memory_append_node(node, value);

if (value == MAX_NODES) {
return;
goto out;
}

*node = g_malloc0(sizeof(**node));
(*node)->value = value;
node = &(*node)->next;

do {
value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1);
if (value == MAX_NODES) {
break;
}

*node = g_malloc0(sizeof(**node));
(*node)->value = value;
node = &(*node)->next;
node = host_memory_append_node(node, value);
} while (true);

out:
visit_type_uint16List(v, name, &host_nodes, errp);
}

Expand Down Expand Up @@ -258,6 +264,16 @@ host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp)
return memory_region_size(&backend->mr) ? &backend->mr : NULL;
}

void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped)
{
backend->is_mapped = mapped;
}

bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
{
return backend->is_mapped;
}

static void
host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
{
Expand Down Expand Up @@ -335,10 +351,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
static bool
host_memory_backend_can_be_deleted(UserCreatable *uc, Error **errp)
{
MemoryRegion *mr;

mr = host_memory_backend_get_memory(MEMORY_BACKEND(uc), errp);
if (memory_region_is_mapped(mr)) {
if (host_memory_backend_is_mapped(MEMORY_BACKEND(uc))) {
return false;
} else {
return true;
Expand Down
18 changes: 11 additions & 7 deletions hw/mem/pc-dimm.c
Expand Up @@ -369,22 +369,16 @@ static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name,
static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name,
Object *val, Error **errp)
{
MemoryRegion *mr;
Error *local_err = NULL;

mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), &local_err);
if (local_err) {
goto out;
}
if (memory_region_is_mapped(mr)) {
if (host_memory_backend_is_mapped(MEMORY_BACKEND(val))) {
char *path = object_get_canonical_path_component(val);
error_setg(&local_err, "can't use already busy memdev: %s", path);
g_free(path);
} else {
qdev_prop_allow_set_link_before_realize(obj, name, val, &local_err);
}

out:
error_propagate(errp, local_err);
}

Expand Down Expand Up @@ -421,6 +415,15 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
if (ddc->realize) {
ddc->realize(dimm, errp);
}

host_memory_backend_set_mapped(dimm->hostmem, true);
}

static void pc_dimm_unrealize(DeviceState *dev, Error **errp)
{
PCDIMMDevice *dimm = PC_DIMM(dev);

host_memory_backend_set_mapped(dimm->hostmem, false);
}

static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm)
Expand All @@ -439,6 +442,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);

dc->realize = pc_dimm_realize;
dc->unrealize = pc_dimm_unrealize;
dc->props = pc_dimm_properties;
dc->desc = "DIMM memory module";

Expand Down
14 changes: 10 additions & 4 deletions hw/misc/ivshmem.c
Expand Up @@ -1008,10 +1008,7 @@ static const TypeInfo ivshmem_common_info = {
static void ivshmem_check_memdev_is_busy(Object *obj, const char *name,
Object *val, Error **errp)
{
MemoryRegion *mr;

mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), &error_abort);
if (memory_region_is_mapped(mr)) {
if (host_memory_backend_is_mapped(MEMORY_BACKEND(val))) {
char *path = object_get_canonical_path_component(val);
error_setg(errp, "can't use already busy memdev: %s", path);
g_free(path);
Expand Down Expand Up @@ -1060,6 +1057,14 @@ static void ivshmem_plain_realize(PCIDevice *dev, Error **errp)
}

ivshmem_common_realize(dev, errp);
host_memory_backend_set_mapped(s->hostmem, true);
}

static void ivshmem_plain_exit(PCIDevice *pci_dev)
{
IVShmemState *s = IVSHMEM_COMMON(pci_dev);

host_memory_backend_set_mapped(s->hostmem, false);
}

static void ivshmem_plain_class_init(ObjectClass *klass, void *data)
Expand All @@ -1068,6 +1073,7 @@ static void ivshmem_plain_class_init(ObjectClass *klass, void *data)
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

k->realize = ivshmem_plain_realize;
k->exit = ivshmem_plain_exit;
dc->props = ivshmem_plain_properties;
dc->vmsd = &ivshmem_plain_vmsd;
}
Expand Down
41 changes: 40 additions & 1 deletion hw/scsi/scsi-bus.c
Expand Up @@ -461,6 +461,14 @@ static bool scsi_target_emulate_inquiry(SCSITargetReq *r)
return true;
}

static size_t scsi_sense_len(SCSIRequest *req)
{
if (req->dev->type == TYPE_SCANNER)
return SCSI_SENSE_LEN_SCANNER;
else
return SCSI_SENSE_LEN;
}

static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf)
{
SCSITargetReq *r = DO_UPCAST(SCSITargetReq, req, req);
Expand All @@ -477,7 +485,7 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf)
}
break;
case REQUEST_SENSE:
scsi_target_alloc_buf(&r->req, SCSI_SENSE_LEN);
scsi_target_alloc_buf(&r->req, scsi_sense_len(req));
r->len = scsi_device_get_sense(r->req.dev, r->buf,
MIN(req->cmd.xfer, r->buf_len),
(req->cmd.buf[1] & 1) == 0);
Expand Down Expand Up @@ -1132,6 +1140,29 @@ static int scsi_req_medium_changer_xfer(SCSICommand *cmd, SCSIDevice *dev, uint8
return 0;
}

static int scsi_req_scanner_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
{
switch (buf[0]) {
/* Scanner commands */
case OBJECT_POSITION:
cmd->xfer = 0;
break;
case SCAN:
cmd->xfer = buf[4];
break;
case READ_10:
case SEND:
case GET_WINDOW:
case SET_WINDOW:
cmd->xfer = buf[8] | (buf[7] << 8) | (buf[6] << 16);
break;
default:
/* GET_DATA_BUFFER_STATUS xfer handled by scsi_req_xfer */
return scsi_req_xfer(cmd, dev, buf);
}

return 0;
}

static void scsi_cmd_xfer_mode(SCSICommand *cmd)
{
Expand Down Expand Up @@ -1178,6 +1209,11 @@ static void scsi_cmd_xfer_mode(SCSICommand *cmd)
case SEND_DVD_STRUCTURE:
case PERSISTENT_RESERVE_OUT:
case MAINTENANCE_OUT:
case SET_WINDOW:
case SCAN:
/* SCAN conflicts with START_STOP. START_STOP has cmd->xfer set to 0 for
* non-scanner devices, so we only get here for SCAN and not for START_STOP.
*/
cmd->mode = SCSI_XFER_TO_DEV;
break;
case ATA_PASSTHROUGH_12:
Expand Down Expand Up @@ -1258,6 +1294,9 @@ int scsi_req_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf)
case TYPE_MEDIUM_CHANGER:
rc = scsi_req_medium_changer_xfer(cmd, dev, buf);
break;
case TYPE_SCANNER:
rc = scsi_req_scanner_length(cmd, dev, buf);
break;
default:
rc = scsi_req_xfer(cmd, dev, buf);
break;
Expand Down
6 changes: 6 additions & 0 deletions include/block/scsi.h
Expand Up @@ -49,24 +49,30 @@
#define ERASE 0x19
#define MODE_SENSE 0x1a
#define LOAD_UNLOAD 0x1b
#define SCAN 0x1b
#define START_STOP 0x1b
#define RECEIVE_DIAGNOSTIC 0x1c
#define SEND_DIAGNOSTIC 0x1d
#define ALLOW_MEDIUM_REMOVAL 0x1e
#define SET_WINDOW 0x24
#define READ_CAPACITY_10 0x25
#define GET_WINDOW 0x25
#define READ_10 0x28
#define WRITE_10 0x2a
#define SEND 0x2a
#define SEEK_10 0x2b
#define LOCATE_10 0x2b
#define POSITION_TO_ELEMENT 0x2b
#define WRITE_VERIFY_10 0x2e
#define VERIFY_10 0x2f
#define SEARCH_HIGH 0x30
#define SEARCH_EQUAL 0x31
#define OBJECT_POSITION 0x31
#define SEARCH_LOW 0x32
#define SET_LIMITS 0x33
#define PRE_FETCH 0x34
#define READ_POSITION 0x34
#define GET_DATA_BUFFER_STATUS 0x34
#define SYNCHRONIZE_CACHE 0x35
#define LOCK_UNLOCK_CACHE 0x36
#define INITIALIZE_ELEMENT_STATUS_WITH_RANGE 0x37
Expand Down
2 changes: 1 addition & 1 deletion include/disas/bfd.h
Expand Up @@ -9,7 +9,7 @@
#ifndef DISAS_BFD_H
#define DISAS_BFD_H

#include "qemu-common.h"
#include "qemu/fprintf-fn.h"

typedef void *PTR;
typedef uint64_t bfd_vma;
Expand Down
7 changes: 4 additions & 3 deletions include/hw/scsi/scsi.h
Expand Up @@ -8,9 +8,10 @@

#define MAX_SCSI_DEVS 255

#define SCSI_CMD_BUF_SIZE 16
#define SCSI_SENSE_LEN 18
#define SCSI_INQUIRY_LEN 36
#define SCSI_CMD_BUF_SIZE 16
#define SCSI_SENSE_LEN 18
#define SCSI_SENSE_LEN_SCANNER 32
#define SCSI_INQUIRY_LEN 36

typedef struct SCSIBus SCSIBus;
typedef struct SCSIBusInfo SCSIBusInfo;
Expand Down
3 changes: 2 additions & 1 deletion include/qemu/osdep.h
Expand Up @@ -151,7 +151,8 @@ extern int daemon(int, int);
/* Minimum function that returns zero only iff both values are zero.
* Intended for use with unsigned values only. */
#ifndef MIN_NON_ZERO
#define MIN_NON_ZERO(a, b) (((a) != 0 && (a) < (b)) ? (a) : (b))
#define MIN_NON_ZERO(a, b) ((a) == 0 ? (b) : \
((b) == 0 ? (a) : (MIN(a, b))))
#endif

/* Round number down to multiple */
Expand Down
7 changes: 7 additions & 0 deletions include/sysemu/char.h
Expand Up @@ -151,6 +151,13 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename,
*/
void qemu_chr_disconnect(CharDriverState *chr);

/**
* @qemu_chr_cleanup:
*
* Delete all chardevs (when leaving qemu)
*/
void qemu_chr_cleanup(void);

/**
* @qemu_chr_new_noreplay:
*
Expand Down
4 changes: 3 additions & 1 deletion include/sysemu/hostmem.h
Expand Up @@ -54,7 +54,7 @@ struct HostMemoryBackend {
/* protected */
uint64_t size;
bool merge, dump;
bool prealloc, force_prealloc;
bool prealloc, force_prealloc, is_mapped;
DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
HostMemPolicy policy;

Expand All @@ -64,4 +64,6 @@ struct HostMemoryBackend {
MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend,
Error **errp);

void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
#endif
2 changes: 1 addition & 1 deletion main-loop.c
Expand Up @@ -154,11 +154,11 @@ int qemu_init_main_loop(Error **errp)
}

qemu_aio_context = aio_context_new(&local_error);
qemu_notify_bh = qemu_bh_new(notify_event_cb, NULL);
if (!qemu_aio_context) {
error_propagate(errp, local_error);
return -EMFILE;
}
qemu_notify_bh = qemu_bh_new(notify_event_cb, NULL);
gpollfds = g_array_new(FALSE, FALSE, sizeof(GPollFD));
src = aio_get_g_source(qemu_aio_context);
g_source_attach(src, NULL);
Expand Down
11 changes: 11 additions & 0 deletions net/slirp.c
Expand Up @@ -38,6 +38,7 @@
#include "slirp/libslirp.h"
#include "slirp/ip6.h"
#include "sysemu/char.h"
#include "sysemu/sysemu.h"
#include "qemu/cutils.h"

static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
Expand Down Expand Up @@ -76,6 +77,7 @@ typedef struct SlirpState {
NetClientState nc;
QTAILQ_ENTRY(SlirpState) entry;
Slirp *slirp;
Notifier exit_notifier;
#ifndef _WIN32
char smb_dir[128];
#endif
Expand Down Expand Up @@ -118,11 +120,18 @@ static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_t
return size;
}

static void slirp_smb_exit(Notifier *n, void *data)
{
SlirpState *s = container_of(n, SlirpState, exit_notifier);
slirp_smb_cleanup(s);
}

static void net_slirp_cleanup(NetClientState *nc)
{
SlirpState *s = DO_UPCAST(SlirpState, nc, nc);

slirp_cleanup(s->slirp);
qemu_remove_exit_notifier(&s->exit_notifier);
slirp_smb_cleanup(s);
QTAILQ_REMOVE(&slirp_stacks, s, entry);
}
Expand Down Expand Up @@ -349,6 +358,8 @@ static int net_slirp_init(NetClientState *peer, const char *model,
}
#endif

s->exit_notifier.notify = slirp_smb_exit;
qemu_add_exit_notifier(&s->exit_notifier);
return 0;

error:
Expand Down

0 comments on commit 190c93c

Please sign in to comment.