All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: will@kernel.org, julien.thierry.kdev@gmail.com, kvm@vger.kernel.org
Cc: christoffer.dall@arm.com, vivek.gautam@arm.com
Subject: [PATCH kvmtool 05/10] Use kvm->nr_disks instead of kvm->cfg.image_count
Date: Thu, 23 Sep 2021 15:45:00 +0100	[thread overview]
Message-ID: <20210923144505.60776-6-alexandru.elisei@arm.com> (raw)
In-Reply-To: <20210923144505.60776-1-alexandru.elisei@arm.com>

A user can specify multiple disk images using the --disk/-d argument. The
callback for the argument ends up in
disk/core.c::calling disk_img_name_parser(), which increments
kvm->cfg.image_count for each disk image.

Immediately after parsing the arguments in kvm_cmd_run_init(),
kvm->nr_disks is set to kvm->cfg.image_count, effectively making
kvm->nr_disks an alias for kvm->cfg.image_count, as image_count is never
changed afterward.

Later on, the core disk code uses kvm->cfg.image_count when opening all the
disk images, but kvm->nr_disks when closing them, which is inconsistent,
but technically correct since they represent the same thing and have the
same value.

Let's remove all this confusing usage and use only kvm->nr_disks to
represent the number of disk images specified by the user.

While this technically means that kvmtool now supports up to INT_MAX disk
images, in practice this is limited by MAX_DISK_IMAGES, which is equal to
four. Which means there are no functional changes.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 builtin-run.c            |  2 --
 disk/core.c              | 18 +++++++++---------
 include/kvm/kvm-config.h |  1 -
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/builtin-run.c b/builtin-run.c
index 2a14723ba042..6822c321883e 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -526,8 +526,6 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
 
 	kvm_run_validate_cfg(kvm);
 
-	kvm->nr_disks = kvm->cfg.image_count;
-
 	if (!kvm->cfg.kernel_filename && !kvm->cfg.firmware_filename) {
 		kvm->cfg.kernel_filename = find_kernel();
 
diff --git a/disk/core.c b/disk/core.c
index 8d95c98e2169..d8d04cb0a24e 100644
--- a/disk/core.c
+++ b/disk/core.c
@@ -16,20 +16,20 @@ int disk_img_name_parser(const struct option *opt, const char *arg, int unset)
 	char *sep;
 	struct kvm *kvm = opt->ptr;
 
-	if (kvm->cfg.image_count >= MAX_DISK_IMAGES)
+	if (kvm->nr_disks >= MAX_DISK_IMAGES)
 		die("Currently only 4 images are supported");
 
-	kvm->cfg.disk_image[kvm->cfg.image_count].filename = arg;
+	kvm->cfg.disk_image[kvm->nr_disks].filename = arg;
 	cur = arg;
 
 	if (strncmp(arg, "scsi:", 5) == 0) {
 		sep = strstr(arg, ":");
 		if (sep)
-			kvm->cfg.disk_image[kvm->cfg.image_count].wwpn = sep + 1;
+			kvm->cfg.disk_image[kvm->nr_disks].wwpn = sep + 1;
 		sep = strstr(sep + 1, ":");
 		if (sep) {
 			*sep = 0;
-			kvm->cfg.disk_image[kvm->cfg.image_count].tpgt = sep + 1;
+			kvm->cfg.disk_image[kvm->nr_disks].tpgt = sep + 1;
 		}
 		cur = sep + 1;
 	}
@@ -38,15 +38,15 @@ int disk_img_name_parser(const struct option *opt, const char *arg, int unset)
 		sep = strstr(cur, ",");
 		if (sep) {
 			if (strncmp(sep + 1, "ro", 2) == 0)
-				kvm->cfg.disk_image[kvm->cfg.image_count].readonly = true;
+				kvm->cfg.disk_image[kvm->nr_disks].readonly = true;
 			else if (strncmp(sep + 1, "direct", 6) == 0)
-				kvm->cfg.disk_image[kvm->cfg.image_count].direct = true;
+				kvm->cfg.disk_image[kvm->nr_disks].direct = true;
 			*sep = 0;
 			cur = sep + 1;
 		}
 	} while (sep);
 
-	kvm->cfg.image_count++;
+	kvm->nr_disks++;
 
 	return 0;
 }
@@ -152,7 +152,7 @@ static struct disk_image **disk_image__open_all(struct kvm *kvm)
 	void *err;
 	int i;
 	struct disk_image_params *params = (struct disk_image_params *)&kvm->cfg.disk_image;
-	int count = kvm->cfg.image_count;
+	int count = kvm->nr_disks;
 
 	if (!count)
 		return ERR_PTR(-EINVAL);
@@ -328,7 +328,7 @@ void disk_image__set_callback(struct disk_image *disk,
 
 int disk_image__init(struct kvm *kvm)
 {
-	if (kvm->cfg.image_count) {
+	if (kvm->nr_disks) {
 		kvm->disks = disk_image__open_all(kvm);
 		if (IS_ERR(kvm->disks))
 			return PTR_ERR(kvm->disks);
diff --git a/include/kvm/kvm-config.h b/include/kvm/kvm-config.h
index 8b6c151191f6..35d45c0f7ab1 100644
--- a/include/kvm/kvm-config.h
+++ b/include/kvm/kvm-config.h
@@ -23,7 +23,6 @@ struct kvm_config {
 	struct disk_image_params disk_image[MAX_DISK_IMAGES];
 	struct vfio_device_params *vfio_devices;
 	u64 ram_size;
-	u8  image_count;
 	u8 num_net_devices;
 	u8 num_vfio_devices;
 	u64 vsock_cid;
-- 
2.31.1


  parent reply	other threads:[~2021-09-23 14:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 14:44 [PATCH kvmtool 00/10] Run kvm-unit-tests with --kernel Alexandru Elisei
2021-09-23 14:44 ` [PATCH kvmtool 01/10] builtin-run: Treat specifying both --kernel and --firmware as an error Alexandru Elisei
2021-09-23 14:44 ` [PATCH kvmtool 02/10] builtin-run: Warn when ignoring initrd because --firmware was specified Alexandru Elisei
2021-09-23 14:44 ` [PATCH kvmtool 03/10] builtin-run: Do not attempt to find vmlinux if --firmware Alexandru Elisei
2021-09-23 14:44 ` [PATCH kvmtool 04/10] builtin-run: Abstract argument validation into a separate function Alexandru Elisei
2021-09-23 14:45 ` Alexandru Elisei [this message]
2021-09-23 14:45 ` [PATCH kvmtool 06/10] builtin-run: Move kernel command line generation to " Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 07/10] Add --nodefaults command line argument Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 08/10] Add --nocompat option to disable compat warnings Alexandru Elisei
2021-10-12  8:34   ` Will Deacon
2021-10-12 14:24     ` Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 09/10] arm64: Use the default offset when the kernel image magic is not found Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 10/10] arm64: Be more permissive when parsing the kernel header Alexandru Elisei
2021-10-12  8:46 ` [PATCH kvmtool 00/10] Run kvm-unit-tests with --kernel Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210923144505.60776-6-alexandru.elisei@arm.com \
    --to=alexandru.elisei@arm.com \
    --cc=christoffer.dall@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=vivek.gautam@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.