thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 339b5cbcea1d459d2a0fc4d289e17fc71622be23 Mon Sep 17 00:00:00 2001
9ae3a8
From: Jeffrey Cody <jcody@redhat.com>
9ae3a8
Date: Tue, 4 Mar 2014 19:38:27 +0100
9ae3a8
Subject: [PATCH 6/6] block: Set block filename sizes to PATH_MAX instead of 1024
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Jeffrey Cody <jcody@redhat.com>
9ae3a8
Message-id: <cd1c834d5d15020c9521e95aa24d7db675dc12e2.1393961758.git.jcody@redhat.com>
9ae3a8
Patchwork-id: 58013
9ae3a8
O-Subject: [RHEL7 qemu-kvm PATCH] block: Set block filename sizes to PATH_MAX instead of 1024
9ae3a8
Bugzilla: 1072339
9ae3a8
RH-Acked-by: Eric Blake <eblake@redhat.com>
9ae3a8
RH-Acked-by: Amos Kong <akong@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
This is an interim fix for a regression introduced by:
9ae3a8
9ae3a8
    commit dc5a137125d6ac641c566f10e68bf6e1fe31bcb5
9ae3a8
    qemu-img: make "info" backing file output correct and easier to use
9ae3a8
9ae3a8
In that commit, bdrv_get_full_backing_filename() was introduced,
9ae3a8
which replaced calling path_combine() manually.  The difference
9ae3a8
is that rather than using the filename string as passed to
9ae3a8
bdrv_open(), it uses the filename string attached to the BDS.
9ae3a8
9ae3a8
Both the backing_file and filename strings in the BDS are limited to
9ae3a8
1024 characters.  The backing_file string built up in bdrv_open(),
9ae3a8
however, has a limit of PATH_MAX, which is 4096 under Linux.
9ae3a8
9ae3a8
This difference comes into play when using an image chain that has
9ae3a8
a medium-to-large number of images, all of which have relative-pathed
9ae3a8
backing file references to the parent directory.
9ae3a8
9ae3a8
For instance, consider the following backing chain:
9ae3a8
9ae3a8
tstA
9ae3a8
├── base.qcow2
9ae3a8
├── sn1.qcow2   (backing file ../tstA/base.qcow2)
9ae3a8
├── sn2.qcow2   (backing file ../tstA/sn1.qcow2)
9ae3a8
└── sn3.qcow2   (backing file ../tstA/sn2.qcow2)
9ae3a8
9ae3a8
The backing filename string is built up with the relative paths intact,
9ae3a8
like so:
9ae3a8
9ae3a8
    base.qcow2:  ../tstA../tstA../tstA/base.qcow2
9ae3a8
9ae3a8
The backing filename is then passed into the bdrv_open() call to open
9ae3a8
the backing file.
9ae3a8
9ae3a8
When using lv volume names, the snapshot and pathname ends up longer,
9ae3a8
and after ~23 snapshots we have hit or exceeded the 1024 byte limit
9ae3a8
for the BDS filename.
9ae3a8
9ae3a8
This fix is different then the approach for RHEL6.6/6.5.z, because in
9ae3a8
those it was trivial to modify bdrv_get_full_backing_filename().  In
9ae3a8
RHEL7, there are places that use bdrv_get_backing_filename(), which
9ae3a8
call bdrv_get_full_backing_filename(), yet do not have access to a
9ae3a8
filename string that does not originate from the BDS.  The simplest
9ae3a8
approach, that should yield identical results, is to set all of the
9ae3a8
filename and backing_file string sizes to PATH_MAX instead of 1024.
9ae3a8
9ae3a8
This is not a long-term solution, because a character limit of 4096
9ae3a8
bytes will be hit with additional images.  The proper long-term
9ae3a8
solution should happen upstream first, and consist of:
9ae3a8
9ae3a8
1) dynamically allocated filename strings in the BDS
9ae3a8
2) flattening redundant relative pathname strings
9ae3a8
9ae3a8
This is a bug that was reported in RHEL6, that also occurs in RHEL7.  To
9ae3a8
prevent a regression in RHEL7.0, this temporary solution will prevent
9ae3a8
the regression, while not eliminating the ultimate problem.
9ae3a8
9ae3a8
Since this is not the final solution, and the fix really is relevant
9ae3a8
just to undo a regression, the fix is downstream only.  It will be
9ae3a8
replaced by the final upstream fix, once complete.
9ae3a8
9ae3a8
BZ 1072339
9ae3a8
RHEL Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7140291
9ae3a8
RHEV Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7140320
9ae3a8
---
9ae3a8
 block/mirror.c            | 2 +-
