xref: /qemu/tests/qemu-iotests/126 (revision 1278dce7927301bf3d004a40061dbd2c1e0846a8)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
26f55dfa4SMax Reitz#
36f55dfa4SMax Reitz# Tests handling of colons in filenames (which may be confused with protocol
46f55dfa4SMax Reitz# prefixes)
56f55dfa4SMax Reitz#
66f55dfa4SMax Reitz# Copyright (C) 2017 Red Hat, Inc.
76f55dfa4SMax Reitz#
86f55dfa4SMax Reitz# This program is free software; you can redistribute it and/or modify
96f55dfa4SMax Reitz# it under the terms of the GNU General Public License as published by
106f55dfa4SMax Reitz# the Free Software Foundation; either version 2 of the License, or
116f55dfa4SMax Reitz# (at your option) any later version.
126f55dfa4SMax Reitz#
136f55dfa4SMax Reitz# This program is distributed in the hope that it will be useful,
146f55dfa4SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
156f55dfa4SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
166f55dfa4SMax Reitz# GNU General Public License for more details.
176f55dfa4SMax Reitz#
186f55dfa4SMax Reitz# You should have received a copy of the GNU General Public License
196f55dfa4SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
206f55dfa4SMax Reitz#
216f55dfa4SMax Reitz
226f55dfa4SMax Reitz# creator
236f55dfa4SMax Reitzowner=mreitz@redhat.com
246f55dfa4SMax Reitz
256f55dfa4SMax Reitzseq="$(basename $0)"
266f55dfa4SMax Reitzecho "QA output created by $seq"
276f55dfa4SMax Reitz
286f55dfa4SMax Reitzstatus=1	# failure is the default!
296f55dfa4SMax Reitz
306f55dfa4SMax Reitz# get standard environment, filters and checks
316f55dfa4SMax Reitz. ./common.rc
326f55dfa4SMax Reitz. ./common.filter
336f55dfa4SMax Reitz
346f55dfa4SMax Reitz# Needs backing file support
356f55dfa4SMax Reitz_supported_fmt qcow qcow2 qed vmdk
366f55dfa4SMax Reitz# This is the default protocol (and we want to test the difference between
376f55dfa4SMax Reitz# colons which separate a protocol prefix from the rest and colons which are
386f55dfa4SMax Reitz# just part of the filename, so we cannot test protocols which require a prefix)
396f55dfa4SMax Reitz_supported_proto file
406f55dfa4SMax Reitz_supported_os Linux
416f55dfa4SMax Reitz
426f55dfa4SMax Reitzecho
436f55dfa4SMax Reitzecho '=== Testing plain files ==='
446f55dfa4SMax Reitzecho
456f55dfa4SMax Reitz
466f55dfa4SMax Reitz# A colon after a slash is not a protocol prefix separator
476f55dfa4SMax ReitzTEST_IMG="$TEST_DIR/a:b.$IMGFMT" _make_test_img 64M
486f55dfa4SMax Reitz_rm_test_img "$TEST_DIR/a:b.$IMGFMT"
496f55dfa4SMax Reitz
506f55dfa4SMax Reitz# But if you want to be really sure, you can do this
516f55dfa4SMax ReitzTEST_IMG="file:$TEST_DIR/a:b.$IMGFMT" _make_test_img 64M
526f55dfa4SMax Reitz_rm_test_img "$TEST_DIR/a:b.$IMGFMT"
536f55dfa4SMax Reitz
546f55dfa4SMax Reitz
556f55dfa4SMax Reitzecho
566f55dfa4SMax Reitzecho '=== Testing relative backing filename resolution ==='
576f55dfa4SMax Reitzecho
586f55dfa4SMax Reitz
596f55dfa4SMax ReitzBASE_IMG="$TEST_DIR/image:base.$IMGFMT"
606f55dfa4SMax ReitzTOP_IMG="$TEST_DIR/image:top.$IMGFMT"
616f55dfa4SMax Reitz
626f55dfa4SMax ReitzTEST_IMG=$BASE_IMG _make_test_img 64M
636f55dfa4SMax ReitzTEST_IMG=$TOP_IMG _make_test_img -b ./image:base.$IMGFMT
646f55dfa4SMax Reitz
65*1278dce7SMax Reitz# (1) The default cluster size depends on the image format
66*1278dce7SMax Reitz# (2) vmdk only supports vmdk backing files, so it always reports the
67*1278dce7SMax Reitz#     format of its backing file as such (but neither it nor qcow
68*1278dce7SMax Reitz#     support the backing_fmt creation option, so we cannot use that to
69*1278dce7SMax Reitz#     harmonize the output across all image formats this test supports)
70*1278dce7SMax ReitzTEST_IMG=$TOP_IMG _img_info | grep -ve 'cluster_size' -e 'backing file format'
716f55dfa4SMax Reitz
726f55dfa4SMax Reitz_rm_test_img "$BASE_IMG"
736f55dfa4SMax Reitz_rm_test_img "$TOP_IMG"
746f55dfa4SMax Reitz
756f55dfa4SMax Reitz
766f55dfa4SMax Reitz# Do another test where we access both top and base without any slash in them
776f55dfa4SMax Reitzecho
786f55dfa4SMax Reitzpushd "$TEST_DIR" >/dev/null
796f55dfa4SMax Reitz
806f55dfa4SMax ReitzBASE_IMG="base.$IMGFMT"
816f55dfa4SMax ReitzTOP_IMG="file:image:top.$IMGFMT"
826f55dfa4SMax Reitz
836f55dfa4SMax ReitzTEST_IMG=$BASE_IMG _make_test_img 64M
846f55dfa4SMax ReitzTEST_IMG=$TOP_IMG _make_test_img -b "$BASE_IMG"
856f55dfa4SMax Reitz
86*1278dce7SMax ReitzTEST_IMG=$TOP_IMG _img_info | grep -ve 'cluster_size' -e 'backing file format'
876f55dfa4SMax Reitz
886f55dfa4SMax Reitz_rm_test_img "$BASE_IMG"
896f55dfa4SMax Reitz_rm_test_img "image:top.$IMGFMT"
906f55dfa4SMax Reitz
916f55dfa4SMax Reitzpopd >/dev/null
926f55dfa4SMax Reitz
936f55dfa4SMax Reitz# Note that we could also do the same test with BASE_IMG=file:image:base.$IMGFMT
946f55dfa4SMax Reitz# -- but behavior for that case is a bit strange. Protocol-prefixed paths are
956f55dfa4SMax Reitz# in a sense always absolute paths, so such paths will never be combined with
966f55dfa4SMax Reitz# the path of the overlay. But since "image:base.$IMGFMT" is actually a
976f55dfa4SMax Reitz# relative path, it will always be evaluated relative to qemu's CWD (but not
986f55dfa4SMax Reitz# relative to the overlay!). While this is more or less intended, it is still
996f55dfa4SMax Reitz# pretty strange and thus not something that is tested here.
1006f55dfa4SMax Reitz# (The root of the issue is the use of a relative path with a protocol prefix.
1016f55dfa4SMax Reitz#  This may always give you weird results because in one sense, qemu considers
1026f55dfa4SMax Reitz#  such paths absolute, whereas in another, they are still relative.)
1036f55dfa4SMax Reitz
1046f55dfa4SMax Reitz
1056f55dfa4SMax Reitz# success, all done
1066f55dfa4SMax Reitzecho '*** done'
1076f55dfa4SMax Reitzrm -f $seq.full
1086f55dfa4SMax Reitzstatus=0
109