use context logger in ControllerZfsBaseDriver and descendants

This commit is contained in:
Danil Uzlov 2025-04-13 06:03:00 +00:00
parent 3ec110a7d9
commit f36ea774f4
5 changed files with 108 additions and 106 deletions

View File

@ -74,10 +74,10 @@ class ControllerZfsGenericDriver extends ControllerZfsBaseDriver {
} }
} }
generateSmbShareName(datasetName) { generateSmbShareName(callContext, datasetName) {
const driver = this; const driver = this;
driver.ctx.logger.verbose( callContext.logger.verbose(
`generating smb share name for dataset: ${datasetName}` `generating smb share name for dataset: ${datasetName}`
); );
@ -85,7 +85,7 @@ class ControllerZfsGenericDriver extends ControllerZfsBaseDriver {
name = name.replaceAll("/", "_"); name = name.replaceAll("/", "_");
name = name.replaceAll("-", "_"); name = name.replaceAll("-", "_");
driver.ctx.logger.verbose( callContext.logger.verbose(
`generated smb share name for dataset (${datasetName}): ${name}` `generated smb share name for dataset (${datasetName}): ${name}`
); );
@ -98,7 +98,7 @@ class ControllerZfsGenericDriver extends ControllerZfsBaseDriver {
* *
* @param {*} datasetName * @param {*} datasetName
*/ */
async createShare(call, datasetName) { async createShare(callContext, call, datasetName) {
const driver = this; const driver = this;
const zb = await this.getZetabyte(); const zb = await this.getZetabyte();
const execClient = this.getExecClient(); const execClient = this.getExecClient();
@ -133,7 +133,7 @@ class ControllerZfsGenericDriver extends ControllerZfsBaseDriver {
properties = await zb.zfs.get(datasetName, ["mountpoint"]); properties = await zb.zfs.get(datasetName, ["mountpoint"]);
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
volume_context = { volume_context = {
node_attach_driver: "nfs", node_attach_driver: "nfs",
@ -160,7 +160,7 @@ class ControllerZfsGenericDriver extends ControllerZfsBaseDriver {
} }
} }
share = driver.generateSmbShareName(datasetName); share = driver.generateSmbShareName(callContext, datasetName);
break; break;
default: default:
break; break;
@ -168,7 +168,7 @@ class ControllerZfsGenericDriver extends ControllerZfsBaseDriver {
properties = await zb.zfs.get(datasetName, ["mountpoint"]); properties = await zb.zfs.get(datasetName, ["mountpoint"]);
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
volume_context = { volume_context = {
node_attach_driver: "smb", node_attach_driver: "smb",
@ -264,7 +264,7 @@ class ControllerZfsGenericDriver extends ControllerZfsBaseDriver {
3, 3,
2000, 2000,
async () => { async () => {
await this.targetCliCommand( await this.targetCliCommand(callContext,
` `
# create target # create target
cd /iscsi cd /iscsi
@ -303,7 +303,7 @@ create /backstores/block/${assetName}
// iqn = target // iqn = target
let iqn = basename + ":" + assetName; let iqn = basename + ":" + assetName;
this.ctx.logger.info("iqn: " + iqn); callContext.logger.info("iqn: " + iqn);
// store this off to make delete process more bullet proof // store this off to make delete process more bullet proof
await zb.zfs.set(datasetName, { await zb.zfs.set(datasetName, {
@ -403,7 +403,7 @@ create ${basename}:${assetName}
3, 3,
2000, 2000,
async () => { async () => {
await this.nvmetCliCommand( await this.nvmetCliCommand(callContext,
` `
# create subsystem # create subsystem
cd /subsystems cd /subsystems
@ -487,7 +487,7 @@ create ${listenerAttributesText}
3, 3,
2000, 2000,
async () => { async () => {
await this.spdkCliCommand( await this.spdkCliCommand(callContext,
` `
# create bdev # create bdev
cd /bdevs/${this.options.nvmeof.shareStrategySpdkCli.bdev.type} cd /bdevs/${this.options.nvmeof.shareStrategySpdkCli.bdev.type}
@ -528,7 +528,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
// iqn = target // iqn = target
let nqn = basename + ":" + assetName; let nqn = basename + ":" + assetName;
this.ctx.logger.info("nqn: " + nqn); callContext.logger.info("nqn: " + nqn);
// store this off to make delete process more bullet proof // store this off to make delete process more bullet proof
await zb.zfs.set(datasetName, { await zb.zfs.set(datasetName, {
@ -555,7 +555,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
} }
} }
async deleteShare(call, datasetName) { async deleteShare(callContext, call, datasetName) {
const zb = await this.getZetabyte(); const zb = await this.getZetabyte();
const execClient = this.getExecClient(); const execClient = this.getExecClient();
@ -640,7 +640,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
} }
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
assetName = properties[ISCSI_ASSETS_NAME_PROPERTY_NAME].value; assetName = properties[ISCSI_ASSETS_NAME_PROPERTY_NAME].value;
@ -666,7 +666,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
3, 3,
2000, 2000,
async () => { async () => {
await this.targetCliCommand( await this.targetCliCommand(callContext,
` `
# delete target # delete target
cd /iscsi cd /iscsi
@ -712,7 +712,7 @@ delete ${assetName}
} }
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
assetName = properties[NVMEOF_ASSETS_NAME_PROPERTY_NAME].value; assetName = properties[NVMEOF_ASSETS_NAME_PROPERTY_NAME].value;
@ -756,7 +756,7 @@ delete ${basename}:${assetName}
3, 3,
2000, 2000,
async () => { async () => {
await this.nvmetCliCommand( await this.nvmetCliCommand(callContext,
` `
# delete subsystem from port # delete subsystem from port
${portCommands} ${portCommands}
@ -787,7 +787,7 @@ saveconfig ${savefile}
3, 3,
2000, 2000,
async () => { async () => {
await this.spdkCliCommand( await this.spdkCliCommand(callContext,
` `
# delete subsystem # delete subsystem
cd /nvmf/subsystem/ cd /nvmf/subsystem/
@ -830,7 +830,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
return {}; return {};
} }
async expandVolume(call, datasetName) { async expandVolume(callContext, call, datasetName) {
switch (this.options.driver) { switch (this.options.driver) {
case "zfs-generic-nfs": case "zfs-generic-nfs":
break; break;
@ -850,7 +850,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
} }
} }
async targetCliCommand(data) { async targetCliCommand(callContext, data) {
const execClient = this.getExecClient(); const execClient = this.getExecClient();
const driver = this; const driver = this;
@ -887,7 +887,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
logCommand += "\n"; logCommand += "\n";
}); });
driver.ctx.logger.verbose("TargetCLI command: " + logCommand); callContext.logger.verbose("TargetCLI command: " + logCommand);
// https://github.com/democratic-csi/democratic-csi/issues/127 // https://github.com/democratic-csi/democratic-csi/issues/127
// https://bugs.launchpad.net/ubuntu/+source/python-configshell-fb/+bug/1776761 // https://bugs.launchpad.net/ubuntu/+source/python-configshell-fb/+bug/1776761
@ -901,7 +901,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
execClient.buildCommand(command, args), execClient.buildCommand(command, args),
options options
); );
driver.ctx.logger.verbose( callContext.logger.verbose(
"TargetCLI response: " + JSON.stringify(response) "TargetCLI response: " + JSON.stringify(response)
); );
if (response.code != 0) { if (response.code != 0) {
@ -910,7 +910,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
return response; return response;
} }
async nvmetCliCommand(data) { async nvmetCliCommand(callContext, data) {
const execClient = this.getExecClient(); const execClient = this.getExecClient();
const driver = this; const driver = this;
@ -974,7 +974,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
logCommand += "\n"; logCommand += "\n";
}); });
driver.ctx.logger.verbose("nvmetCLI command: " + logCommand); callContext.logger.verbose("nvmetCLI command: " + logCommand);
//process.exit(0); //process.exit(0);
// https://github.com/democratic-csi/democratic-csi/issues/127 // https://github.com/democratic-csi/democratic-csi/issues/127
@ -989,14 +989,14 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
execClient.buildCommand(command, args), execClient.buildCommand(command, args),
options options
); );
driver.ctx.logger.verbose("nvmetCLI response: " + JSON.stringify(response)); callContext.logger.verbose("nvmetCLI response: " + JSON.stringify(response));
if (response.code != 0) { if (response.code != 0) {
throw response; throw response;
} }
return response; return response;
} }
async spdkCliCommand(data) { async spdkCliCommand(callContext, data) {
const execClient = this.getExecClient(); const execClient = this.getExecClient();
const driver = this; const driver = this;
@ -1033,7 +1033,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
logCommand += "\n"; logCommand += "\n";
}); });
driver.ctx.logger.verbose("spdkCLI command: " + logCommand); callContext.logger.verbose("spdkCLI command: " + logCommand);
//process.exit(0); //process.exit(0);
// https://github.com/democratic-csi/democratic-csi/issues/127 // https://github.com/democratic-csi/democratic-csi/issues/127
@ -1048,7 +1048,7 @@ save_config filename=${this.options.nvmeof.shareStrategySpdkCli.configPath}
execClient.buildCommand(command, args), execClient.buildCommand(command, args),
options options
); );
driver.ctx.logger.verbose("spdkCLI response: " + JSON.stringify(response)); callContext.logger.verbose("spdkCLI response: " + JSON.stringify(response));
if (response.code != 0) { if (response.code != 0) {
throw response; throw response;
} }

View File

@ -160,7 +160,7 @@ class ControllerZfsLocalDriver extends ControllerZfsBaseDriver {
* *
* @param {*} datasetName * @param {*} datasetName
*/ */
async createShare(call, datasetName) { async createShare(callContext, call, datasetName) {
let volume_context = {}; let volume_context = {};
switch (this.options.driver) { switch (this.options.driver) {
@ -193,7 +193,7 @@ class ControllerZfsLocalDriver extends ControllerZfsBaseDriver {
* @param {*} datasetName * @param {*} datasetName
* @returns * @returns
*/ */
async deleteShare(call, datasetName) { async deleteShare(callContext, call, datasetName) {
return {}; return {};
} }
@ -203,7 +203,7 @@ class ControllerZfsLocalDriver extends ControllerZfsBaseDriver {
* @param {*} call * @param {*} call
* @param {*} datasetName * @param {*} datasetName
*/ */
async expandVolume(call, datasetName) {} async expandVolume(callContext, call, datasetName) {}
/** /**
* List of topologies associated with the *volume* * List of topologies associated with the *volume*

View File

@ -41,9 +41,9 @@ const MAX_ZVOL_NAME_LENGTH_CACHE_KEY = "controller-zfs:max_zvol_name_length";
* - getFSTypes() // optional * - getFSTypes() // optional
* - getAccessModes(capability) // optional * - getAccessModes(capability) // optional
* - async getAccessibleTopology() // optional * - async getAccessibleTopology() // optional
* - async createShare(call, datasetName) // return appropriate volume_context for Node operations * - async createShare(callContext, call, datasetName) // return appropriate volume_context for Node operations
* - async deleteShare(call, datasetName) // no return expected * - async deleteShare(callContext, call, datasetName) // no return expected
* - async expandVolume(call, datasetName) // no return expected, used for restarting services etc if needed * - async expandVolume(callContext, call, datasetName) // no return expected, used for restarting services etc if needed
*/ */
class ControllerZfsBaseDriver extends CsiBaseDriver { class ControllerZfsBaseDriver extends CsiBaseDriver {
constructor(ctx, options) { constructor(ctx, options) {
@ -152,11 +152,11 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
} }
} }
async getWhoAmI() { async getWhoAmI(callContext) {
const driver = this; const driver = this;
const execClient = driver.getExecClient(); const execClient = driver.getExecClient();
const command = "whoami"; const command = "whoami";
driver.ctx.logger.verbose("whoami command: %s", command); callContext.logger.verbose("whoami command: %s", command);
const response = await execClient.exec(command); const response = await execClient.exec(command);
if (response.code !== 0) { if (response.code !== 0) {
throw new Error("failed to run uname to determine max zvol name length"); throw new Error("failed to run uname to determine max zvol name length");
@ -252,7 +252,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
assertCapabilities(callContext, capabilities) { assertCapabilities(callContext, capabilities) {
const driverZfsResourceType = this.getDriverZfsResourceType(); const driverZfsResourceType = this.getDriverZfsResourceType();
this.ctx.logger.verbose("validating capabilities: %j", capabilities); callContext.logger.verbose("validating capabilities: %j", capabilities);
let message = null; let message = null;
//[{"access_mode":{"mode":"SINGLE_NODE_WRITER"},"mount":{"mount_flags":["noatime","_netdev"],"fs_type":"nfs"},"access_type":"mount"}] //[{"access_mode":{"mode":"SINGLE_NODE_WRITER"},"mount":{"mount_flags":["noatime","_netdev"],"fs_type":"nfs"},"access_type":"mount"}]
@ -346,7 +346,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
return volume_status; return volume_status;
} }
async populateCsiVolumeFromData(row) { async populateCsiVolumeFromData(callContext, row) {
const driver = this; const driver = this;
const zb = await this.getZetabyte(); const zb = await this.getZetabyte();
const driverZfsResourceType = this.getDriverZfsResourceType(); const driverZfsResourceType = this.getDriverZfsResourceType();
@ -360,7 +360,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
if ( if (
!zb.helpers.isPropertyValueSet(row[SHARE_VOLUME_CONTEXT_PROPERTY_NAME]) !zb.helpers.isPropertyValueSet(row[SHARE_VOLUME_CONTEXT_PROPERTY_NAME])
) { ) {
driver.ctx.logger.warn(`${row.name} is missing share context`); callContext.logger.warn(`${row.name} is missing share context`);
return; return;
} }
@ -430,7 +430,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=238112 * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=238112
* https://svnweb.freebsd.org/base?view=revision&revision=343485 * https://svnweb.freebsd.org/base?view=revision&revision=343485
*/ */
async getMaxZvolNameLength() { async getMaxZvolNameLength(callContext) {
const driver = this; const driver = this;
const execClient = driver.getExecClient(); const execClient = driver.getExecClient();
@ -449,7 +449,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
// get kernel // get kernel
command = "uname -s"; command = "uname -s";
driver.ctx.logger.verbose("uname command: %s", command); callContext.logger.verbose("uname command: %s", command);
response = await execClient.exec(command); response = await execClient.exec(command);
if (response.code !== 0) { if (response.code !== 0) {
throw new Error("failed to run uname to determine max zvol name length"); throw new Error("failed to run uname to determine max zvol name length");
@ -468,7 +468,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
case "freebsd": case "freebsd":
// get kernel_release // get kernel_release
command = "uname -r"; command = "uname -r";
driver.ctx.logger.verbose("uname command: %s", command); callContext.logger.verbose("uname command: %s", command);
response = await execClient.exec(command); response = await execClient.exec(command);
if (response.code !== 0) { if (response.code !== 0) {
throw new Error( throw new Error(
@ -496,16 +496,16 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
return max; return max;
} }
async setFilesystemMode(path, mode) { async setFilesystemMode(callContext, path, mode) {
const driver = this; const driver = this;
const execClient = this.getExecClient(); const execClient = this.getExecClient();
let command = execClient.buildCommand("chmod", [mode, path]); let command = execClient.buildCommand("chmod", [mode, path]);
if ((await driver.getWhoAmI()) != "root") { if ((await driver.getWhoAmI(callContext)) != "root") {
command = (await driver.getSudoPath()) + " " + command; command = (await driver.getSudoPath()) + " " + command;
} }
driver.ctx.logger.verbose("set permission command: %s", command); callContext.logger.verbose("set permission command: %s", command);
let response = await execClient.exec(command); let response = await execClient.exec(command);
if (response.code != 0) { if (response.code != 0) {
@ -516,7 +516,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
} }
} }
async setFilesystemOwnership(path, user = false, group = false) { async setFilesystemOwnership(callContext, path, user = false, group = false) {
const driver = this; const driver = this;
const execClient = this.getExecClient(); const execClient = this.getExecClient();
@ -539,11 +539,11 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
(user.length > 0 ? user : "") + ":" + (group.length > 0 ? group : ""), (user.length > 0 ? user : "") + ":" + (group.length > 0 ? group : ""),
path, path,
]); ]);
if ((await driver.getWhoAmI()) != "root") { if ((await driver.getWhoAmI(callContext)) != "root") {
command = (await driver.getSudoPath()) + " " + command; command = (await driver.getSudoPath()) + " " + command;
} }
driver.ctx.logger.verbose("set ownership command: %s", command); callContext.logger.verbose("set ownership command: %s", command);
let response = await execClient.exec(command); let response = await execClient.exec(command);
if (response.code != 0) { if (response.code != 0) {
@ -590,7 +590,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
*/ */
if (!driver.currentExecShell || timerEnabled === false) { if (!driver.currentExecShell || timerEnabled === false) {
const execClient = this.getExecClient(); const execClient = this.getExecClient();
driver.ctx.logger.debug("performing exec sanity check.."); callContext.logger.debug("performing exec sanity check..");
const response = await execClient.exec("echo $0"); const response = await execClient.exec("echo $0");
driver.currentExecShell = response.stdout.split("\n")[0]; driver.currentExecShell = response.stdout.split("\n")[0];
} }
@ -600,7 +600,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
const intervalTime = 60000; const intervalTime = 60000;
driver.currentExecShellInterval = setInterval(async () => { driver.currentExecShellInterval = setInterval(async () => {
try { try {
driver.ctx.logger.debug("performing exec sanity check.."); callContext.logger.debug("performing exec sanity check..");
const execClient = this.getExecClient(); const execClient = this.getExecClient();
const response = await execClient.exec("echo $0"); const response = await execClient.exec("echo $0");
driver.currentExecShell = response.stdout.split("\n")[0]; driver.currentExecShell = response.stdout.split("\n")[0];
@ -792,8 +792,8 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
*/ */
if (driverZfsResourceType == "volume") { if (driverZfsResourceType == "volume") {
let extentDiskName = "zvol/" + datasetName; let extentDiskName = "zvol/" + datasetName;
let maxZvolNameLength = await driver.getMaxZvolNameLength(); let maxZvolNameLength = await driver.getMaxZvolNameLength(callContext);
driver.ctx.logger.debug("max zvol name length: %s", maxZvolNameLength); callContext.logger.debug("max zvol name length: %s", maxZvolNameLength);
if (extentDiskName.length > maxZvolNameLength) { if (extentDiskName.length > maxZvolNameLength) {
throw new GrpcError( throw new GrpcError(
@ -849,7 +849,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
volumeProperties[VOLUME_CONTENT_SOURCE_TYPE_PROPERTY_NAME] = volumeProperties[VOLUME_CONTENT_SOURCE_TYPE_PROPERTY_NAME] =
volume_content_source.type; volume_content_source.type;
switch (volume_content_source.type) { switch (volume_content_source.type) {
// must be available when adverstising CREATE_DELETE_SNAPSHOT // must be available when advertising CREATE_DELETE_SNAPSHOT
// simply clone // simply clone
case "snapshot": case "snapshot":
try { try {
@ -883,7 +883,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
volume_id; volume_id;
} }
driver.ctx.logger.debug("full snapshot name: %s", fullSnapshotName); callContext.logger.debug("full snapshot name: %s", fullSnapshotName);
if (!zb.helpers.isZfsSnapshot(volume_content_source_snapshot_id)) { if (!zb.helpers.isZfsSnapshot(volume_content_source_snapshot_id)) {
try { try {
@ -997,7 +997,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
VOLUME_SOURCE_CLONE_SNAPSHOT_PREFIX + VOLUME_SOURCE_CLONE_SNAPSHOT_PREFIX +
volume_id; volume_id;
driver.ctx.logger.debug("full snapshot name: %s", fullSnapshotName); callContext.logger.debug("full snapshot name: %s", fullSnapshotName);
// create snapshot // create snapshot
try { try {
@ -1130,11 +1130,12 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
VOLUME_CONTENT_SOURCE_ID_PROPERTY_NAME, VOLUME_CONTENT_SOURCE_ID_PROPERTY_NAME,
]); ]);
properties = properties[datasetName]; properties = properties[datasetName];
driver.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
// set mode // set mode
if (this.options.zfs.datasetPermissionsMode) { if (this.options.zfs.datasetPermissionsMode) {
await driver.setFilesystemMode( await driver.setFilesystemMode(
callContext,
properties.mountpoint.value, properties.mountpoint.value,
this.options.zfs.datasetPermissionsMode this.options.zfs.datasetPermissionsMode
); );
@ -1148,6 +1149,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
.length > 0 .length > 0
) { ) {
await driver.setFilesystemOwnership( await driver.setFilesystemOwnership(
callContext,
properties.mountpoint.value, properties.mountpoint.value,
this.options.zfs.datasetPermissionsUser, this.options.zfs.datasetPermissionsUser,
this.options.zfs.datasetPermissionsGroup this.options.zfs.datasetPermissionsGroup
@ -1155,7 +1157,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
} }
// set acls // set acls
// TODO: this is unsfafe approach, make it better // TODO: this is unsafe approach, make it better
// probably could see if ^-.*\s and split and then shell escape // probably could see if ^-.*\s and split and then shell escape
if (this.options.zfs.datasetPermissionsAcls) { if (this.options.zfs.datasetPermissionsAcls) {
let aclBinary = _.get( let aclBinary = _.get(
@ -1168,11 +1170,11 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
acl, acl,
properties.mountpoint.value, properties.mountpoint.value,
]); ]);
if ((await this.getWhoAmI()) != "root") { if ((await driver.getWhoAmI(callContext)) != "root") {
command = (await this.getSudoPath()) + " " + command; command = (await this.getSudoPath()) + " " + command;
} }
driver.ctx.logger.verbose("set acl command: %s", command); callContext.logger.verbose("set acl command: %s", command);
response = await execClient.exec(command); response = await execClient.exec(command);
if (response.code != 0) { if (response.code != 0) {
throw new GrpcError( throw new GrpcError(
@ -1222,7 +1224,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
break; break;
} }
volume_context = await this.createShare(call, datasetName); volume_context = await this.createShare(callContext, call, datasetName);
await zb.zfs.set(datasetName, { await zb.zfs.set(datasetName, {
[SHARE_VOLUME_CONTEXT_PROPERTY_NAME]: JSON.stringify(volume_context), [SHARE_VOLUME_CONTEXT_PROPERTY_NAME]: JSON.stringify(volume_context),
}); });
@ -1314,7 +1316,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
} }
} }
driver.ctx.logger.debug("dataset properties: %j", properties); callContext.logger.debug("dataset properties: %j", properties);
// deleteStrategy // deleteStrategy
const delete_strategy = _.get( const delete_strategy = _.get(
@ -1328,7 +1330,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
} }
// remove share resources // remove share resources
await this.deleteShare(call, datasetName); await this.deleteShare(callContext, call, datasetName);
// remove parent snapshot if appropriate with defer // remove parent snapshot if appropriate with defer
if ( if (
@ -1339,7 +1341,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
.extractSnapshotName(properties.origin.value) .extractSnapshotName(properties.origin.value)
.startsWith(VOLUME_SOURCE_CLONE_SNAPSHOT_PREFIX) .startsWith(VOLUME_SOURCE_CLONE_SNAPSHOT_PREFIX)
) { ) {
driver.ctx.logger.debug( callContext.logger.debug(
"removing with defer source snapshot: %s", "removing with defer source snapshot: %s",
properties.origin.value properties.origin.value
); );
@ -1503,7 +1505,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
await zb.zfs.set(datasetName, properties); await zb.zfs.set(datasetName, properties);
} }
await this.expandVolume(call, datasetName); await this.expandVolume(callContext, call, datasetName);
return { return {
capacity_bytes: capacity_bytes:
@ -1632,8 +1634,8 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
throw err; throw err;
} }
driver.ctx.logger.debug("list volumes result: %j", response); callContext.logger.debug("list volumes result: %j", response);
let volume = await driver.populateCsiVolumeFromData(response.indexed[0]); let volume = await driver.populateCsiVolumeFromData(callContext, response.indexed[0]);
let status = await driver.getVolumeStatus(datasetName); let status = await driver.getVolumeStatus(datasetName);
let res = { volume }; let res = { volume };
@ -1747,7 +1749,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
throw err; throw err;
} }
driver.ctx.logger.debug("list volumes result: %j", response); callContext.logger.debug("list volumes result: %j", response);
// remove parent dataset from results // remove parent dataset from results
if (driverZfsResourceType == "filesystem") { if (driverZfsResourceType == "filesystem") {
@ -1761,7 +1763,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
continue; continue;
} }
let volume = await driver.populateCsiVolumeFromData(row); let volume = await driver.populateCsiVolumeFromData(callContext, row);
if (volume) { if (volume) {
let status = await driver.getVolumeStatus(datasetName); let status = await driver.getVolumeStatus(datasetName);
entries.push({ entries.push({
@ -2113,7 +2115,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
source_volume_id; source_volume_id;
snapshotProperties[MANAGED_PROPERTY_NAME] = "true"; snapshotProperties[MANAGED_PROPERTY_NAME] = "true";
driver.ctx.logger.verbose("requested snapshot name: %s", name); callContext.logger.verbose("requested snapshot name: %s", name);
let invalid_chars; let invalid_chars;
invalid_chars = name.match(/[^a-z0-9_\-:.+]+/gi); invalid_chars = name.match(/[^a-z0-9_\-:.+]+/gi);
@ -2130,7 +2132,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
// https://stackoverflow.com/questions/32106243/regex-to-remove-all-non-alpha-numeric-and-replace-spaces-with/32106277 // https://stackoverflow.com/questions/32106243/regex-to-remove-all-non-alpha-numeric-and-replace-spaces-with/32106277
name = name.replace(/[^a-z0-9_\-:.+]+/gi, ""); name = name.replace(/[^a-z0-9_\-:.+]+/gi, "");
driver.ctx.logger.verbose("cleansed snapshot name: %s", name); callContext.logger.verbose("cleansed snapshot name: %s", name);
// check for other snapshopts with the same name on other volumes and fail as appropriate // check for other snapshopts with the same name on other volumes and fail as appropriate
{ {
@ -2189,7 +2191,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
fullSnapshotName = datasetName + "@" + name; fullSnapshotName = datasetName + "@" + name;
} }
driver.ctx.logger.verbose("full snapshot name: %s", fullSnapshotName); callContext.logger.verbose("full snapshot name: %s", fullSnapshotName);
if (detachedSnapshot) { if (detachedSnapshot) {
tmpSnapshotName = tmpSnapshotName =
@ -2297,7 +2299,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
{ types } { types }
); );
properties = properties[fullSnapshotName]; properties = properties[fullSnapshotName];
driver.ctx.logger.verbose("snapshot properties: %j", properties); callContext.logger.verbose("snapshot properties: %j", properties);
// TODO: properly handle use-case where datasetEnableQuotas is not turned on // TODO: properly handle use-case where datasetEnableQuotas is not turned on
if (driverZfsResourceType == "filesystem") { if (driverZfsResourceType == "filesystem") {
@ -2383,7 +2385,7 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
const fullSnapshotName = datasetParentName + "/" + snapshot_id; const fullSnapshotName = datasetParentName + "/" + snapshot_id;
driver.ctx.logger.verbose("deleting snapshot: %s", fullSnapshotName); callContext.logger.verbose("deleting snapshot: %s", fullSnapshotName);
try { try {
await zb.zfs.destroy(fullSnapshotName, { await zb.zfs.destroy(fullSnapshotName, {

View File

@ -249,7 +249,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
* *
* @param {*} datasetName * @param {*} datasetName
*/ */
async createShare(call, datasetName) { async createShare(callContext, call, datasetName) {
const driver = this; const driver = this;
const driverShareType = this.getDriverShareType(); const driverShareType = this.getDriverShareType();
const execClient = this.getExecClient(); const execClient = this.getExecClient();
@ -284,7 +284,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
FREENAS_NFS_SHARE_PROPERTY_NAME, FREENAS_NFS_SHARE_PROPERTY_NAME,
]); ]);
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
// create nfs share // create nfs share
if ( if (
@ -495,7 +495,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
FREENAS_SMB_SHARE_PROPERTY_NAME, FREENAS_SMB_SHARE_PROPERTY_NAME,
]); ]);
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
let smbName; let smbName;
@ -518,7 +518,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
smbName = smbName.toLowerCase(); smbName = smbName.toLowerCase();
this.ctx.logger.info( callContext.logger.info(
"FreeNAS creating smb share with name: " + smbName "FreeNAS creating smb share with name: " + smbName
); );
@ -744,7 +744,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
FREENAS_ISCSI_TARGETTOEXTENT_ID_PROPERTY_NAME, FREENAS_ISCSI_TARGETTOEXTENT_ID_PROPERTY_NAME,
]); ]);
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
let basename; let basename;
let iscsiName; let iscsiName;
@ -773,8 +773,8 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
iscsiName = iscsiName.toLowerCase(); iscsiName = iscsiName.toLowerCase();
let extentDiskName = "zvol/" + datasetName; let extentDiskName = "zvol/" + datasetName;
let maxZvolNameLength = await driver.getMaxZvolNameLength(); let maxZvolNameLength = await driver.getMaxZvolNameLength(callContext);
driver.ctx.logger.debug("max zvol name length: %s", maxZvolNameLength); callContext.logger.debug("max zvol name length: %s", maxZvolNameLength);
/** /**
* limit is a FreeBSD limitation * limit is a FreeBSD limitation
@ -796,7 +796,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
); );
} }
this.ctx.logger.info( callContext.logger.info(
"FreeNAS creating iscsi assets with name: " + iscsiName "FreeNAS creating iscsi assets with name: " + iscsiName
); );
@ -870,7 +870,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
); );
} }
basename = response.body.iscsi_basename; basename = response.body.iscsi_basename;
this.ctx.logger.verbose("FreeNAS ISCSI BASENAME: " + basename); callContext.logger.verbose("FreeNAS ISCSI BASENAME: " + basename);
break; break;
case 2: case 2:
response = await httpClient.get("/iscsi/global"); response = await httpClient.get("/iscsi/global");
@ -883,7 +883,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
); );
} }
basename = response.body.basename; basename = response.body.basename;
this.ctx.logger.verbose("FreeNAS ISCSI BASENAME: " + basename); callContext.logger.verbose("FreeNAS ISCSI BASENAME: " + basename);
break; break;
default: default:
throw new GrpcError( throw new GrpcError(
@ -953,7 +953,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
); );
} }
this.ctx.logger.verbose("FreeNAS ISCSI TARGET: %j", target); callContext.logger.verbose("FreeNAS ISCSI TARGET: %j", target);
// set target.id on zvol // set target.id on zvol
await zb.zfs.set(datasetName, { await zb.zfs.set(datasetName, {
@ -1035,7 +1035,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
); );
} }
this.ctx.logger.verbose( callContext.logger.verbose(
"FreeNAS ISCSI TARGET_GROUP: %j", "FreeNAS ISCSI TARGET_GROUP: %j",
targetGroup targetGroup
); );
@ -1101,7 +1101,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
); );
} }
this.ctx.logger.verbose("FreeNAS ISCSI EXTENT: %j", extent); callContext.logger.verbose("FreeNAS ISCSI EXTENT: %j", extent);
await zb.zfs.set(datasetName, { await zb.zfs.set(datasetName, {
[FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME]: extent.id, [FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME]: extent.id,
@ -1159,7 +1159,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
`unknown error creating iscsi targettoextent` `unknown error creating iscsi targettoextent`
); );
} }
this.ctx.logger.verbose( callContext.logger.verbose(
"FreeNAS ISCSI TARGET_TO_EXTENT: %j", "FreeNAS ISCSI TARGET_TO_EXTENT: %j",
targetToExtent targetToExtent
); );
@ -1285,7 +1285,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
} }
} }
this.ctx.logger.verbose("FreeNAS ISCSI TARGET: %j", target); callContext.logger.verbose("FreeNAS ISCSI TARGET: %j", target);
// set target.id on zvol // set target.id on zvol
await zb.zfs.set(datasetName, { await zb.zfs.set(datasetName, {
@ -1350,7 +1350,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
); );
} }
this.ctx.logger.verbose("FreeNAS ISCSI EXTENT: %j", extent); callContext.logger.verbose("FreeNAS ISCSI EXTENT: %j", extent);
await zb.zfs.set(datasetName, { await zb.zfs.set(datasetName, {
[FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME]: extent.id, [FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME]: extent.id,
@ -1407,7 +1407,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
`unknown error creating iscsi targetextent` `unknown error creating iscsi targetextent`
); );
} }
this.ctx.logger.verbose( callContext.logger.verbose(
"FreeNAS ISCSI TARGET_TO_EXTENT: %j", "FreeNAS ISCSI TARGET_TO_EXTENT: %j",
targetToExtent targetToExtent
); );
@ -1428,7 +1428,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
// iqn = target // iqn = target
let iqn = basename + ":" + iscsiName; let iqn = basename + ":" + iscsiName;
this.ctx.logger.info("FreeNAS iqn: " + iqn); callContext.logger.info("FreeNAS iqn: " + iqn);
// store this off to make delete process more bullet proof // store this off to make delete process more bullet proof
await zb.zfs.set(datasetName, { await zb.zfs.set(datasetName, {
@ -1455,7 +1455,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
} }
} }
async deleteShare(call, datasetName) { async deleteShare(callContext, call, datasetName) {
const driverShareType = this.getDriverShareType(); const driverShareType = this.getDriverShareType();
const httpClient = await this.getHttpClient(); const httpClient = await this.getHttpClient();
const apiVersion = httpClient.getApiVersion(); const apiVersion = httpClient.getApiVersion();
@ -1482,7 +1482,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
throw err; throw err;
} }
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
shareId = properties[FREENAS_NFS_SHARE_PROPERTY_NAME].value; shareId = properties[FREENAS_NFS_SHARE_PROPERTY_NAME].value;
@ -1585,7 +1585,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
throw err; throw err;
} }
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
shareId = properties[FREENAS_SMB_SHARE_PROPERTY_NAME].value; shareId = properties[FREENAS_SMB_SHARE_PROPERTY_NAME].value;
@ -1697,7 +1697,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
} }
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
let targetId = properties[FREENAS_ISCSI_TARGET_ID_PROPERTY_NAME].value; let targetId = properties[FREENAS_ISCSI_TARGET_ID_PROPERTY_NAME].value;
let extentId = properties[FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME].value; let extentId = properties[FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME].value;
@ -1763,7 +1763,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
_.get(response, "body.errno") == 14 _.get(response, "body.errno") == 14
) { ) {
retries++; retries++;
this.ctx.logger.debug( callContext.logger.debug(
"target: %s is in use, retry %s shortly", "target: %s is in use, retry %s shortly",
targetId, targetId,
retries retries
@ -1788,7 +1788,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
FREENAS_ISCSI_TARGET_ID_PROPERTY_NAME FREENAS_ISCSI_TARGET_ID_PROPERTY_NAME
); );
} else { } else {
this.ctx.logger.debug( callContext.logger.debug(
"not deleting iscsitarget asset as it appears ID %s has been re-used: zfs name - %s, iscsitarget name - %s", "not deleting iscsitarget asset as it appears ID %s has been re-used: zfs name - %s, iscsitarget name - %s",
targetId, targetId,
iscsiName, iscsiName,
@ -1850,7 +1850,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME FREENAS_ISCSI_EXTENT_ID_PROPERTY_NAME
); );
} else { } else {
this.ctx.logger.debug( callContext.logger.debug(
"not deleting iscsiextent asset as it appears ID %s has been re-used: zfs name - %s, iscsiextent name - %s", "not deleting iscsiextent asset as it appears ID %s has been re-used: zfs name - %s, iscsiextent name - %s",
extentId, extentId,
iscsiName, iscsiName,
@ -1875,7 +1875,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
} }
} }
async setFilesystemMode(path, mode) { async setFilesystemMode(callContext, path, mode) {
const httpClient = await this.getHttpClient(); const httpClient = await this.getHttpClient();
const apiVersion = httpClient.getApiVersion(); const apiVersion = httpClient.getApiVersion();
const httpApiClient = await this.getTrueNASHttpApiClient(); const httpApiClient = await this.getTrueNASHttpApiClient();
@ -1925,7 +1925,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
} }
} }
async setFilesystemOwnership(path, user = false, group = false) { async setFilesystemOwnership(callContext, path, user = false, group = false) {
const httpClient = await this.getHttpClient(); const httpClient = await this.getHttpClient();
const apiVersion = httpClient.getApiVersion(); const apiVersion = httpClient.getApiVersion();
const httpApiClient = await this.getTrueNASHttpApiClient(); const httpApiClient = await this.getTrueNASHttpApiClient();
@ -2011,7 +2011,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
} }
} }
async expandVolume(call, datasetName) { async expandVolume(callContext, call, datasetName) {
const driverShareType = this.getDriverShareType(); const driverShareType = this.getDriverShareType();
const execClient = this.getExecClient(); const execClient = this.getExecClient();
const httpClient = await this.getHttpClient(); const httpClient = await this.getHttpClient();
@ -2029,7 +2029,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
FREENAS_ISCSI_ASSETS_NAME_PROPERTY_NAME, FREENAS_ISCSI_ASSETS_NAME_PROPERTY_NAME,
]); ]);
properties = properties[datasetName]; properties = properties[datasetName];
this.ctx.logger.debug("zfs props data: %j", properties); callContext.logger.debug("zfs props data: %j", properties);
let iscsiName = let iscsiName =
properties[FREENAS_ISCSI_ASSETS_NAME_PROPERTY_NAME].value; properties[FREENAS_ISCSI_ASSETS_NAME_PROPERTY_NAME].value;
@ -2063,7 +2063,7 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
reload = true; reload = true;
break; break;
case 2: case 2:
this.ctx.logger.verbose( callContext.logger.verbose(
"FreeNAS reloading iscsi daemon using api" "FreeNAS reloading iscsi daemon using api"
); );
// POST /service/reload // POST /service/reload
@ -2092,11 +2092,11 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
} }
if (reload) { if (reload) {
if ((await this.getWhoAmI()) != "root") { if ((await this.getWhoAmI(callContext)) != "root") {
command = (await this.getSudoPath()) + " " + command; command = (await this.getSudoPath()) + " " + command;
} }
this.ctx.logger.verbose( callContext.logger.verbose(
"FreeNAS reloading iscsi daemon: %s", "FreeNAS reloading iscsi daemon: %s",
command command
); );

View File

@ -168,7 +168,7 @@ class ZfsLocalEphemeralInlineDriver extends CsiBaseDriver {
assertCapabilities(callContext, capabilities) { assertCapabilities(callContext, capabilities) {
// hard code this for now // hard code this for now
const driverZfsResourceType = "filesystem"; const driverZfsResourceType = "filesystem";
this.ctx.logger.verbose("validating capabilities: %j", capabilities); callContext.logger.verbose("validating capabilities: %j", capabilities);
let message = null; let message = null;
//[{"access_mode":{"mode":"SINGLE_NODE_WRITER"},"mount":{"mount_flags":["noatime","_netdev"],"fs_type":"nfs"},"access_type":"mount"}] //[{"access_mode":{"mode":"SINGLE_NODE_WRITER"},"mount":{"mount_flags":["noatime","_netdev"],"fs_type":"nfs"},"access_type":"mount"}]