better delete race-condition handling, resize capacity for zvols

This commit is contained in:
Travis Glenn Hansen 2020-11-29 22:59:32 -07:00
parent 8cde1a1979
commit 001301d53e
2 changed files with 136 additions and 104 deletions

View File

@ -1012,7 +1012,11 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver {
await this.expandVolume(call, datasetName); await this.expandVolume(call, datasetName);
return { return {
capacity_bytes: this.options.zfs.datasetEnableQuotas ? capacity_bytes : 0, capacity_bytes:
this.options.zfs.datasetEnableQuotas ||
driverZfsResourceType == "volume"
? capacity_bytes
: 0,
node_expansion_required: driverZfsResourceType == "volume" ? true : false, node_expansion_required: driverZfsResourceType == "volume" ? true : false,
}; };
} }

View File

@ -1066,12 +1066,9 @@ class FreeNASDriver extends ControllerZfsSshBaseDriver {
shareId = properties[FREENAS_NFS_SHARE_PROPERTY_NAME].value; shareId = properties[FREENAS_NFS_SHARE_PROPERTY_NAME].value;
// remove nfs share // only remove if the process has not succeeded already
if ( if (zb.helpers.isPropertyValueSet(shareId)) {
properties && // remove nfs share
properties[FREENAS_NFS_SHARE_PROPERTY_NAME] &&
properties[FREENAS_NFS_SHARE_PROPERTY_NAME].value != "-"
) {
switch (apiVersion) { switch (apiVersion) {
case 1: case 1:
case 2: case 2:
@ -1113,6 +1110,13 @@ class FreeNASDriver extends ControllerZfsSshBaseDriver {
} body: ${JSON.stringify(response.body)}` } body: ${JSON.stringify(response.body)}`
); );
} }
// remove property to prevent delete race conditions
// due to id re-use by FreeNAS/TrueNAS
await zb.zfs.inherit(
datasetName,
FREENAS_NFS_SHARE_PROPERTY_NAME
);
} }
} }
break; break;
@ -1141,12 +1145,9 @@ class FreeNASDriver extends ControllerZfsSshBaseDriver {
shareId = properties[FREENAS_SMB_SHARE_PROPERTY_NAME].value; shareId = properties[FREENAS_SMB_SHARE_PROPERTY_NAME].value;
// remove smb share // only remove if the process has not succeeded already
if ( if (zb.helpers.isPropertyValueSet(shareId)) {
properties && // remove smb share
properties[FREENAS_SMB_SHARE_PROPERTY_NAME] &&
properties[FREENAS_SMB_SHARE_PROPERTY_NAME].value != "-"
) {
switch (apiVersion) { switch (apiVersion) {
case 1: case 1:
case 2: case 2:
@ -1191,6 +1192,13 @@ class FreeNASDriver extends ControllerZfsSshBaseDriver {
} body: ${JSON.stringify(response.body)}` } body: ${JSON.stringify(response.body)}`
); );
} }
// remove property to prevent delete race conditions
// due to id re-use by FreeNAS/TrueNAS
await zb.zfs.inherit(
datasetName,
FREENAS_SMB_SHARE_PROPERTY_NAME
);
} }
} }
break; break;
@ -1233,112 +1241,132 @@ class FreeNASDriver extends ControllerZfsSshBaseDriver {
switch (apiVersion) { switch (apiVersion) {
case 1: case 1:
case 2: case 2:
// https://jira.ixsystems.com/browse/NAS-103952 // only remove if the process has not succeeded already
if (zb.helpers.isPropertyValueSet(targetId)) {
// https://jira.ixsystems.com/browse/NAS-103952
// v1 - /services/iscsi/target/{id}/ // v1 - /services/iscsi/target/{id}/
// v2 - /iscsi/target/id/{id} // v2 - /iscsi/target/id/{id}
endpoint = ""; endpoint = "";
if (apiVersion == 1) { if (apiVersion == 1) {
endpoint += "/services"; endpoint += "/services";
}
endpoint += "/iscsi/target/";
if (apiVersion == 2) {
endpoint += "id/";
}
endpoint += targetId;
response = await httpClient.get(endpoint);
// assume is gone for now
if ([404, 500].includes(response.statusCode)) {
} else {
deleteAsset = true;
assetName = null;
// checking if set for backwards compatibility
if (zb.helpers.isPropertyValueSet(iscsiName)) {
switch (apiVersion) {
case 1:
assetName = response.body.iscsi_target_name;
break;
case 2:
assetName = response.body.name;
break;
}
if (assetName != iscsiName) {
deleteAsset = false;
}
} }
endpoint += "/iscsi/target/";
if (apiVersion == 2) {
endpoint += "id/";
}
endpoint += targetId;
response = await httpClient.get(endpoint);
if (deleteAsset) { // assume is gone for now
response = await httpClient.delete(endpoint); if ([404, 500].includes(response.statusCode)) {
if (![200, 204].includes(response.statusCode)) { } else {
throw new GrpcError( deleteAsset = true;
grpc.status.UNKNOWN, assetName = null;
`received error deleting iscsi target - extent: ${targetId} code: ${
response.statusCode // checking if set for backwards compatibility
} body: ${JSON.stringify(response.body)}` if (zb.helpers.isPropertyValueSet(iscsiName)) {
switch (apiVersion) {
case 1:
assetName = response.body.iscsi_target_name;
break;
case 2:
assetName = response.body.name;
break;
}
if (assetName != iscsiName) {
deleteAsset = false;
}
}
if (deleteAsset) {
response = await httpClient.delete(endpoint);
if (![200, 204].includes(response.statusCode)) {
throw new GrpcError(
grpc.status.UNKNOWN,
`received error deleting iscsi target - extent: ${targetId} code: ${
response.statusCode
} body: ${JSON.stringify(response.body)}`
);
}
// remove property to prevent delete race conditions
// due to id re-use by FreeNAS/TrueNAS
await zb.zfs.inherit(
datasetName,
FREENAS_ISCSI_TARGET_ID_PROPERTY_NAME
);
} else {
this.ctx.logger.debug(
"not deleting iscsitarget asset as it appears ID %s has been re-used: zfs name - %s, iscsitarget name - %s",
targetId,
iscsiName,
assetName
); );
} }
}
}
// only remove if the process has not succeeded already
if (zb.helpers.isPropertyValueSet(extentId)) {
// v1 - /services/iscsi/targettoextent/{id}/
// v2 - /iscsi/targetextent/id/{id}
if (apiVersion == 1) {
endpoint = "/services/iscsi/extent/";
} else { } else {
this.ctx.logger.debug( endpoint = "/iscsi/extent/id/";
"not deleting iscsitarget asset as it appears ID %s has been re-used: zfs name - %s, iscsitarget name - %s",
targetId,
iscsiName,
assetName
);
} }
} endpoint += extentId;
response = await httpClient.get(endpoint);
// v1 - /services/iscsi/targettoextent/{id}/ // assume is gone for now
// v2 - /iscsi/targetextent/id/{id} if ([404, 500].includes(response.statusCode)) {
if (apiVersion == 1) { } else {
endpoint = "/services/iscsi/extent/"; deleteAsset = true;
} else { assetName = null;
endpoint = "/iscsi/extent/id/";
}
endpoint += extentId;
response = await httpClient.get(endpoint);
// assume is gone for now // checking if set for backwards compatibility
if ([404, 500].includes(response.statusCode)) { if (zb.helpers.isPropertyValueSet(iscsiName)) {
} else { switch (apiVersion) {
deleteAsset = true; case 1:
assetName = null; assetName = response.body.iscsi_target_extent_name;
break;
case 2:
assetName = response.body.name;
break;
}
// checking if set for backwards compatibility if (assetName != iscsiName) {
if (zb.helpers.isPropertyValueSet(iscsiName)) { deleteAsset = false;
switch (apiVersion) { }
case 1:
assetName = response.body.iscsi_target_extent_name;
break;
case 2:
assetName = response.body.name;
break;
} }
if (assetName != iscsiName) { if (deleteAsset) {
deleteAsset = false; response = await httpClient.delete(endpoint);
} if (![200, 204].includes(response.statusCode)) {
} throw new GrpcError(
grpc.status.UNKNOWN,
`received error deleting iscsi extent - extent: ${extentId} code: ${
response.statusCode
} body: ${JSON.stringify(response.body)}`
);
}
if (deleteAsset) { // remove property to prevent delete race conditions
response = await httpClient.delete(endpoint); // due to id re-use by FreeNAS/TrueNAS
if (![200, 204].includes(response.statusCode)) { await zb.zfs.inherit(
throw new GrpcError( datasetName,
grpc.status.UNKNOWN, FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME
`received error deleting iscsi extent - extent: ${extentId} code: ${ );
response.statusCode } else {
} body: ${JSON.stringify(response.body)}` this.ctx.logger.debug(
"not deleting iscsiextent asset as it appears ID %s has been re-used: zfs name - %s, iscsiextent name - %s",
extentId,
iscsiName,
assetName
); );
} }
} else {
this.ctx.logger.debug(
"not deleting iscsiextent asset as it appears ID %s has been re-used: zfs name - %s, iscsiextent name - %s",
extentId,
iscsiName,
assetName
);
} }
} }
break; break;