qemu-img.c (b2e10493c71160d88bb823cae9a92e806a79b9d6) qemu-img.c (4f6fd3491cf0f768b135ed2e242bd1d1d2a2efec)
1/*
2 * QEMU disk image utility
3 *
4 * Copyright (c) 2003-2008 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

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

295 if (bdrv_set_key(bs, password) < 0) {
296 error_report("invalid password");
297 goto fail;
298 }
299 }
300 return bs;
301fail:
302 if (bs) {
1/*
2 * QEMU disk image utility
3 *
4 * Copyright (c) 2003-2008 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

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

295 if (bdrv_set_key(bs, password) < 0) {
296 error_report("invalid password");
297 goto fail;
298 }
299 }
300 return bs;
301fail:
302 if (bs) {
303 bdrv_delete(bs);
303 bdrv_unref(bs);
304 }
305 return NULL;
306}
307
308static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
309 const char *base_filename,
310 const char *base_fmt)
311{

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

649 } else if (check->leaks) {
650 ret = 3;
651 } else {
652 ret = 0;
653 }
654
655fail:
656 qapi_free_ImageCheck(check);
304 }
305 return NULL;
306}
307
308static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
309 const char *base_filename,
310 const char *base_fmt)
311{

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

649 } else if (check->leaks) {
650 ret = 3;
651 } else {
652 ret = 0;
653 }
654
655fail:
656 qapi_free_ImageCheck(check);
657 bdrv_delete(bs);
657 bdrv_unref(bs);
658
659 return ret;
660}
661
662static int img_commit(int argc, char **argv)
663{
664 int c, ret, flags;
665 const char *filename, *fmt, *cache;

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

719 case -ENOTSUP:
720 error_report("Image is already committed");
721 break;
722 default:
723 error_report("Error while committing image");
724 break;
725 }
726
658
659 return ret;
660}
661
662static int img_commit(int argc, char **argv)
663{
664 int c, ret, flags;
665 const char *filename, *fmt, *cache;

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

719 case -ENOTSUP:
720 error_report("Image is already committed");
721 break;
722 default:
723 error_report("Error while committing image");
724 break;
725 }
726
727 bdrv_delete(bs);
727 bdrv_unref(bs);
728 if (ret) {
729 return 1;
730 }
731 return 0;
732}
733
734/*
735 * Returns true iff the first sector pointed to by 'buf' contains at least

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

1101 qemu_progress_print(((float) nb_sectors / progress_base)*100, 100);
1102 }
1103 }
1104
1105 qprintf(quiet, "Images are identical.\n");
1106 ret = 0;
1107
1108out:
728 if (ret) {
729 return 1;
730 }
731 return 0;
732}
733
734/*
735 * Returns true iff the first sector pointed to by 'buf' contains at least

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

1101 qemu_progress_print(((float) nb_sectors / progress_base)*100, 100);
1102 }
1103 }
1104
1105 qprintf(quiet, "Images are identical.\n");
1106 ret = 0;
1107
1108out:
1109 bdrv_delete(bs2);
1109 bdrv_unref(bs2);
1110 qemu_vfree(buf1);
1111 qemu_vfree(buf2);
1112out2:
1110 qemu_vfree(buf1);
1111 qemu_vfree(buf2);
1112out2:
1113 bdrv_delete(bs1);
1113 bdrv_unref(bs1);
1114out3:
1115 qemu_progress_end();
1116 return ret;
1117}
1118
1119static int img_convert(int argc, char **argv)
1120{
1121 int c, ret = 0, n, n1, bs_n, bs_i, compress, cluster_size,

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

1556 }
1557 }
1558out:
1559 qemu_progress_end();
1560 free_option_parameters(create_options);
1561 free_option_parameters(param);
1562 qemu_vfree(buf);
1563 if (out_bs) {
1114out3:
1115 qemu_progress_end();
1116 return ret;
1117}
1118
1119static int img_convert(int argc, char **argv)
1120{
1121 int c, ret = 0, n, n1, bs_n, bs_i, compress, cluster_size,

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

1556 }
1557 }
1558out:
1559 qemu_progress_end();
1560 free_option_parameters(create_options);
1561 free_option_parameters(param);
1562 qemu_vfree(buf);
1563 if (out_bs) {
1564 bdrv_delete(out_bs);
1564 bdrv_unref(out_bs);
1565 }
1566 if (bs) {
1567 for (bs_i = 0; bs_i < bs_n; bs_i++) {
1568 if (bs[bs_i]) {
1565 }
1566 if (bs) {
1567 for (bs_i = 0; bs_i < bs_n; bs_i++) {
1568 if (bs[bs_i]) {
1569 bdrv_delete(bs[bs_i]);
1569 bdrv_unref(bs[bs_i]);
1570 }
1571 }
1572 g_free(bs);
1573 }
1574 if (ret) {
1575 return 1;
1576 }
1577 return 0;

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

1699 goto err;
1700 }
1701
1702 elem = g_new0(ImageInfoList, 1);
1703 elem->value = info;
1704 *last = elem;
1705 last = &elem->next;
1706
1570 }
1571 }
1572 g_free(bs);
1573 }
1574 if (ret) {
1575 return 1;
1576 }
1577 return 0;

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

1699 goto err;
1700 }
1701
1702 elem = g_new0(ImageInfoList, 1);
1703 elem->value = info;
1704 *last = elem;
1705 last = &elem->next;
1706
1707 bdrv_delete(bs);
1707 bdrv_unref(bs);
1708
1709 filename = fmt = NULL;
1710 if (chain) {
1711 if (info->has_full_backing_filename) {
1712 filename = info->full_backing_filename;
1713 } else if (info->has_backing_filename) {
1714 filename = info->backing_filename;
1715 }

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

1913 if (ret) {
1914 error_report("Could not delete snapshot '%s': %d (%s)",
1915 snapshot_name, ret, strerror(-ret));
1916 }
1917 break;
1918 }
1919
1920 /* Cleanup */
1708
1709 filename = fmt = NULL;
1710 if (chain) {
1711 if (info->has_full_backing_filename) {
1712 filename = info->full_backing_filename;
1713 } else if (info->has_backing_filename) {
1714 filename = info->backing_filename;
1715 }

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

1913 if (ret) {
1914 error_report("Could not delete snapshot '%s': %d (%s)",
1915 snapshot_name, ret, strerror(-ret));
1916 }
1917 break;
1918 }
1919
1920 /* Cleanup */
1921 bdrv_delete(bs);
1921 bdrv_unref(bs);
1922 if (ret) {
1923 return 1;
1924 }
1925 return 0;
1926}
1927
1928static int img_rebase(int argc, char **argv)
1929{

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

2188 * could be dropped from the COW file. Don't do this before switching the
2189 * backing file, in case of a crash this would lead to corruption.
2190 */
2191out:
2192 qemu_progress_end();
2193 /* Cleanup */
2194 if (!unsafe) {
2195 if (bs_old_backing != NULL) {
1922 if (ret) {
1923 return 1;
1924 }
1925 return 0;
1926}
1927
1928static int img_rebase(int argc, char **argv)
1929{

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

2188 * could be dropped from the COW file. Don't do this before switching the
2189 * backing file, in case of a crash this would lead to corruption.
2190 */
2191out:
2192 qemu_progress_end();
2193 /* Cleanup */
2194 if (!unsafe) {
2195 if (bs_old_backing != NULL) {
2196 bdrv_delete(bs_old_backing);
2196 bdrv_unref(bs_old_backing);
2197 }
2198 if (bs_new_backing != NULL) {
2197 }
2198 if (bs_new_backing != NULL) {
2199 bdrv_delete(bs_new_backing);
2199 bdrv_unref(bs_new_backing);
2200 }
2201 }
2202
2200 }
2201 }
2202
2203 bdrv_delete(bs);
2203 bdrv_unref(bs);
2204 if (ret) {
2205 return 1;
2206 }
2207 return 0;
2208}
2209
2210static int img_resize(int argc, char **argv)
2211{

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

2318 error_report("Image is read-only");
2319 break;
2320 default:
2321 error_report("Error resizing image (%d)", -ret);
2322 break;
2323 }
2324out:
2325 if (bs) {
2204 if (ret) {
2205 return 1;
2206 }
2207 return 0;
2208}
2209
2210static int img_resize(int argc, char **argv)
2211{

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

2318 error_report("Image is read-only");
2319 break;
2320 default:
2321 error_report("Error resizing image (%d)", -ret);
2322 break;
2323 }
2324out:
2325 if (bs) {
2326 bdrv_delete(bs);
2326 bdrv_unref(bs);
2327 }
2328 if (ret) {
2329 return 1;
2330 }
2331 return 0;
2332}
2333
2334static const img_cmd_t img_cmds[] = {

--- 37 unchanged lines hidden ---
2327 }
2328 if (ret) {
2329 return 1;
2330 }
2331 return 0;
2332}
2333
2334static const img_cmd_t img_cmds[] = {

--- 37 unchanged lines hidden ---