If you try to make a device implementation that can handle multiple
connections and allow disconnections (which requires overriding the
VHOST_USER_NONE handling), then glib will warn that we remove a src
while it's still on the mainloop, and will poll() an FD that doesn't
exist anymore.
Fix this by making vug_source_new() require pairing with the new
vug_source_destroy() so we can keep the GSource referenced in the
meantime.
Note that this requires calling the new API in vhost-user-input.
vhost-user-gpu also uses vug_source_new(), but never seems to free
the result at all, so I haven't changed anything there.
Fixes: 8bb7ddb78a1c ("libvhost-user: add glib source helper")
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Message-Id: <20200123081708.7817-3-johannes@sipsolutions.net>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
		
	
			
		
			
				
	
	
		
			37 lines
		
	
	
		
			926 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			926 B
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 * Vhost User library
 | 
						|
 *
 | 
						|
 * Copyright (c) 2016 Nutanix Inc. All rights reserved.
 | 
						|
 * Copyright (c) 2017 Red Hat, Inc.
 | 
						|
 *
 | 
						|
 * Authors:
 | 
						|
 *  Marc-André Lureau <mlureau@redhat.com>
 | 
						|
 *  Felipe Franciosi <felipe@nutanix.com>
 | 
						|
 *
 | 
						|
 * This work is licensed under the terms of the GNU GPL, version 2 or
 | 
						|
 * later.  See the COPYING file in the top-level directory.
 | 
						|
 */
 | 
						|
 | 
						|
#ifndef LIBVHOST_USER_GLIB_H
 | 
						|
#define LIBVHOST_USER_GLIB_H
 | 
						|
 | 
						|
#include <glib.h>
 | 
						|
#include "libvhost-user.h"
 | 
						|
 | 
						|
typedef struct VugDev {
 | 
						|
    VuDev parent;
 | 
						|
 | 
						|
    GHashTable *fdmap; /* fd -> gsource */
 | 
						|
    GSource *src;
 | 
						|
} VugDev;
 | 
						|
 | 
						|
bool vug_init(VugDev *dev, uint16_t max_queues, int socket,
 | 
						|
              vu_panic_cb panic, const VuDevIface *iface);
 | 
						|
void vug_deinit(VugDev *dev);
 | 
						|
 | 
						|
GSource *vug_source_new(VugDev *dev, int fd, GIOCondition cond,
 | 
						|
                        vu_watch_cb vu_cb, gpointer data);
 | 
						|
void vug_source_destroy(GSource *src);
 | 
						|
 | 
						|
#endif /* LIBVHOST_USER_GLIB_H */
 |