On 21/05/16 11:58, Michal Privoznik wrote:
On 16.05.2016 09:19, Olga Krishtal wrote:
> The modification of .volWipe callback wipes ploop volume using one of
> given wiping algorithm: dod, nnsa, etc.
> However, in case of ploop volume we need to reinitialize root.hds and
DiskDescriptor.xml.
>
> Signed-off-by: Olga Krishtal <okrishtal(a)virtuozzo.com>
> ---
> src/storage/storage_backend.c | 58 ++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 52 insertions(+), 6 deletions(-)
>
> diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
> index d47a76a..367a887 100644
> --- a/src/storage/storage_backend.c
> +++ b/src/storage/storage_backend.c
> @@ -2295,6 +2295,45 @@ virStorageBackendWipeLocal(virStorageVolDefPtr vol,
> return ret;
> }
>
> +static int
> +virStorageBackendVolWipePloop(virStorageVolDefPtr vol)
> +{
> + virCommandPtr cmd = NULL;
> + char *target_path = NULL;
> + char *disk_desc = NULL;
> + int ret = -1;
> +
> + if (virAsprintf(&target_path, "%s/root.hds", vol->target.path)
< 0)
> + goto cleanup;
> +
> + if (virAsprintf(&disk_desc, "%s/DiskDescriptor.xml",
vol->target.path) < 0)
> + goto cleanup;
> +
> + if (virFileRemove(disk_desc, 0, 0) < 0) {
> + virReportError(errno, _("Failed to delete DiskDescriptor.xml of volume
'%s'"),
> + vol->target.path);
> + goto cleanup;
> + }
> + if (virFileRemove(target_path, 0, 0) < 0) {
> + virReportError(errno, _("failed to delete root.hds of volume
'%s'"),
> + vol->target.path);
> + goto cleanup;
> + }
> +
> + cmd = virCommandNewArgList("ploop", "init", "-s",
NULL);
In virStorageBackendCreatePloop() we try to find this binary prior
executing it. I guess we should do the same here and if not found, deny
whole operation.
Ok,
> +
> + virCommandAddArgFormat(cmd, "%lluM",
VIR_DIV_UP(vol->target.capacity,
> + (1024 * 1024)));
> + virCommandAddArgList(cmd, "-t", "ext4", NULL);
> + virCommandAddArgFormat(cmd, "%s/root.hds", vol->target.path);
This could be just virCommandAddArg(cmd, target_path);
Will fix
> + ret = virCommandRun(cmd, NULL);
> +
> + cleanup:
> + VIR_FREE(disk_desc);
> + VIR_FREE(target_path);
> + virCommandFree(cmd);
> + return ret;
> +}
Otherwise looking good.
Michal
Thanks