io.c (0c4fa5bc1aa47d30a8def2dc8345284400d123f1) io.c (93393e698c76c9b95b1fcf9649eef41f9cdbbb07)
1/*
2 * Block layer I/O functions
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 3295 unchanged lines hidden (view full) ---

3304 * 'offset'. Otherwise, it is sufficient for the node to be at least
3305 * 'offset' bytes in length.
3306 */
3307int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
3308 PreallocMode prealloc, BdrvRequestFlags flags,
3309 Error **errp)
3310{
3311 BlockDriverState *bs = child->bs;
1/*
2 * Block layer I/O functions
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 3295 unchanged lines hidden (view full) ---

3304 * 'offset'. Otherwise, it is sufficient for the node to be at least
3305 * 'offset' bytes in length.
3306 */
3307int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
3308 PreallocMode prealloc, BdrvRequestFlags flags,
3309 Error **errp)
3310{
3311 BlockDriverState *bs = child->bs;
3312 BdrvChild *filtered;
3312 BlockDriver *drv = bs->drv;
3313 BdrvTrackedRequest req;
3314 int64_t old_size, new_bytes;
3315 int ret;
3316
3317
3318 /* if bs->drv == NULL, bs is closed, so there's nothing to do here */
3319 if (!drv) {

--- 35 unchanged lines hidden (view full) ---

3355 ret = bdrv_co_write_req_prepare(child, offset - new_bytes, new_bytes, &req,
3356 0);
3357 if (ret < 0) {
3358 error_setg_errno(errp, -ret,
3359 "Failed to prepare request for truncation");
3360 goto out;
3361 }
3362
3313 BlockDriver *drv = bs->drv;
3314 BdrvTrackedRequest req;
3315 int64_t old_size, new_bytes;
3316 int ret;
3317
3318
3319 /* if bs->drv == NULL, bs is closed, so there's nothing to do here */
3320 if (!drv) {

--- 35 unchanged lines hidden (view full) ---

3356 ret = bdrv_co_write_req_prepare(child, offset - new_bytes, new_bytes, &req,
3357 0);
3358 if (ret < 0) {
3359 error_setg_errno(errp, -ret,
3360 "Failed to prepare request for truncation");
3361 goto out;
3362 }
3363
3364 filtered = bdrv_filter_child(bs);
3365
3363 /*
3364 * If the image has a backing file that is large enough that it would
3365 * provide data for the new area, we cannot leave it unallocated because
3366 * then the backing file content would become visible. Instead, zero-fill
3367 * the new area.
3368 *
3369 * Note that if the image has a backing file, but was opened without the
3370 * backing file, taking care of keeping things consistent with that backing

--- 16 unchanged lines hidden (view full) ---

3387
3388 if (drv->bdrv_co_truncate) {
3389 if (flags & ~bs->supported_truncate_flags) {
3390 error_setg(errp, "Block driver does not support requested flags");
3391 ret = -ENOTSUP;
3392 goto out;
3393 }
3394 ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
3366 /*
3367 * If the image has a backing file that is large enough that it would
3368 * provide data for the new area, we cannot leave it unallocated because
3369 * then the backing file content would become visible. Instead, zero-fill
3370 * the new area.
3371 *
3372 * Note that if the image has a backing file, but was opened without the
3373 * backing file, taking care of keeping things consistent with that backing

--- 16 unchanged lines hidden (view full) ---

3390
3391 if (drv->bdrv_co_truncate) {
3392 if (flags & ~bs->supported_truncate_flags) {
3393 error_setg(errp, "Block driver does not support requested flags");
3394 ret = -ENOTSUP;
3395 goto out;
3396 }
3397 ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
3395 } else if (bs->file && drv->is_filter) {
3396 ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp);
3398 } else if (filtered) {
3399 ret = bdrv_co_truncate(filtered, offset, exact, prealloc, flags, errp);
3397 } else {
3398 error_setg(errp, "Image format driver does not support resize");
3399 ret = -ENOTSUP;
3400 goto out;
3401 }
3402 if (ret < 0) {
3403 goto out;
3404 }

--- 50 unchanged lines hidden ---
3400 } else {
3401 error_setg(errp, "Image format driver does not support resize");
3402 ret = -ENOTSUP;
3403 goto out;
3404 }
3405 if (ret < 0) {
3406 goto out;
3407 }

--- 50 unchanged lines hidden ---