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: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
This commit is contained in:
parent
cc294653ca
commit
b276649c98
@ -36,6 +36,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/eventfd.h>
|
#include <sys/eventfd.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <semaphore.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;
|
struct spdk_vhost_scsi_ctrlr *vdev;
|
||||||
unsigned ctrlr_num;
|
unsigned ctrlr_num;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
struct stat file_stat;
|
||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
SPDK_ERRLOG("Can't add controller with no name\n");
|
SPDK_ERRLOG("Can't add controller with no name\n");
|
||||||
@ -799,10 +802,14 @@ spdk_vhost_scsi_ctrlr_construct(const char *name, uint64_t cpumask)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register vhost(cuse or user) driver to handle vhost messages. */
|
/* Register vhost driver to handle vhost messages. */
|
||||||
if (access(path, F_OK) != -1) {
|
if (stat(path, &file_stat) != -1) {
|
||||||
if (unlink(path) != 0)
|
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);
|
rte_exit(EXIT_FAILURE, "Cannot remove %s.\n", path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rte_vhost_driver_register(path, 0) != 0) {
|
if (rte_vhost_driver_register(path, 0) != 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user