]> git.proxmox.com Git - pve-qemu.git/blame - debian/patches/pve/0040-PVE-fall-back-to-open-iscsi-initiatorname.patch
update submodule and patches to 6.1.1
[pve-qemu.git] / debian / patches / pve / 0040-PVE-fall-back-to-open-iscsi-initiatorname.patch
CommitLineData
a16eaaff
FE
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Fabian Ebner <f.ebner@proxmox.com>
3Date: Tue, 17 Nov 2020 10:51:05 +0100
4Subject: [PATCH] PVE: fall back to open-iscsi initiatorname
5
6When no explicit option is given, try reading the initiator name from
7/etc/iscsi/initiatorname.iscsi and only use the generic fallback, i.e.
8iqn.2008-11.org.linux-kvmXXX, as a third alternative.
9
10This avoids the need to add an explicit option for vma and to explicitly set it
11for each call to qemu that deals with iSCSI disks, while still allowing to set
12the option if a different name is needed.
13
14According to RFC 3720, an initiator name is at most 223 bytes long, so the
154 KiB buffer is big enough, even if many whitespaces are used.
16
17Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
ddbf7a87 18Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
a16eaaff
FE
19---
20 block/iscsi.c | 30 ++++++++++++++++++++++++++++++
21 1 file changed, 30 insertions(+)
22
23diff --git a/block/iscsi.c b/block/iscsi.c
8dca018b 24index 4d2a416ce7..c345d30812 100644
a16eaaff
FE
25--- a/block/iscsi.c
26+++ b/block/iscsi.c
8dca018b 27@@ -1372,12 +1372,42 @@ static char *get_initiator_name(QemuOpts *opts)
a16eaaff
FE
28 const char *name;
29 char *iscsi_name;
30 UuidInfo *uuid_info;
31+ FILE *name_fh;
32
33 name = qemu_opt_get(opts, "initiator-name");
34 if (name) {
35 return g_strdup(name);
36 }
37
38+ name_fh = fopen("/etc/iscsi/initiatorname.iscsi", "r");
39+ if (name_fh) {
40+ const char *key = "InitiatorName";
41+ char buffer[4096];
42+ char *line;
43+
44+ while ((line = fgets(buffer, sizeof(buffer), name_fh))) {
45+ line = g_strstrip(line);
46+ if (!strncmp(line, key, strlen(key))) {
47+ line = strchr(line, '=');
48+ if (!line || strlen(line) == 1) {
49+ continue;
50+ }
51+ line++;
52+ g_strstrip(line);
53+ if (!strlen(line)) {
54+ continue;
55+ }
56+ name = line;
57+ break;
58+ }
59+ }
60+ fclose(name_fh);
61+
62+ if (name) {
63+ return g_strdup(name);
64+ }
65+ }
66+
67 uuid_info = qmp_query_uuid(NULL);
68 if (strcmp(uuid_info->UUID, UUID_NONE) == 0) {
69 name = qemu_get_vm_name();