Commit b276649c authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

vhost: check if file is a socket when creating a controller



This patch makes create_vhost_scsi_controller check if given file is a socket before deleting it

Change-Id: I7a37c12913b461f779732e724c85e2f7b5d67442
Signed-off-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
parent cc294653
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@
#include <stdint.h>
#include <sys/eventfd.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <semaphore.h>

@@ -766,6 +768,7 @@ spdk_vhost_scsi_ctrlr_construct(const char *name, uint64_t cpumask)
	struct spdk_vhost_scsi_ctrlr *vdev;
	unsigned ctrlr_num;
	char path[PATH_MAX];
	struct stat file_stat;

	if (name == NULL) {
		SPDK_ERRLOG("Can't add controller with no name\n");
@@ -799,11 +802,15 @@ spdk_vhost_scsi_ctrlr_construct(const char *name, uint64_t cpumask)
		return -EINVAL;
	}

	/* Register vhost(cuse or user) driver to handle vhost messages. */
	if (access(path, F_OK) != -1) {
		if (unlink(path) != 0)
	/* Register vhost driver to handle vhost messages. */
	if (stat(path, &file_stat) != -1) {
		if (!S_ISSOCK(file_stat.st_mode)) {
			SPDK_ERRLOG("Cannot remove %s: not a socket.\n", path);
			return -EINVAL;
		} else if (unlink(path) != 0) {
			rte_exit(EXIT_FAILURE, "Cannot remove %s.\n", path);
		}
	}

	if (rte_vhost_driver_register(path, 0) != 0) {
		SPDK_ERRLOG("Could not register controller %s with vhost library\n", name);