9ae3a8
 block/qapi.c              | 2 +-
9ae3a8
 block/stream.c            | 2 +-
9ae3a8
 include/block/block_int.h | 6 +++---
9ae3a8
 4 files changed, 6 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/mirror.c            |    2 +-
9ae3a8
 block/qapi.c              |    2 +-
9ae3a8
 block/stream.c            |    2 +-
9ae3a8
 include/block/block_int.h |    6 +++---
9ae3a8
 4 files changed, 6 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/mirror.c b/block/mirror.c
9ae3a8
index ba1428b..47e14cd 100644
9ae3a8
--- a/block/mirror.c
9ae3a8
+++ b/block/mirror.c
9ae3a8
@@ -297,7 +297,7 @@ static void coroutine_fn mirror_run(void *opaque)
9ae3a8
     int64_t sector_num, end, sectors_per_chunk, length;
9ae3a8
     uint64_t last_pause_ns;
9ae3a8
     BlockDriverInfo bdi;
9ae3a8
-    char backing_filename[1024];
9ae3a8
+    char backing_filename[PATH_MAX];
9ae3a8
     int ret = 0;
9ae3a8
     int n;
9ae3a8
 
9ae3a8
diff --git a/block/qapi.c b/block/qapi.c
9ae3a8
index 77e1719..2d4bdcd 100644
9ae3a8
--- a/block/qapi.c
9ae3a8
+++ b/block/qapi.c
9ae3a8
@@ -112,7 +112,7 @@ void bdrv_query_image_info(BlockDriverState *bs,
9ae3a8
 {
9ae3a8
     uint64_t total_sectors;
9ae3a8
     const char *backing_filename;
9ae3a8
-    char backing_filename2[1024];
9ae3a8
+    char backing_filename2[PATH_MAX];
9ae3a8
     BlockDriverInfo bdi;
9ae3a8
     int ret;
9ae3a8
     Error *err = NULL;
9ae3a8
diff --git a/block/stream.c b/block/stream.c
9ae3a8
index 3a7d8f3..2a6f533 100644
9ae3a8
--- a/block/stream.c
9ae3a8
+++ b/block/stream.c
9ae3a8
@@ -32,7 +32,7 @@ typedef struct StreamBlockJob {
9ae3a8
     RateLimit limit;
9ae3a8
     BlockDriverState *base;
9ae3a8
     BlockdevOnError on_error;
9ae3a8
-    char backing_file_id[1024];
9ae3a8
+    char backing_file_id[PATH_MAX];
9ae3a8
 } StreamBlockJob;
9ae3a8
 
9ae3a8
 static int coroutine_fn stream_populate(BlockDriverState *bs,
9ae3a8
diff --git a/include/block/block_int.h b/include/block/block_int.h
9ae3a8
index 2ec4bb2..53fc98c 100644
9ae3a8
--- a/include/block/block_int.h
9ae3a8
+++ b/include/block/block_int.h
9ae3a8
@@ -269,9 +269,9 @@ struct BlockDriverState {
9ae3a8
     const BlockDevOps *dev_ops;
9ae3a8
     void *dev_opaque;
9ae3a8
 
9ae3a8
-    char filename[1024];
9ae3a8
-    char backing_file[1024]; /* if non zero, the image is a diff of
9ae3a8
-                                this file image */
9ae3a8
+    char filename[PATH_MAX];
9ae3a8
+    char backing_file[PATH_MAX]; /* if non zero, the image is a diff of
9ae3a8
+                                    this file image */
9ae3a8
     char backing_format[16]; /* if non-zero and backing_file exists */
9ae3a8
     int is_temporary;
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8