From f93b3ae720fafe9938015cfd99e263e3c14ace5d Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Mon, 14 Nov 2022 15:33:38 +0300 Subject: [PATCH] scst_copy_mgr: Introduce scst_cm_get_free_lun() Introduce the helper function scst_cm_get_free_lun(), which purpose is to return the next free copy manager LUN. This patch doesn't change any functionality. --- scst/src/scst_copy_mgr.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/scst/src/scst_copy_mgr.c b/scst/src/scst_copy_mgr.c index 8b52974dc..57ff72e37 100644 --- a/scst/src/scst_copy_mgr.c +++ b/scst/src/scst_copy_mgr.c @@ -2541,11 +2541,28 @@ out: return res; } +static uint64_t scst_cm_get_free_lun(void) +{ + uint64_t lun; + + while (1) { + lun = scst_cm_next_lun++; + if (lun == SCST_MAX_LUN) { + scst_cm_next_lun = 0; + continue; + } + + if (scst_cm_is_lun_free(lun)) + break; + } + + return lun; +} + static int scst_cm_dev_register(struct scst_device *dev, uint64_t lun) { int res; struct scst_acg_dev *acg_dev; - bool add_lun; TRACE_ENTRY(); @@ -2561,20 +2578,8 @@ static int scst_cm_dev_register(struct scst_device *dev, uint64_t lun) goto out; } - add_lun = true; - while (1) { - lun = scst_cm_next_lun++; - if (lun == SCST_MAX_LUN) { - scst_cm_next_lun = 0; - continue; - } - if (scst_cm_is_lun_free(lun)) - break; - } - } else - add_lun = false; + lun = scst_cm_get_free_lun(); - if (add_lun) { res = scst_acg_add_lun(scst_cm_tgt->default_acg, scst_cm_tgt->tgt_luns_kobj, dev, lun, SCST_ADD_LUN_CM, &acg_dev);