22c213
From 3d3509c010129bd15eb1f5ec1a7b9eedcdbf23f6 Mon Sep 17 00:00:00 2001
22c213
From: Maxim Levitsky <mlevitsk@redhat.com>
22c213
Date: Wed, 11 Mar 2020 10:51:44 +0000
22c213
Subject: [PATCH 03/20] file-posix: Drop hdev_co_create_opts()
22c213
22c213
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
22c213
Message-id: <20200311105147.13208-4-mlevitsk@redhat.com>
22c213
Patchwork-id: 94225
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 3/6] file-posix: Drop hdev_co_create_opts()
22c213
Bugzilla: 1640894
22c213
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
22c213
RH-Acked-by: John Snow <jsnow@redhat.com>
22c213
RH-Acked-by: Max Reitz <mreitz@redhat.com>
22c213
22c213
From: Max Reitz <mreitz@redhat.com>
22c213
22c213
The generic fallback implementation effectively does the same.
22c213
22c213
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
22c213
Signed-off-by: Max Reitz <mreitz@redhat.com>
22c213
Message-Id: <20200122164532.178040-4-mreitz@redhat.com>
22c213
Signed-off-by: Max Reitz <mreitz@redhat.com>
22c213
(cherry picked from commit 87ca3b8fa615b278b33cabf9ed22b3f44b5214ba)
22c213
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 block/file-posix.c | 67 ------------------------------------------------------
22c213
 1 file changed, 67 deletions(-)
22c213
22c213
diff --git a/block/file-posix.c b/block/file-posix.c
22c213
index 1b805bd..fd29372 100644
22c213
--- a/block/file-posix.c
22c213
+++ b/block/file-posix.c
22c213
@@ -3418,67 +3418,6 @@ static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs,
22c213
     return raw_do_pwrite_zeroes(bs, offset, bytes, flags, true);
22c213
 }
22c213
 
22c213
-static int coroutine_fn hdev_co_create_opts(const char *filename, QemuOpts *opts,
22c213
-                                            Error **errp)
22c213
-{
22c213
-    int fd;
22c213
-    int ret = 0;
22c213
-    struct stat stat_buf;
22c213
-    int64_t total_size = 0;
22c213
-    bool has_prefix;
22c213
-
22c213
-    /* This function is used by both protocol block drivers and therefore either
22c213
-     * of these prefixes may be given.
22c213
-     * The return value has to be stored somewhere, otherwise this is an error
22c213
-     * due to -Werror=unused-value. */
22c213
-    has_prefix =
22c213
-        strstart(filename, "host_device:", &filename) ||
22c213
-        strstart(filename, "host_cdrom:" , &filename);
22c213
-
22c213
-    (void)has_prefix;
22c213
-
22c213
-    ret = raw_normalize_devicepath(&filename, errp);
22c213
-    if (ret < 0) {
22c213
-        return ret;
22c213
-    }
22c213
-
22c213
-    /* Read out options */
22c213
-    total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
22c213
-                          BDRV_SECTOR_SIZE);
22c213
-
22c213
-    fd = qemu_open(filename, O_WRONLY | O_BINARY);
22c213
-    if (fd < 0) {
22c213
-        ret = -errno;
22c213
-        error_setg_errno(errp, -ret, "Could not open device");
22c213
-        return ret;
22c213
-    }
22c213
-
22c213
-    if (fstat(fd, &stat_buf) < 0) {
22c213
-        ret = -errno;
22c213
-        error_setg_errno(errp, -ret, "Could not stat device");
22c213
-    } else if (!S_ISBLK(stat_buf.st_mode) && !S_ISCHR(stat_buf.st_mode)) {
22c213
-        error_setg(errp,
22c213
-                   "The given file is neither a block nor a character device");
22c213
-        ret = -ENODEV;
22c213
-    } else if (lseek(fd, 0, SEEK_END) < total_size) {
22c213
-        error_setg(errp, "Device is too small");
22c213
-        ret = -ENOSPC;
22c213
-    }
22c213
-
22c213
-    if (!ret && total_size) {
22c213
-        uint8_t buf[BDRV_SECTOR_SIZE] = { 0 };
22c213
-        int64_t zero_size = MIN(BDRV_SECTOR_SIZE, total_size);
22c213
-        if (lseek(fd, 0, SEEK_SET) == -1) {
22c213
-            ret = -errno;
22c213
-        } else {
22c213
-            ret = qemu_write_full(fd, buf, zero_size);
22c213
-            ret = ret == zero_size ? 0 : -errno;
22c213
-        }
22c213
-    }
22c213
-    qemu_close(fd);
22c213
-    return ret;
22c213
-}
22c213
-
22c213
 static BlockDriver bdrv_host_device = {
22c213
     .format_name        = "host_device",
22c213
     .protocol_name        = "host_device",
22c213
@@ -3491,8 +3430,6 @@ static BlockDriver bdrv_host_device = {
22c213
     .bdrv_reopen_prepare = raw_reopen_prepare,
22c213
     .bdrv_reopen_commit  = raw_reopen_commit,
22c213
     .bdrv_reopen_abort   = raw_reopen_abort,
22c213
-    .bdrv_co_create_opts = hdev_co_create_opts,
22c213
-    .create_opts         = &raw_create_opts,
22c213
     .mutable_opts        = mutable_opts,
22c213
     .bdrv_co_invalidate_cache = raw_co_invalidate_cache,
22c213
     .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes,
22c213
@@ -3619,8 +3556,6 @@ static BlockDriver bdrv_host_cdrom = {
22c213
     .bdrv_reopen_prepare = raw_reopen_prepare,
22c213
     .bdrv_reopen_commit  = raw_reopen_commit,
22c213
     .bdrv_reopen_abort   = raw_reopen_abort,
22c213
-    .bdrv_co_create_opts = hdev_co_create_opts,
22c213
-    .create_opts         = &raw_create_opts,
22c213
     .mutable_opts        = mutable_opts,
22c213
     .bdrv_co_invalidate_cache = raw_co_invalidate_cache,
22c213
 
22c213
@@ -3753,8 +3688,6 @@ static BlockDriver bdrv_host_cdrom = {
22c213
     .bdrv_reopen_prepare = raw_reopen_prepare,
22c213
     .bdrv_reopen_commit  = raw_reopen_commit,
22c213
     .bdrv_reopen_abort   = raw_reopen_abort,
22c213
-    .bdrv_co_create_opts = hdev_co_create_opts,
22c213
-    .create_opts        = &raw_create_opts,
22c213
     .mutable_opts       = mutable_opts,
22c213
 
22c213
     .bdrv_co_preadv         = raw_co_preadv,
22c213
-- 
22c213
1.8.3.1
22c213