cryptospore / rpms / qemu-kvm

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