aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/file-posix.c7
-rw-r--r--block/io.c2
-rw-r--r--block/nbd.c18
3 files changed, 19 insertions, 8 deletions
diff --git a/block/file-posix.c b/block/file-posix.c
index 71f168ee2f..87c5a4ccbd 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1588,6 +1588,13 @@ static int handle_aiocb_write_zeroes(void *opaque)
if (s->has_write_zeroes) {
int ret = do_fallocate(s->fd, FALLOC_FL_ZERO_RANGE,
aiocb->aio_offset, aiocb->aio_nbytes);
+ if (ret == -EINVAL) {
+ /*
+ * Allow falling back to pwrite for file systems that
+ * do not support fallocate() for an unaligned byte range.
+ */
+ return -ENOTSUP;
+ }
if (ret == 0 || ret != -ENOTSUP) {
return ret;
}
diff --git a/block/io.c b/block/io.c
index 0fa10831ed..16a598fd08 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1746,7 +1746,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
assert(!bs->supported_zero_flags);
}
- if (ret < 0 && !(flags & BDRV_REQ_NO_FALLBACK)) {
+ if (ret == -ENOTSUP && !(flags & BDRV_REQ_NO_FALLBACK)) {
/* Fall back to bounce buffer if write zeroes is unsupported */
BdrvRequestFlags write_flags = flags & ~BDRV_REQ_ZERO_WRITE;
diff --git a/block/nbd.c b/block/nbd.c
index beed46fb34..813c40d8f0 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -1044,6 +1044,10 @@ static int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
if (!(flags & BDRV_REQ_MAY_UNMAP)) {
request.flags |= NBD_CMD_FLAG_NO_HOLE;
}
+ if (flags & BDRV_REQ_NO_FALLBACK) {
+ assert(s->info.flags & NBD_FLAG_SEND_FAST_ZERO);
+ request.flags |= NBD_CMD_FLAG_FAST_ZERO;
+ }
if (!bytes) {
return 0;
@@ -1239,6 +1243,9 @@ static int nbd_client_connect(BlockDriverState *bs, Error **errp)
}
if (s->info.flags & NBD_FLAG_SEND_WRITE_ZEROES) {
bs->supported_zero_flags |= BDRV_REQ_MAY_UNMAP;
+ if (s->info.flags & NBD_FLAG_SEND_FAST_ZERO) {
+ bs->supported_zero_flags |= BDRV_REQ_NO_FALLBACK;
+ }
}
s->sioc = sioc;
@@ -1374,7 +1381,7 @@ static bool nbd_has_filename_options_conflict(QDict *options, Error **errp)
static void nbd_parse_filename(const char *filename, QDict *options,
Error **errp)
{
- char *file;
+ g_autofree char *file = NULL;
char *export_name;
const char *host_spec;
const char *unixpath;
@@ -1396,7 +1403,7 @@ static void nbd_parse_filename(const char *filename, QDict *options,
export_name = strstr(file, EN_OPTSTR);
if (export_name) {
if (export_name[strlen(EN_OPTSTR)] == 0) {
- goto out;
+ return;
}
export_name[0] = 0; /* truncate 'file' */
export_name += strlen(EN_OPTSTR);
@@ -1407,11 +1414,11 @@ static void nbd_parse_filename(const char *filename, QDict *options,
/* extract the host_spec - fail if it's not nbd:... */
if (!strstart(file, "nbd:", &host_spec)) {
error_setg(errp, "File name string for NBD must start with 'nbd:'");
- goto out;
+ return;
}
if (!*host_spec) {
- goto out;
+ return;
}
/* are we a UNIX or TCP socket? */
@@ -1431,9 +1438,6 @@ static void nbd_parse_filename(const char *filename, QDict *options,
out_inet:
qapi_free_InetSocketAddress(addr);
}
-
-out:
- g_free(file);
}
static bool nbd_process_legacy_socket_options(QDict *output_options,