[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RFC v11 2/6] raw, qcow2: don't convert file size to
From: |
Hu Tao |
Subject: |
[Qemu-devel] [PATCH RFC v11 2/6] raw, qcow2: don't convert file size to sector size |
Date: |
Wed, 2 Jul 2014 16:17:29 +0800 |
and avoid converting it back later.
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Hu Tao <address@hidden>
---
block/qcow2.c | 10 +++++-----
block/raw-posix.c | 6 +++---
block/raw-win32.c | 6 +++---
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 0dfbb9a..05df4b9 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1715,7 +1715,7 @@ static int qcow2_create2(const char *filename, int64_t
total_size,
}
/* Okay, now that we have a valid image, let's give it the right size */
- ret = bdrv_truncate(bs, total_size * BDRV_SECTOR_SIZE);
+ ret = bdrv_truncate(bs, total_size);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not resize image");
goto out;
@@ -1768,7 +1768,7 @@ static int qcow2_create(const char *filename, QemuOpts
*opts, Error **errp)
char *backing_file = NULL;
char *backing_fmt = NULL;
char *buf = NULL;
- uint64_t sectors = 0;
+ uint64_t size = 0;
int flags = 0;
size_t cluster_size = DEFAULT_CLUSTER_SIZE;
int prealloc = 0;
@@ -1777,8 +1777,8 @@ static int qcow2_create(const char *filename, QemuOpts
*opts, Error **errp)
int ret;
/* Read out options */
- sectors = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
- BDRV_SECTOR_SIZE);
+ size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
+ BDRV_SECTOR_SIZE);
backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
@@ -1828,7 +1828,7 @@ static int qcow2_create(const char *filename, QemuOpts
*opts, Error **errp)
goto finish;
}
- ret = qcow2_create2(filename, sectors, backing_file, backing_fmt, flags,
+ ret = qcow2_create2(filename, size, backing_file, backing_fmt, flags,
cluster_size, prealloc, opts, version, &local_err);
if (local_err) {
error_propagate(errp, local_err);
diff --git a/block/raw-posix.c b/block/raw-posix.c
index b861bd9..58c51d8 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1282,8 +1282,8 @@ static int raw_create(const char *filename, QemuOpts
*opts, Error **errp)
strstart(filename, "file:", &filename);
/* Read out options */
- total_size = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
- BDRV_SECTOR_SIZE);
+ total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
+ BDRV_SECTOR_SIZE);
fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -1291,7 +1291,7 @@ static int raw_create(const char *filename, QemuOpts
*opts, Error **errp)
result = -errno;
error_setg_errno(errp, -result, "Could not create file");
} else {
- if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
+ if (ftruncate(fd, total_size) != 0) {
result = -errno;
error_setg_errno(errp, -result, "Could not resize file");
}
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 1e1880d..9bf8225 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -511,8 +511,8 @@ static int raw_create(const char *filename, QemuOpts *opts,
Error **errp)
strstart(filename, "file:", &filename);
/* Read out options */
- total_size = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
- BDRV_SECTOR_SIZE);
+ total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
+ BDRV_SECTOR_SIZE);
fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -521,7 +521,7 @@ static int raw_create(const char *filename, QemuOpts *opts,
Error **errp)
return -EIO;
}
set_sparse(fd);
- ftruncate(fd, total_size * 512);
+ ftruncate(fd, total_size);
qemu_close(fd);
return 0;
}
--
1.9.3
- [Qemu-devel] [PATCH RFC v11 0/6] qcow2, raw: add preallocation=full and preallocation=falloc, Hu Tao, 2014/07/02
- [Qemu-devel] [PATCH RFC v11 1/6] block: round up file size to nearest sector, Hu Tao, 2014/07/02
- [Qemu-devel] [PATCH RFC v11 2/6] raw, qcow2: don't convert file size to sector size,
Hu Tao <=
- [Qemu-devel] [PATCH RFC v11 3/6] rename parse_enum_option to qapi_enum_parse and make it public, Hu Tao, 2014/07/02
- [Qemu-devel] [PATCH RFC v11 4/6] qapi: introduce PreallocMode and a new PreallocMode full., Hu Tao, 2014/07/02
- [Qemu-devel] [PATCH RFC v11 5/6] raw-posix: Add falloc and full preallocation option, Hu Tao, 2014/07/02
- [Qemu-devel] [PATCH RFC v11 6/6] qcow2: Add falloc and full preallocation option, Hu Tao, 2014/07/02