diff --git a/src/driver/controller-client-common/index.js b/src/driver/controller-client-common/index.js index db251c3..7d48b88 100644 --- a/src/driver/controller-client-common/index.js +++ b/src/driver/controller-client-common/index.js @@ -228,6 +228,12 @@ class ControllerClientCommonDriver extends CsiBaseDriver { return this.getControllerSnapshotBasePath() + "/" + snapshot_id; } + async getDirectoryUsage(path) { + let result = await this.exec("du", ["-s", "--block-size=1", path]); + let size = result.stdout.split("\t", 1)[0]; + return size; + } + exec(command, args, options = {}) { args = args || []; @@ -664,13 +670,14 @@ class ControllerClientCommonDriver extends CsiBaseDriver { await driver.cloneDir(volume_path, snapshot_path); } + let size_bytes = await driver.getDirectoryUsage(snapshot_path); return { snapshot: { /** * The purpose of this field is to give CO guidance on how much space * is needed to create a volume from this snapshot. */ - //size_bytes: 0, + size_bytes, snapshot_id, source_volume_id: source_volume_id, //https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto diff --git a/src/driver/controller-synology/index.js b/src/driver/controller-synology/index.js index a06736c..5234958 100644 --- a/src/driver/controller-synology/index.js +++ b/src/driver/controller-synology/index.js @@ -830,7 +830,7 @@ class ControllerSynologyDriver extends CsiBaseDriver { `invalid source_volume_id: ${source_volume_id}` ); } - + // check for other snapshopts with the same name on other volumes and fail as appropriate // TODO: technically this should only be checking lun/snapshots relevant to this specific install of the driver // but alas an isolation/namespacing mechanism does not exist in synology @@ -845,47 +845,35 @@ class ControllerSynologyDriver extends CsiBaseDriver { } // check for already exists - let snapshot = await httpClient.GetSnapshotByLunIDAndName(lun.lun_id, name); - if (snapshot) { - return { - snapshot: { - /** - * The purpose of this field is to give CO guidance on how much space - * is needed to create a volume from this snapshot. - */ - //size_bytes: 0, - snapshot_id: `/lun/${lun.lun_id}/${snapshot.uuid}`, // add shanpshot_uuid //fixme - source_volume_id: source_volume_id, - //https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto - creation_time: { - seconds: snapshot.time, - nanos: 0, - }, - ready_to_use: true, - }, - }; + let snapshot; + snapshot = await httpClient.GetSnapshotByLunIDAndName(lun.lun_id, name); + if (!snapshot) { + let data = Object.assign({}, driver.options.iscsi.lunSnapshotTemplate, { + src_lun_uuid: lun.uuid, + taken_by: "democratic-csi", + description: name, //check + }); + + await httpClient.CreateSnapshot(data); + snapshot = await httpClient.GetSnapshotByLunIDAndName(lun.lun_id, name); + + if (!snapshot) { + throw new Error(`failed to create snapshot`); + } } - let data = Object.assign({}, driver.options.iscsi.lunSnapshotTemplate, { - src_lun_uuid: lun.uuid, - taken_by: "democratic-csi", - description: name, //check - }); - - let response = await httpClient.CreateSnapshot(data); - return { snapshot: { /** * The purpose of this field is to give CO guidance on how much space * is needed to create a volume from this snapshot. */ - //size_bytes: 0, - snapshot_id: `/lun/${lun.lun_id}/${response.body.data.snapshot_uuid}`, + size_bytes: snapshot.total_size, + snapshot_id: `/lun/${lun.lun_id}/${snapshot.uuid}`, // add shanpshot_uuid //fixme source_volume_id: source_volume_id, //https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto creation_time: { - seconds: Math.round(new Date().getTime() / 1000), + seconds: snapshot.time, nanos: 0, }, ready_to_use: true, diff --git a/src/driver/controller-zfs-ssh/index.js b/src/driver/controller-zfs-ssh/index.js index e74144a..7764887 100644 --- a/src/driver/controller-zfs-ssh/index.js +++ b/src/driver/controller-zfs-ssh/index.js @@ -2162,6 +2162,8 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver { } } + // TODO: let things settle to ensure proper size_bytes is reported + // sysctl -d vfs.zfs.txg.timeout # vfs.zfs.txg.timeout: Max seconds worth of delta per txg let properties; properties = await zb.zfs.get( fullSnapshotName, diff --git a/src/driver/freenas/api.js b/src/driver/freenas/api.js index e5a5a28..5fd4c95 100644 --- a/src/driver/freenas/api.js +++ b/src/driver/freenas/api.js @@ -3939,6 +3939,8 @@ class FreeNASApiDriver extends CsiBaseDriver { MANAGED_PROPERTY_NAME, ]; + // TODO: let things settle to ensure proper size_bytes is reported + // sysctl -d vfs.zfs.txg.timeout # vfs.zfs.txg.timeout: Max seconds worth of delta per txg if (detachedSnapshot) { properties = await httpApiClient.DatasetGet( fullSnapshotName,