block.c (004915a96a7a40e942ac85e6d22518cbcd283506) | block.c (e2dd273754eb9a47c33660b4e14074e8e96ada4d) |
---|---|
1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * Copyright (c) 2020 Virtuozzo International GmbH. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal --- 5750 unchanged lines hidden (view full) --- 5759/* 5760 * Return values: 5761 * 0 - success 5762 * -EINVAL - backing format specified, but no file 5763 * -ENOSPC - can't update the backing file because no space is left in the 5764 * image file header 5765 * -ENOTSUP - format driver doesn't support changing the backing file 5766 */ | 1/* 2 * QEMU System Emulator block driver 3 * 4 * Copyright (c) 2003 Fabrice Bellard 5 * Copyright (c) 2020 Virtuozzo International GmbH. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal --- 5750 unchanged lines hidden (view full) --- 5759/* 5760 * Return values: 5761 * 0 - success 5762 * -EINVAL - backing format specified, but no file 5763 * -ENOSPC - can't update the backing file because no space is left in the 5764 * image file header 5765 * -ENOTSUP - format driver doesn't support changing the backing file 5766 */ |
5767int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file, 5768 const char *backing_fmt, bool require) | 5767int coroutine_fn 5768bdrv_co_change_backing_file(BlockDriverState *bs, const char *backing_file, 5769 const char *backing_fmt, bool require) |
5769{ 5770 BlockDriver *drv = bs->drv; 5771 int ret; 5772 | 5770{ 5771 BlockDriver *drv = bs->drv; 5772 int ret; 5773 |
5773 GLOBAL_STATE_CODE(); | 5774 IO_CODE(); |
5774 5775 if (!drv) { 5776 return -ENOMEDIUM; 5777 } 5778 5779 /* Backing file format doesn't make sense without a backing file */ 5780 if (backing_fmt && !backing_file) { 5781 return -EINVAL; 5782 } 5783 5784 if (require && backing_file && !backing_fmt) { 5785 return -EINVAL; 5786 } 5787 | 5775 5776 if (!drv) { 5777 return -ENOMEDIUM; 5778 } 5779 5780 /* Backing file format doesn't make sense without a backing file */ 5781 if (backing_fmt && !backing_file) { 5782 return -EINVAL; 5783 } 5784 5785 if (require && backing_file && !backing_fmt) { 5786 return -EINVAL; 5787 } 5788 |
5788 if (drv->bdrv_change_backing_file != NULL) { 5789 ret = drv->bdrv_change_backing_file(bs, backing_file, backing_fmt); | 5789 if (drv->bdrv_co_change_backing_file != NULL) { 5790 ret = drv->bdrv_co_change_backing_file(bs, backing_file, backing_fmt); |
5790 } else { 5791 ret = -ENOTSUP; 5792 } 5793 5794 if (ret == 0) { 5795 pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?: ""); 5796 pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fmt ?: ""); 5797 pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), --- 2840 unchanged lines hidden --- | 5791 } else { 5792 ret = -ENOTSUP; 5793 } 5794 5795 if (ret == 0) { 5796 pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?: ""); 5797 pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fmt ?: ""); 5798 pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), --- 2840 unchanged lines hidden --- |