Result StorageVolControlThread::resizeStorageVol() { Result result; result.name = QString("%1_%2").arg(task.srcConName).arg(currPoolName); QString name = task.object; if (currStoragePool!=NULL) { virStoragePoolFree(currStoragePool); currStoragePool = NULL; }; currStoragePool = virStoragePoolLookupByName( *task.srcConnPtr, currPoolName.toUtf8().data()); unsigned long long capacity = task.args.size; bool resized = false; virStorageVol *storageVol = virStorageVolLookupByName( currStoragePool, name.toUtf8().data()); if ( storageVol!=NULL ) { int ret = virStorageVolResize( storageVol, capacity, VIR_STORAGE_VOL_RESIZE_ALLOCATE | VIR_STORAGE_VOL_RESIZE_SHRINK); if ( ret<0 ) { result.err = sendConnErrors(); } else resized = true; virStorageVolFree(storageVol); } else result.err = sendConnErrors(); result.msg.append( QString("'<b>%1</b>' StorageVol %2 Resized to %3 (bytes).") .arg(name).arg((resized)?"":"don't").arg(capacity)); result.result = resized; return result; }
static bool cmdVolResize(vshControl *ctl, const vshCmd *cmd) { virStorageVolPtr vol; const char *capacityStr = NULL; unsigned long long capacity = 0; unsigned int flags = 0; bool ret = false; bool delta = false; if (vshCommandOptBool(cmd, "allocate")) flags |= VIR_STORAGE_VOL_RESIZE_ALLOCATE; if (vshCommandOptBool(cmd, "delta")) { delta = true; flags |= VIR_STORAGE_VOL_RESIZE_DELTA; } if (vshCommandOptBool(cmd, "shrink")) flags |= VIR_STORAGE_VOL_RESIZE_SHRINK; if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0) goto cleanup; virSkipSpaces(&capacityStr); if (*capacityStr == '-') { /* The API always requires a positive value; but we allow a * negative value for convenience. */ if (delta && vshCommandOptBool(cmd, "shrink")){ capacityStr++; } else { vshError(ctl, "%s", _("negative size requires --delta and --shrink")); goto cleanup; } } if (vshVolSize(capacityStr, &capacity) < 0) { vshError(ctl, _("Malformed size %s"), capacityStr); goto cleanup; } if (virStorageVolResize(vol, capacity, flags) == 0) { vshPrint(ctl, delta ? _("Size of volume '%s' successfully changed by %s\n") : _("Size of volume '%s' successfully changed to %s\n"), virStorageVolGetName(vol), capacityStr); ret = true; } else { vshError(ctl, delta ? _("Failed to change size of volume '%s' by %s\n") : _("Failed to change size of volume '%s' to %s\n"), virStorageVolGetName(vol), capacityStr); ret = false; } cleanup: virStorageVolFree(vol); return ret; }
/** * gvir_storage_vol_resize: * @vol: the storage volume to resize * @capacity: the new capacity of the volume * @flags: (type GVirStorageVolResizeFlags): the flags * @err: Return location for errors, or NULL * * Changes the capacity of the storage volume @vol to @capacity. * * Returns: #TRUE success, #FALSE otherwise */ gboolean gvir_storage_vol_resize(GVirStorageVol *vol, guint64 capacity, guint flags, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); if (virStorageVolResize(vol->priv->handle, capacity, flags) < 0) { gvir_set_error_literal(err, GVIR_STORAGE_VOL_ERROR, 0, "Unable to resize volume storage"); return FALSE; } return TRUE; }