|
@@ -64,6 +64,7 @@ enum {
|
|
OPTION_TARGET_IMAGE_OPTS = 263,
|
|
OPTION_TARGET_IMAGE_OPTS = 263,
|
|
OPTION_SIZE = 264,
|
|
OPTION_SIZE = 264,
|
|
OPTION_PREALLOCATION = 265,
|
|
OPTION_PREALLOCATION = 265,
|
|
|
|
+ OPTION_SHRINK = 266,
|
|
};
|
|
};
|
|
|
|
|
|
typedef enum OutputFormat {
|
|
typedef enum OutputFormat {
|
|
@@ -3436,6 +3437,7 @@ static int img_resize(int argc, char **argv)
|
|
},
|
|
},
|
|
};
|
|
};
|
|
bool image_opts = false;
|
|
bool image_opts = false;
|
|
|
|
+ bool shrink = false;
|
|
|
|
|
|
/* Remove size from argv manually so that negative numbers are not treated
|
|
/* Remove size from argv manually so that negative numbers are not treated
|
|
* as options by getopt. */
|
|
* as options by getopt. */
|
|
@@ -3454,6 +3456,7 @@ static int img_resize(int argc, char **argv)
|
|
{"object", required_argument, 0, OPTION_OBJECT},
|
|
{"object", required_argument, 0, OPTION_OBJECT},
|
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
|
{"preallocation", required_argument, 0, OPTION_PREALLOCATION},
|
|
{"preallocation", required_argument, 0, OPTION_PREALLOCATION},
|
|
|
|
+ {"shrink", no_argument, 0, OPTION_SHRINK},
|
|
{0, 0, 0, 0}
|
|
{0, 0, 0, 0}
|
|
};
|
|
};
|
|
c = getopt_long(argc, argv, ":f:hq",
|
|
c = getopt_long(argc, argv, ":f:hq",
|
|
@@ -3496,6 +3499,9 @@ static int img_resize(int argc, char **argv)
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
+ case OPTION_SHRINK:
|
|
|
|
+ shrink = true;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (optind != argc - 1) {
|
|
if (optind != argc - 1) {
|
|
@@ -3569,6 +3575,23 @@ static int img_resize(int argc, char **argv)
|
|
goto out;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (total_size < current_size && !shrink) {
|
|
|
|
+ warn_report("Shrinking an image will delete all data beyond the "
|
|
|
|
+ "shrunken image's end. Before performing such an "
|
|
|
|
+ "operation, make sure there is no important data there.");
|
|
|
|
+
|
|
|
|
+ if (g_strcmp0(bdrv_get_format_name(blk_bs(blk)), "raw") != 0) {
|
|
|
|
+ error_report(
|
|
|
|
+ "Use the --shrink option to perform a shrink operation.");
|
|
|
|
+ ret = -1;
|
|
|
|
+ goto out;
|
|
|
|
+ } else {
|
|
|
|
+ warn_report("Using the --shrink option will suppress this message. "
|
|
|
|
+ "Note that future versions of qemu-img may refuse to "
|
|
|
|
+ "shrink images without this option.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
ret = blk_truncate(blk, total_size, prealloc, &err);
|
|
ret = blk_truncate(blk, total_size, prealloc, &err);
|
|
if (!ret) {
|
|
if (!ret) {
|
|
qprintf(quiet, "Image resized.\n");
|
|
qprintf(quiet, "Image resized.\n");
|