From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSTED-0000j5-L2 for qemu-devel@nongnu.org; Fri, 12 Sep 2014 11:57:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XSTE9-0000o8-9q for qemu-devel@nongnu.org; Fri, 12 Sep 2014 11:57:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSTE9-0000o3-2s for qemu-devel@nongnu.org; Fri, 12 Sep 2014 11:57:37 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8CFvZrJ005752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 12 Sep 2014 11:57:36 -0400 From: Kevin Wolf Date: Fri, 12 Sep 2014 17:57:03 +0200 Message-Id: <1410537426-9917-20-git-send-email-kwolf@redhat.com> In-Reply-To: <1410537426-9917-1-git-send-email-kwolf@redhat.com> References: <1410537426-9917-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 19/22] block: don't convert file size to sector size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Hu Tao and avoid converting it back later. Signed-off-by: Hu Tao Reviewed-by: Max Reitz Reviewed-by: Beno=C3=AEt Canet Signed-off-by: Kevin Wolf --- block/gluster.c | 9 ++++----- block/qcow.c | 8 ++++---- block/qcow2.c | 10 +++++----- block/raw-posix.c | 12 ++++++------ block/raw-win32.c | 6 +++--- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 65c7a58..1eb3a8c 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -494,8 +494,8 @@ static int qemu_gluster_create(const char *filename, goto out; } =20 - total_size =3D DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SI= ZE, 0), - BDRV_SECTOR_SIZE); + total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, = 0), + BDRV_SECTOR_SIZE); =20 tmp =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); if (!tmp || !strcmp(tmp, "off")) { @@ -516,9 +516,8 @@ static int qemu_gluster_create(const char *filename, if (!fd) { ret =3D -errno; } else { - if (!glfs_ftruncate(fd, total_size * BDRV_SECTOR_SIZE)) { - if (prealloc && qemu_gluster_zerofill(fd, 0, - total_size * BDRV_SECTOR_SIZE)) { + if (!glfs_ftruncate(fd, total_size)) { + if (prealloc && qemu_gluster_zerofill(fd, 0, total_size)) { ret =3D -errno; } } else { diff --git a/block/qcow.c b/block/qcow.c index 041af26..a87bd69 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -725,8 +725,8 @@ static int qcow_create(const char *filename, QemuOpts= *opts, Error **errp) BlockDriverState *qcow_bs; =20 /* Read out options */ - total_size =3D DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SI= ZE, 0), - BDRV_SECTOR_SIZE); + total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, = 0), + BDRV_SECTOR_SIZE); backing_file =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { flags |=3D BLOCK_FLAG_ENCRYPT; @@ -754,7 +754,7 @@ static int qcow_create(const char *filename, QemuOpts= *opts, Error **errp) memset(&header, 0, sizeof(header)); header.magic =3D cpu_to_be32(QCOW_MAGIC); header.version =3D cpu_to_be32(QCOW_VERSION); - header.size =3D cpu_to_be64(total_size * 512); + header.size =3D cpu_to_be64(total_size); header_size =3D sizeof(header); backing_filename_len =3D 0; if (backing_file) { @@ -776,7 +776,7 @@ static int qcow_create(const char *filename, QemuOpts= *opts, Error **errp) } header_size =3D (header_size + 7) & ~7; shift =3D header.cluster_bits + header.l2_bits; - l1_size =3D ((total_size * 512) + (1LL << shift) - 1) >> shift; + l1_size =3D (total_size + (1LL << shift) - 1) >> shift; =20 header.l1_table_offset =3D cpu_to_be64(header_size); if (flags & BLOCK_FLAG_ENCRYPT) { diff --git a/block/qcow2.c b/block/qcow2.c index c8050e5..cf27c3f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1859,7 +1859,7 @@ static int qcow2_create2(const char *filename, int6= 4_t total_size, } =20 /* Okay, now that we have a valid image, let's give it the right siz= e */ - ret =3D bdrv_truncate(bs, total_size * BDRV_SECTOR_SIZE); + ret =3D bdrv_truncate(bs, total_size); if (ret < 0) { error_setg_errno(errp, -ret, "Could not resize image"); goto out; @@ -1912,7 +1912,7 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) char *backing_file =3D NULL; char *backing_fmt =3D NULL; char *buf =3D NULL; - uint64_t sectors =3D 0; + uint64_t size =3D 0; int flags =3D 0; size_t cluster_size =3D DEFAULT_CLUSTER_SIZE; int prealloc =3D 0; @@ -1921,8 +1921,8 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) int ret; =20 /* Read out options */ - sectors =3D DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE,= 0), - BDRV_SECTOR_SIZE); + size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), + BDRV_SECTOR_SIZE); backing_file =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); backing_fmt =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT); if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { @@ -1972,7 +1972,7 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) goto finish; } =20 - ret =3D qcow2_create2(filename, sectors, backing_file, backing_fmt, = flags, + ret =3D qcow2_create2(filename, size, backing_file, backing_fmt, fla= gs, cluster_size, prealloc, opts, version, &local_er= r); if (local_err) { error_propagate(errp, local_err); diff --git a/block/raw-posix.c b/block/raw-posix.c index 9c22e3f..7208c05 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1369,8 +1369,8 @@ static int raw_create(const char *filename, QemuOpt= s *opts, Error **errp) strstart(filename, "file:", &filename); =20 /* Read out options */ - total_size =3D DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SI= ZE, 0), - BDRV_SECTOR_SIZE); + total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, = 0), + BDRV_SECTOR_SIZE); nocow =3D qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false); =20 fd =3D qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, @@ -1394,7 +1394,7 @@ static int raw_create(const char *filename, QemuOpt= s *opts, Error **errp) #endif } =20 - if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) !=3D 0) { + if (ftruncate(fd, total_size) !=3D 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not resize file"); } @@ -1966,8 +1966,8 @@ static int hdev_create(const char *filename, QemuOp= ts *opts, (void)has_prefix; =20 /* Read out options */ - total_size =3D DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SI= ZE, 0), - BDRV_SECTOR_SIZE); + total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, = 0), + BDRV_SECTOR_SIZE); =20 fd =3D qemu_open(filename, O_WRONLY | O_BINARY); if (fd < 0) { @@ -1983,7 +1983,7 @@ static int hdev_create(const char *filename, QemuOp= ts *opts, error_setg(errp, "The given file is neither a block nor a character de= vice"); ret =3D -ENODEV; - } else if (lseek(fd, 0, SEEK_END) < total_size * BDRV_SECTOR_SIZE) { + } else if (lseek(fd, 0, SEEK_END) < total_size) { error_setg(errp, "Device is too small"); ret =3D -ENOSPC; } 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); =20 /* Read out options */ - total_size =3D DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SI= ZE, 0), - BDRV_SECTOR_SIZE); + total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, = 0), + BDRV_SECTOR_SIZE); =20 fd =3D 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; } --=20 1.8.3.1