From c210a81fd9edc524c45d823e02af95bd24dc1513 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 20 Jan 2017 11:20:18 +0100 Subject: [PATCH] scsi: spdk_scsi_lun_construct should return only new objects This patch makes spdk_scsi_lun_construct behave as documented. spdk_scsi_lun_construct will return only newly created LUN. If LUN with that name already exists, NULL will be returned. Unit test relevant to this behaviour is now changed to show this functionality is now working. Signed-off-by: Tomasz Zawadzki Change-Id: I002903d6f96555c638aba3fa99cc2c2504ced603 --- lib/scsi/lun.c | 3 ++- test/lib/scsi/lun/lun_ut.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/scsi/lun.c b/lib/scsi/lun.c index d382af448..9de263afa 100644 --- a/lib/scsi/lun.c +++ b/lib/scsi/lun.c @@ -280,7 +280,8 @@ spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev) lun = spdk_lun_db_get_lun(name, 0); if (lun) { - return lun; + SPDK_ERRLOG("LUN %s already created\n", lun->name); + return NULL; } lun = calloc(1, sizeof(*lun)); diff --git a/test/lib/scsi/lun/lun_ut.c b/test/lib/scsi/lun/lun_ut.c index 7af3212ec..388fa234d 100644 --- a/test/lib/scsi/lun/lun_ut.c +++ b/test/lib/scsi/lun/lun_ut.c @@ -621,7 +621,7 @@ lun_construct_same_same_twice(void) lun2 = spdk_scsi_lun_construct("lun0", &bdev2); /* Fails to construct the same lun on another bdev and returns NULL */ - CU_ASSERT(lun2 != NULL); /* lun2 should be NULL, this shows it is not currently working */ + CU_ASSERT(lun2 == NULL); lun_destruct(lun);