From 3924f08ae873be83946c4a7083f238461353cb97 Mon Sep 17 00:00:00 2001 From: Travis Glenn Hansen Date: Mon, 30 Nov 2020 09:42:58 -0700 Subject: [PATCH] sudo support for reloading iscsi daemon, error handling for failed chown/chmod/setacl --- src/driver/controller-zfs-ssh/index.js | 20 ++++++++++++++++ src/driver/freenas/index.js | 33 ++++++++++++++------------ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/driver/controller-zfs-ssh/index.js b/src/driver/controller-zfs-ssh/index.js index 66526f5..9da45dc 100644 --- a/src/driver/controller-zfs-ssh/index.js +++ b/src/driver/controller-zfs-ssh/index.js @@ -699,6 +699,14 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver { driver.ctx.logger.verbose("set permission command: %s", command); response = await sshClient.exec(command); + if (response.code != 0) { + throw new GrpcError( + grpc.status.UNKNOWN, + `error setting permissions on dataset: ${JSON.stringify( + response + )}` + ); + } } // set ownership @@ -722,6 +730,12 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver { driver.ctx.logger.verbose("set ownership command: %s", command); response = await sshClient.exec(command); + if (response.code != 0) { + throw new GrpcError( + grpc.status.UNKNOWN, + `error setting ownership on dataset: ${JSON.stringify(response)}` + ); + } } // set acls @@ -739,6 +753,12 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver { driver.ctx.logger.verbose("set acl command: %s", command); response = await sshClient.exec(command); + if (response.code != 0) { + throw new GrpcError( + grpc.status.UNKNOWN, + `error setting acl on dataset: ${JSON.stringify(response)}` + ); + } } } diff --git a/src/driver/freenas/index.js b/src/driver/freenas/index.js index c9e982f..3adca8b 100644 --- a/src/driver/freenas/index.js +++ b/src/driver/freenas/index.js @@ -1393,28 +1393,31 @@ class FreeNASDriver extends ControllerZfsSshBaseDriver { switch (driverShareType) { case "iscsi": const isScale = await this.getIsScale(); + let command; + let reload = false; if (isScale) { - this.ctx.logger.verbose("FreeNAS reloading scst"); - response = await sshClient.exec( - sshClient.buildCommand("systemctl", ["reload", "scst"]) - ); - - if (response.code != 0) { - throw new GrpcError( - grpc.status.UNKNOWN, - `error reloading scst: ${JSON.stringify(response)}` - ); - } + command = sshClient.buildCommand("systemctl", ["reload", "scst"]); + reload = true; } else { - this.ctx.logger.verbose("FreeNAS reloading ctld"); - response = await sshClient.exec( - sshClient.buildCommand("/etc/rc.d/ctld", ["reload"]) + command = sshClient.buildCommand("/etc/rc.d/ctld", ["reload"]); + reload = true; + } + + if (reload) { + if (this.getSudoEnabled()) { + command = (await this.getSudoPath()) + " " + command; + } + + this.ctx.logger.verbose( + "FreeNAS reloading iscsi daemon: %s", + command ); + response = await sshClient.exec(command); if (response.code != 0) { throw new GrpcError( grpc.status.UNKNOWN, - `error reloading ctld: ${JSON.stringify(response)}` + `error reloading iscsi daemon: ${JSON.stringify(response)}` ); } }