]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0042-PVE-fall-back-to-open-iscsi-initiatorname.patch
PVE backup: don't call no_co_wrapper function from coroutine
[pve-qemu.git] / debian / patches / pve / 0042-PVE-fall-back-to-open-iscsi-initiatorname.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Fabian Ebner <f.ebner@proxmox.com>
3 Date: Tue, 17 Nov 2020 10:51:05 +0100
4 Subject: [PATCH] PVE: fall back to open-iscsi initiatorname
5
6 When no explicit option is given, try reading the initiator name from
7 /etc/iscsi/initiatorname.iscsi and only use the generic fallback, i.e.
8 iqn.2008-11.org.linux-kvmXXX, as a third alternative.
9
10 This avoids the need to add an explicit option for vma and to explicitly set it
11 for each call to qemu that deals with iSCSI disks, while still allowing to set
12 the option if a different name is needed.
13
14 According to RFC 3720, an initiator name is at most 223 bytes long, so the
15 4 KiB buffer is big enough, even if many whitespaces are used.
16
17 Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
18 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
19 ---
20 block/iscsi.c | 30 ++++++++++++++++++++++++++++++
21 1 file changed, 30 insertions(+)
22
23 diff --git a/block/iscsi.c b/block/iscsi.c
24 index 9fc0bed90b..1d40933165 100644
25 --- a/block/iscsi.c
26 +++ b/block/iscsi.c
27 @@ -1392,12 +1392,42 @@ static char *get_initiator_name(QemuOpts *opts)
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();