properly implement snapshot size_bytes for controller-*-client and synology drivers

Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
Travis Glenn Hansen 2021-11-28 22:52:49 -07:00
parent 4b7604d278
commit d9bf3d7d2e
4 changed files with 31 additions and 32 deletions

View File

@ -228,6 +228,12 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
return this.getControllerSnapshotBasePath() + "/" + snapshot_id; 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 = {}) { exec(command, args, options = {}) {
args = args || []; args = args || [];
@ -664,13 +670,14 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
await driver.cloneDir(volume_path, snapshot_path); await driver.cloneDir(volume_path, snapshot_path);
} }
let size_bytes = await driver.getDirectoryUsage(snapshot_path);
return { return {
snapshot: { snapshot: {
/** /**
* The purpose of this field is to give CO guidance on how much space * The purpose of this field is to give CO guidance on how much space
* is needed to create a volume from this snapshot. * is needed to create a volume from this snapshot.
*/ */
//size_bytes: 0, size_bytes,
snapshot_id, snapshot_id,
source_volume_id: source_volume_id, source_volume_id: source_volume_id,
//https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto //https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto

View File

@ -830,7 +830,7 @@ class ControllerSynologyDriver extends CsiBaseDriver {
`invalid source_volume_id: ${source_volume_id}` `invalid source_volume_id: ${source_volume_id}`
); );
} }
// 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
// TODO: technically this should only be checking lun/snapshots relevant to this specific install of the driver // 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 // but alas an isolation/namespacing mechanism does not exist in synology
@ -845,47 +845,35 @@ class ControllerSynologyDriver extends CsiBaseDriver {
} }
// check for already exists // check for already exists
let snapshot = await httpClient.GetSnapshotByLunIDAndName(lun.lun_id, name); let snapshot;
if (snapshot) { snapshot = await httpClient.GetSnapshotByLunIDAndName(lun.lun_id, name);
return { if (!snapshot) {
snapshot: { let data = Object.assign({}, driver.options.iscsi.lunSnapshotTemplate, {
/** src_lun_uuid: lun.uuid,
* The purpose of this field is to give CO guidance on how much space taken_by: "democratic-csi",
* is needed to create a volume from this snapshot. description: name, //check
*/ });
//size_bytes: 0,
snapshot_id: `/lun/${lun.lun_id}/${snapshot.uuid}`, // add shanpshot_uuid //fixme await httpClient.CreateSnapshot(data);
source_volume_id: source_volume_id, snapshot = await httpClient.GetSnapshotByLunIDAndName(lun.lun_id, name);
//https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto
creation_time: { if (!snapshot) {
seconds: snapshot.time, throw new Error(`failed to create snapshot`);
nanos: 0, }
},
ready_to_use: true,
},
};
} }
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 { return {
snapshot: { snapshot: {
/** /**
* The purpose of this field is to give CO guidance on how much space * The purpose of this field is to give CO guidance on how much space
* is needed to create a volume from this snapshot. * is needed to create a volume from this snapshot.
*/ */
//size_bytes: 0, size_bytes: snapshot.total_size,
snapshot_id: `/lun/${lun.lun_id}/${response.body.data.snapshot_uuid}`, snapshot_id: `/lun/${lun.lun_id}/${snapshot.uuid}`, // add shanpshot_uuid //fixme
source_volume_id: source_volume_id, source_volume_id: source_volume_id,
//https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto //https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto
creation_time: { creation_time: {
seconds: Math.round(new Date().getTime() / 1000), seconds: snapshot.time,
nanos: 0, nanos: 0,
}, },
ready_to_use: true, ready_to_use: true,

View File

@ -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; let properties;
properties = await zb.zfs.get( properties = await zb.zfs.get(
fullSnapshotName, fullSnapshotName,

View File

@ -3939,6 +3939,8 @@ class FreeNASApiDriver extends CsiBaseDriver {
MANAGED_PROPERTY_NAME, 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) { if (detachedSnapshot) {
properties = await httpApiClient.DatasetGet( properties = await httpApiClient.DatasetGet(
fullSnapshotName, fullSnapshotName,