void qmp_block_resize(bool has_device, const char *device,
                      bool has_node_name, const char *node_name,
                      int64_t size, Error **errp)
{
    Error *local_err = NULL;
    BlockDriverState *bs;
    int ret;
    bs = bdrv_lookup_bs(has_device ? device : NULL,
                        has_node_name ? node_name : NULL,
                        &local_err);
    if (local_err) {
        error_propagate(errp, local_err);
    if (!bdrv_is_first_non_filter(bs)) {
        error_set(errp, QERR_FEATURE_DISABLED, "resize");
    if (size < 0) {
        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size");
    /* complete all in-flight operations before resizing the device */
    bdrv_drain_all();
    ret = bdrv_truncate(bs, size);
    switch (ret) {
    case 0:
        break;
    case -ENOMEDIUM:
        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
        break;
    case -ENOTSUP:
        error_set(errp, QERR_UNSUPPORTED);
        break;
    case -EACCES:
        error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
        break;
    case -EBUSY:
        break;
    default:
        error_setg_errno(errp, -ret, "Could not resize");
        break;
void qmp_block_resize(bool has_device, const char *device,
                      bool has_node_name, const char *node_name,
                      int64_t size, Error **errp)
{
    Error *local_err = NULL;
    BlockDriverState *bs;
    int ret;
    bs = bdrv_lookup_bs(has_device ? device : NULL,
                        has_node_name ? node_name : NULL,
                        &local_err);
    if (local_err) {
        error_propagate(errp, local_err);
    if (!bdrv_is_first_non_filter(bs)) {
        error_set(errp, QERR_FEATURE_DISABLED, "resize");
    if (size < 0) {
        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size");
    
    bdrv_drain_all();
    ret = bdrv_truncate(bs, size);
    switch (ret) {
    case 0:
        break;
    case -ENOMEDIUM:
        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
        break;
    case -ENOTSUP:
        error_set(errp, QERR_UNSUPPORTED);
        break;
    case -EACCES:
        error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
        break;
    case -EBUSY:
        break;
    default:
        error_setg_errno(errp, -ret, "Could not resize");
        break;
void FUNC_0(bool VAR_0, const char *VAR_1,
                      bool VAR_2, const char *VAR_3,
                      int64_t VAR_4, Error **VAR_5)
{
    Error *local_err = NULL;
    BlockDriverState *bs;
    int VAR_6;
    bs = bdrv_lookup_bs(VAR_0 ? VAR_1 : NULL,
                        VAR_2 ? VAR_3 : NULL,
                        &local_err);
    if (local_err) {
        error_propagate(VAR_5, local_err);
    if (!bdrv_is_first_non_filter(bs)) {
        error_set(VAR_5, QERR_FEATURE_DISABLED, "resize");
    if (VAR_4 < 0) {
        error_set(VAR_5, QERR_INVALID_PARAMETER_VALUE, "VAR_4", "a >0 VAR_4");
    
    bdrv_drain_all();
    VAR_6 = bdrv_truncate(bs, VAR_4);
    switch (VAR_6) {
    case 0:
        break;
    case -ENOMEDIUM:
        error_set(VAR_5, QERR_DEVICE_HAS_NO_MEDIUM, VAR_1);
        break;
    case -ENOTSUP:
        error_set(VAR_5, QERR_UNSUPPORTED);
        break;
    case -EACCES:
        error_set(VAR_5, QERR_DEVICE_IS_READ_ONLY, VAR_1);
        break;
    case -EBUSY:
        break;
    default:
        error_setg_errno(VAR_5, -VAR_6, "Could not resize");
        break;
void FUNC_0(bool VAR_0, const char *VAR_1,
bool VAR_2, const char *VAR_3,
int64_t VAR_4, Error **VAR_5)
{ Error *local_err = NULL; BlockDriverState *bs; int VAR_6; bs = bdrv_lookup_bs(VAR_0 ? VAR_1 : NULL,
VAR_2 ? VAR_3 : NULL,
&local_err); if (local_err) { error_propagate(VAR_5, local_err); if (!bdrv_is_first_non_filter(bs)) { error_set(VAR_5, QERR_FEATURE_DISABLED, "resize"); if (VAR_4 < 0) { error_set(VAR_5, QERR_INVALID_PARAMETER_VALUE, "VAR_4", "a >0 VAR_4"); bdrv_drain_all(); VAR_6 = bdrv_truncate(bs, VAR_4); switch (VAR_6) { case 0:
break; case -ENOMEDIUM:
error_set(VAR_5, QERR_DEVICE_HAS_NO_MEDIUM, VAR_1); break; case -ENOTSUP:
error_set(VAR_5, QERR_UNSUPPORTED); break; case -EACCES:
error_set(VAR_5, QERR_DEVICE_IS_READ_ONLY, VAR_1); break; case -EBUSY:
break; default:
error_setg_errno(VAR_5, -VAR_6, "Could not resize"); break;