[libvirt] [PATCH] Implement vol delete for disk pools
Daniel Veillard
veillard at redhat.com
Mon Sep 8 08:16:22 UTC 2008
On Fri, Sep 05, 2008 at 11:17:27PM -0400, Cole Robinson wrote:
> static int
> virStorageBackendDiskDeleteVol(virConnectPtr conn,
> - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
> - virStorageVolDefPtr vol ATTRIBUTE_UNUSED,
> + virStoragePoolObjPtr pool,
> + virStorageVolDefPtr vol,
> unsigned int flags ATTRIBUTE_UNUSED)
> {
> - /* delete a partition */
> - virStorageReportError(conn, VIR_ERR_NO_SUPPORT,
> - _("Disk pools are not yet supported"));
> - return -1;
> + char *part_num = NULL;
> + int n;
> + char devpath[PATH_MAX];
> + char *devname, *srcname;
> +
> + if ((n = readlink(vol->target.path, devpath, sizeof(devpath))) < 0 &&
> + errno != EINVAL) {
> + virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
> + _("Couldn't read volume target path '%s'. %s"),
> + vol->target.path, strerror(errno));
> + return -1;
> + } else if (n <= 0) {
> + strncpy(devpath, vol->target.path, PATH_MAX);
> + } else {
> + devpath[n] = '\0';
> + }
> +
> + devname = basename(devpath);
> + srcname = basename(pool->def->source.devices[0].path);
This seems to leak the two strings and not check for errors. That
would need to be fixed before being commited IMHO
> + DEBUG("devname=%s, srcname=%s", devname, srcname);
> +
> + if (!STRPREFIX(devname, srcname)) {
> + virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
> + _("Volume path '%s' did not start with parent "
> + "pool source device name."), devname);
> + return -1;
> + }
> +
> + part_num = devname + strlen(srcname);
> +
> + if (!part_num) {
> + virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
> + _("cannot parse partition number from target "
> + "'%s'"), devname);
> + return -1;
> + }
> +
> + /* eg parted /dev/sda rm 2 */
> + const char *prog[] = {
> + PARTED,
> + pool->def->source.devices[0].path,
> + "rm",
> + "--script",
> + part_num,
> + NULL,
> + };
> +
> + if (virRun(conn, prog, NULL) < 0)
> + return -1;
> +
> + return 0;
> }
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel at veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
More information about the libvir-list
mailing list