[PATCH kvmtool 1/3] Remove initrd magic check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Linux, besides CPIO, supports 7 different compressed formats for the initrd
(gzip, bzip2, LZMA, XZ, LZO, LZ4, ZSTD), but kvmtool only recognizes one of
them.

Remove the initrd magic check because:

1. It doesn't bring much to the end user, as the Linux kernel still
   complains if the initrd is in an unknown format.

2. --kernel can be used to load something that is not a Linux kernel (like
   a kvm-unit-tests test), in which case a format which is not supported by
   a Linux kernel can still be perfectly valid. For example, kvm-unit-tests
   load the test environment as an initrd in plain ASCII format.

3. It cuts down on the maintenance effort when new formats are added to
   the Linux kernel. Not a big deal, since that doesn't happen very often,
   but it's still an effort with very little gain (see point #1 above).

Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx>
---
 kvm.c | 22 ----------------------
 1 file changed, 22 deletions(-)

diff --git a/kvm.c b/kvm.c
index 5bc66c8be82a..952ef1fbb41c 100644
--- a/kvm.c
+++ b/kvm.c
@@ -512,25 +512,6 @@ err:
 }
 core_init(kvm__init);
 
-/* RFC 1952 */
-#define GZIP_ID1		0x1f
-#define GZIP_ID2		0x8b
-#define CPIO_MAGIC		"0707"
-/* initrd may be gzipped, or a plain cpio */
-static bool initrd_check(int fd)
-{
-	unsigned char id[4];
-
-	if (read_in_full(fd, id, ARRAY_SIZE(id)) < 0)
-		return false;
-
-	if (lseek(fd, 0, SEEK_SET) < 0)
-		die_perror("lseek");
-
-	return (id[0] == GZIP_ID1 && id[1] == GZIP_ID2) ||
-		!memcmp(id, CPIO_MAGIC, 4);
-}
-
 bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
 		const char *initrd_filename, const char *kernel_cmdline)
 {
@@ -545,9 +526,6 @@ bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
 		fd_initrd = open(initrd_filename, O_RDONLY);
 		if (fd_initrd < 0)
 			die("Unable to open initrd %s", initrd_filename);
-
-		if (!initrd_check(fd_initrd))
-			die("%s is not an initrd", initrd_filename);
 	}
 
 	ret = kvm__arch_load_kernel_image(kvm, fd_kernel, fd_initrd,
-- 
2.31.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux