[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 06/44] nbd: Clean up ioctl handling of qemu-nbd -
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v3 06/44] nbd: Clean up ioctl handling of qemu-nbd -c |
Date: |
Fri, 22 Apr 2016 17:40:14 -0600 |
The kernel ioctl() interface into NBD is limited to 'unsigned long';
we MUST pass in input with that type (and not int or size_t, as
there may be platform ABIs where the wrong types promote incorrectly
through var-args). Furthermore, on 32-bit platforms, the kernel
is limited to a maximum export size of 2T (our BLKSIZE of 512 times
a SIZE_BLOCKS constrained by 32 bit unsigned long).
Signed-off-by: Eric Blake <address@hidden>
---
nbd/client.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/nbd/client.c b/nbd/client.c
index ae9fdd4..f1afa49 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -593,9 +593,15 @@ fail:
#ifdef __linux__
int nbd_init(int fd, QIOChannelSocket *sioc, uint32_t flags, off_t size)
{
+ unsigned long sectors = size / BDRV_SECTOR_SIZE;
+ if (size / BDRV_SECTOR_SIZE != sectors) {
+ LOG("Export size %lld too large for 32-bit kernel", (long long) size);
+ return -E2BIG;
+ }
+
TRACE("Setting NBD socket");
- if (ioctl(fd, NBD_SET_SOCK, sioc->fd) < 0) {
+ if (ioctl(fd, NBD_SET_SOCK, (unsigned long) sioc->fd) < 0) {
int serrno = errno;
LOG("Failed to set NBD socket");
return -serrno;
@@ -603,21 +609,25 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint32_t
flags, off_t size)
TRACE("Setting block size to %lu", (unsigned long)BDRV_SECTOR_SIZE);
- if (ioctl(fd, NBD_SET_BLKSIZE, (size_t)BDRV_SECTOR_SIZE) < 0) {
+ if (ioctl(fd, NBD_SET_BLKSIZE, (unsigned long)BDRV_SECTOR_SIZE) < 0) {
int serrno = errno;
LOG("Failed setting NBD block size");
return -serrno;
}
- TRACE("Setting size to %zd block(s)", (size_t)(size / BDRV_SECTOR_SIZE));
+ TRACE("Setting size to %lu block(s)", sectors);
+ if (size % BDRV_SECTOR_SIZE) {
+ TRACE("Ignoring trailing %d bytes of export",
+ (int) (size % BDRV_SECTOR_SIZE));
+ }
- if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE)) < 0)
{
+ if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) {
int serrno = errno;
LOG("Failed setting size (in blocks)");
return -serrno;
}
- if (ioctl(fd, NBD_SET_FLAGS, flags) < 0) {
+ if (ioctl(fd, NBD_SET_FLAGS, (unsigned long) flags) < 0) {
if (errno == ENOTTY) {
int read_only = (flags & NBD_FLAG_READ_ONLY) != 0;
TRACE("Setting readonly attribute");
--
2.5.5
- [Qemu-devel] [PATCH v3 15/44] m25p80: Switch to byte-based block access, (continued)
- [Qemu-devel] [PATCH v3 15/44] m25p80: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 14/44] sd: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 13/44] pflash: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 16/44] atapi: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 18/44] qemu-img: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 23/44] qemu-io: Add missing option documentation, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 29/44] nbd: Avoid magic number for NBD max name size, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 31/44] nbd: Share common reply-sending code in server, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 06/44] nbd: Clean up ioctl handling of qemu-nbd -c,
Eric Blake <=
- [Qemu-devel] [PATCH v3 09/44] block: Allow BDRV_REQ_FUA through blk_pwrite(), Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 12/44] onenand: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 17/44] nbd: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 11/44] nand: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 20/44] block: Switch blk_read_unthrottled() to byte interface, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 22/44] block: Kill blk_write(), blk_read(), Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 21/44] block: Switch blk_write_zeroes() to byte interface, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 28/44] nbd: Detect servers that send unexpected error values, Eric Blake, 2016/04/22