diff --git a/src/driver/controller-synology/http/index.js b/src/driver/controller-synology/http/index.js index 3aa19f3..66fe124 100644 --- a/src/driver/controller-synology/http/index.js +++ b/src/driver/controller-synology/http/index.js @@ -8,6 +8,7 @@ class SynologyHttpClient { this.options = JSON.parse(JSON.stringify(options)); this.logger = console; this.doLoginMutex = new Mutex(); + this.apiSerializeMutex = new Mutex(); if (false) { setInterval(() => { @@ -50,6 +51,7 @@ class SynologyHttpClient { const client = this; const isAuth = data.api == "SYNO.API.Auth" && data.method == "login"; let sid; + let apiMutexRelease; if (!isAuth) { sid = await this.doLoginMutex.runExclusive(async () => { return await this.login(); @@ -58,8 +60,14 @@ class SynologyHttpClient { const invoke_options = options; + if (!isAuth) { + if (this.options.serialize) { + apiMutexRelease = await this.apiSerializeMutex.acquire(); + } + } + return new Promise((resolve, reject) => { - if (data.api != "SYNO.API.Auth") { + if (!isAuth) { data._sid = sid; } @@ -93,36 +101,42 @@ class SynologyHttpClient { break; } - request(options, function (error, response, body) { - client.log_response(...arguments, options); + try { + request(options, function (error, response, body) { + client.log_response(...arguments, options); - if (error) { - reject(error); - } - - if ( - typeof response.body !== "object" && - response.body !== null && - response.headers["content-type"] && - response.headers["content-type"].includes("application/json") - ) { - response.body = JSON.parse(response.body); - } - - if (response.statusCode > 299 || response.statusCode < 200) { - reject(response); - } - - if (response.body.success === false) { - // remove invalid sid - if (response.body.error.code == 119 && sid == client.sid) { - client.sid = null; + if (error) { + reject(error); } - reject(response); - } - resolve(response); - }); + if ( + typeof response.body !== "object" && + response.body !== null && + response.headers["content-type"] && + response.headers["content-type"].includes("application/json") + ) { + response.body = JSON.parse(response.body); + } + + if (response.statusCode > 299 || response.statusCode < 200) { + reject(response); + } + + if (response.body.success === false) { + // remove invalid sid + if (response.body.error.code == 119 && sid == client.sid) { + client.sid = null; + } + reject(response); + } + + resolve(response); + }); + } finally { + if (typeof apiMutexRelease == "function") { + apiMutexRelease(); + } + } }); } diff --git a/src/driver/controller-synology/index.js b/src/driver/controller-synology/index.js index b3cdf77..6504516 100644 --- a/src/driver/controller-synology/index.js +++ b/src/driver/controller-synology/index.js @@ -305,6 +305,8 @@ class ControllerSynologyDriver extends CsiBaseDriver { ); } + target_id = target.target_id; + // check if mapping of lun <-> target already exists lun_mapping = target.mapped_luns.find((lun) => { return lun.lun_uuid == lun_uuid; @@ -411,7 +413,7 @@ class ControllerSynologyDriver extends CsiBaseDriver { ); break; case "iscsi": - //await httpClient.DeleteAllLuns(); + await httpClient.DeleteAllLuns(); let iscsiName = driver.buildIscsiName(name); let iqn = driver.options.iscsi.baseiqn + iscsiName; @@ -427,25 +429,30 @@ class ControllerSynologyDriver extends CsiBaseDriver { // therefore we continue to search for the lun after delete success call to ensure full deletion await httpClient.DeleteLun(lun_uuid); - let currentCheck = 0; - let settleMaxRetries = driver.options.api.lunDelete.settleMaxRetries || 6; - let settleSeconds = driver.options.api.lunDelete.settleSeconds || 5; - let waitTimeBetweenChecks = settleSeconds * 1000; + let settleEnabled = driver.options.api.lunDelete.settleEnabled; - await sleep(waitTimeBetweenChecks); - lun_uuid = await httpClient.GetLunUUIDByName(iscsiName); - - while (currentCheck <= settleMaxRetries && lun_uuid) { - currentCheck++; + if (settleEnabled) { + let currentCheck = 0; + let settleMaxRetries = + driver.options.api.lunDelete.settleMaxRetries || 6; + let settleSeconds = driver.options.api.lunDelete.settleSeconds || 5; + let waitTimeBetweenChecks = settleSeconds * 1000; + await sleep(waitTimeBetweenChecks); lun_uuid = await httpClient.GetLunUUIDByName(iscsiName); - } - - if (lun_uuid) { - throw new GrpcError( - grpc.status.UNKNOWN, - `failed to remove lun: ${lun_uuid}` - ); + + while (currentCheck <= settleMaxRetries && lun_uuid) { + currentCheck++; + await sleep(waitTimeBetweenChecks); + lun_uuid = await httpClient.GetLunUUIDByName(iscsiName); + } + + if (lun_uuid) { + throw new GrpcError( + grpc.status.UNKNOWN, + `failed to remove lun: ${lun_uuid}` + ); + } } } break;