]> git.proxmox.com Git - pve-qemu.git/blame - debian/patches/pve/0057-PVE-fall-back-to-open-iscsi-initiatorname.patch
bump version to 5.2.0-2
[pve-qemu.git] / debian / patches / pve / 0057-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>
18---
19 block/iscsi.c | 30 ++++++++++++++++++++++++++++++
20 1 file changed, 30 insertions(+)
21
22diff --git a/block/iscsi.c b/block/iscsi.c
817b7667 23index e30a7e3606..6c70bbe351 100644
a16eaaff
FE
24--- a/block/iscsi.c
25+++ b/block/iscsi.c
26@@ -1374,12 +1374,42 @@ static char *get_initiator_name(QemuOpts *opts)
27 const char *name;
28 char *iscsi_name;
29 UuidInfo *uuid_info;
30+ FILE *name_fh;
31
32 name = qemu_opt_get(opts, "initiator-name");
33 if (name) {
34 return g_strdup(name);
35 }
36
37+ name_fh = fopen("/etc/iscsi/initiatorname.iscsi", "r");
38+ if (name_fh) {
39+ const char *key = "InitiatorName";
40+ char buffer[4096];
41+ char *line;
42+
43+ while ((line = fgets(buffer, sizeof(buffer), name_fh))) {
44+ line = g_strstrip(line);
45+ if (!strncmp(line, key, strlen(key))) {
46+ line = strchr(line, '=');
47+ if (!line || strlen(line) == 1) {
48+ continue;
49+ }
50+ line++;
51+ g_strstrip(line);
52+ if (!strlen(line)) {
53+ continue;
54+ }
55+ name = line;
56+ break;
57+ }
58+ }
59+ fclose(name_fh);
60+
61+ if (name) {
62+ return g_strdup(name);
63+ }
64+ }
65+
66 uuid_info = qmp_query_uuid(NULL);
67 if (strcmp(uuid_info->UUID, UUID_NONE) == 0) {
68 name = qemu_get_vm_name();