From 19153e3a65d0e5dd406d15de72fdbeb81fe04231 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 24 Aug 2012 02:15:04 +0000 Subject: [PATCH] Ensure that generated USN is unique git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4471 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index a559ffd33..d9c081dfa 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -4139,11 +4139,12 @@ out: return res; } +/* scst_vdisk_mutex supposed to be held */ static int vdev_create(struct scst_dev_type *devt, const char *name, struct scst_vdisk_dev **res_virt_dev) { int res; - struct scst_vdisk_dev *virt_dev; + struct scst_vdisk_dev *virt_dev, *vv; uint64_t dev_id_num; res = -EEXIST; @@ -4185,6 +4186,15 @@ static int vdev_create(struct scst_dev_type *devt, scnprintf(virt_dev->usn, sizeof(virt_dev->usn), "%llx", dev_id_num); TRACE_DBG("usn %s", virt_dev->usn); + list_for_each_entry(vv, &vdev_list, vdev_list_entry) { + if (strcmp(virt_dev->usn, vv->usn) == 0) { + PRINT_ERROR("New usn %s conflicts with one of dev %s", + virt_dev->usn, vv->name); + res = -EEXIST; + goto out_free; + } + } + *res_virt_dev = virt_dev; res = 0;