introduce ability to serial api access, allow toggle settle
Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
parent
ff73606b55
commit
eb2bb1dc01
|
|
@ -8,6 +8,7 @@ class SynologyHttpClient {
|
||||||
this.options = JSON.parse(JSON.stringify(options));
|
this.options = JSON.parse(JSON.stringify(options));
|
||||||
this.logger = console;
|
this.logger = console;
|
||||||
this.doLoginMutex = new Mutex();
|
this.doLoginMutex = new Mutex();
|
||||||
|
this.apiSerializeMutex = new Mutex();
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
|
@ -50,6 +51,7 @@ class SynologyHttpClient {
|
||||||
const client = this;
|
const client = this;
|
||||||
const isAuth = data.api == "SYNO.API.Auth" && data.method == "login";
|
const isAuth = data.api == "SYNO.API.Auth" && data.method == "login";
|
||||||
let sid;
|
let sid;
|
||||||
|
let apiMutexRelease;
|
||||||
if (!isAuth) {
|
if (!isAuth) {
|
||||||
sid = await this.doLoginMutex.runExclusive(async () => {
|
sid = await this.doLoginMutex.runExclusive(async () => {
|
||||||
return await this.login();
|
return await this.login();
|
||||||
|
|
@ -58,8 +60,14 @@ class SynologyHttpClient {
|
||||||
|
|
||||||
const invoke_options = options;
|
const invoke_options = options;
|
||||||
|
|
||||||
|
if (!isAuth) {
|
||||||
|
if (this.options.serialize) {
|
||||||
|
apiMutexRelease = await this.apiSerializeMutex.acquire();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (data.api != "SYNO.API.Auth") {
|
if (!isAuth) {
|
||||||
data._sid = sid;
|
data._sid = sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,36 +101,42 @@ class SynologyHttpClient {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
request(options, function (error, response, body) {
|
try {
|
||||||
client.log_response(...arguments, options);
|
request(options, function (error, response, body) {
|
||||||
|
client.log_response(...arguments, options);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(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;
|
|
||||||
}
|
}
|
||||||
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,8 @@ class ControllerSynologyDriver extends CsiBaseDriver {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target_id = target.target_id;
|
||||||
|
|
||||||
// check if mapping of lun <-> target already exists
|
// check if mapping of lun <-> target already exists
|
||||||
lun_mapping = target.mapped_luns.find((lun) => {
|
lun_mapping = target.mapped_luns.find((lun) => {
|
||||||
return lun.lun_uuid == lun_uuid;
|
return lun.lun_uuid == lun_uuid;
|
||||||
|
|
@ -411,7 +413,7 @@ class ControllerSynologyDriver extends CsiBaseDriver {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "iscsi":
|
case "iscsi":
|
||||||
//await httpClient.DeleteAllLuns();
|
await httpClient.DeleteAllLuns();
|
||||||
|
|
||||||
let iscsiName = driver.buildIscsiName(name);
|
let iscsiName = driver.buildIscsiName(name);
|
||||||
let iqn = driver.options.iscsi.baseiqn + iscsiName;
|
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
|
// therefore we continue to search for the lun after delete success call to ensure full deletion
|
||||||
await httpClient.DeleteLun(lun_uuid);
|
await httpClient.DeleteLun(lun_uuid);
|
||||||
|
|
||||||
let currentCheck = 0;
|
let settleEnabled = driver.options.api.lunDelete.settleEnabled;
|
||||||
let settleMaxRetries = driver.options.api.lunDelete.settleMaxRetries || 6;
|
|
||||||
let settleSeconds = driver.options.api.lunDelete.settleSeconds || 5;
|
|
||||||
let waitTimeBetweenChecks = settleSeconds * 1000;
|
|
||||||
|
|
||||||
await sleep(waitTimeBetweenChecks);
|
if (settleEnabled) {
|
||||||
lun_uuid = await httpClient.GetLunUUIDByName(iscsiName);
|
let currentCheck = 0;
|
||||||
|
let settleMaxRetries =
|
||||||
while (currentCheck <= settleMaxRetries && lun_uuid) {
|
driver.options.api.lunDelete.settleMaxRetries || 6;
|
||||||
currentCheck++;
|
let settleSeconds = driver.options.api.lunDelete.settleSeconds || 5;
|
||||||
|
let waitTimeBetweenChecks = settleSeconds * 1000;
|
||||||
|
|
||||||
await sleep(waitTimeBetweenChecks);
|
await sleep(waitTimeBetweenChecks);
|
||||||
lun_uuid = await httpClient.GetLunUUIDByName(iscsiName);
|
lun_uuid = await httpClient.GetLunUUIDByName(iscsiName);
|
||||||
}
|
|
||||||
|
while (currentCheck <= settleMaxRetries && lun_uuid) {
|
||||||
if (lun_uuid) {
|
currentCheck++;
|
||||||
throw new GrpcError(
|
await sleep(waitTimeBetweenChecks);
|
||||||
grpc.status.UNKNOWN,
|
lun_uuid = await httpClient.GetLunUUIDByName(iscsiName);
|
||||||
`failed to remove lun: ${lun_uuid}`
|
}
|
||||||
);
|
|
||||||
|
if (lun_uuid) {
|
||||||
|
throw new GrpcError(
|
||||||
|
grpc.status.UNKNOWN,
|
||||||
|
`failed to remove lun: ${lun_uuid}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue