Pārlūkot izejas kodu

[vmware] Add VMware logfile console (CONSOLE_VMWARE)

Allow iPXE console output to be sent to the VMware logfile via the
GuestRPC mechanism.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 gadus atpakaļ
vecāks
revīzija
fa538bdbc6
3 mainītis faili ar 121 papildinājumiem un 0 dzēšanām
  1. 117
    0
      src/arch/i386/interface/vmware/vmconsole.c
  2. 3
    0
      src/config/config.c
  3. 1
    0
      src/config/console.h

+ 117
- 0
src/arch/i386/interface/vmware/vmconsole.c Parādīt failu

@@ -0,0 +1,117 @@
1
+/*
2
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+/** @file
22
+ *
23
+ * VMware logfile console
24
+ *
25
+ */
26
+
27
+#include <string.h>
28
+#include <ipxe/console.h>
29
+#include <ipxe/lineconsole.h>
30
+#include <ipxe/init.h>
31
+#include <ipxe/guestrpc.h>
32
+
33
+/** VMware logfile console buffer size */
34
+#define VMCONSOLE_BUFSIZE 128
35
+
36
+/** VMware logfile console GuestRPC channel */
37
+static int vmconsole_channel;
38
+
39
+/** VMware logfile console line buffer */
40
+static struct {
41
+	char prefix[4];
42
+	char message[VMCONSOLE_BUFSIZE];
43
+} vmconsole_buffer = {
44
+	.prefix = "log ",
45
+};
46
+
47
+/** VMware logfile line console */
48
+static struct line_console vmconsole_line = {
49
+	.buffer = vmconsole_buffer.message,
50
+	.len = sizeof ( vmconsole_buffer.message ),
51
+};
52
+
53
+/** VMware logfile console recursion marker */
54
+static int vmconsole_entered;
55
+
56
+/**
57
+ * Print a character to VMware logfile console
58
+ *
59
+ * @v character		Character to be printed
60
+ */
61
+static void vmconsole_putchar ( int character ) {
62
+	int rc;
63
+
64
+	/* Ignore if we are already mid-logging */
65
+	if ( vmconsole_entered )
66
+		return;
67
+
68
+	/* Fill line buffer */
69
+	if ( line_putchar ( &vmconsole_line, character ) == 0 )
70
+		return;
71
+
72
+	/* Guard against re-entry */
73
+	vmconsole_entered = 1;
74
+
75
+	/* Send log message */
76
+	if ( ( rc = guestrpc_command ( vmconsole_channel,
77
+				       vmconsole_buffer.prefix, NULL, 0 ) ) <0){
78
+		DBG ( "VMware console could not send log message: %s\n",
79
+		      strerror ( rc ) );
80
+	}
81
+
82
+	/* Clear re-entry flag */
83
+	vmconsole_entered = 0;
84
+}
85
+
86
+/** VMware logfile console driver */
87
+struct console_driver vmconsole __console_driver = {
88
+	.putchar = vmconsole_putchar,
89
+	.disabled = 1,
90
+};
91
+
92
+/**
93
+ * Initialise VMware logfile console
94
+ *
95
+ */
96
+static void vmconsole_init ( void ) {
97
+	int rc;
98
+
99
+	/* Attempt to open console */
100
+	vmconsole_channel = guestrpc_open();
101
+	if ( vmconsole_channel < 0 ) {
102
+		rc = vmconsole_channel;
103
+		DBG ( "VMware console could not be initialised: %s\n",
104
+		      strerror ( rc ) );
105
+		return;
106
+	}
107
+
108
+	/* Mark console as available */
109
+	vmconsole.disabled = 0;
110
+}
111
+
112
+/**
113
+ * VMware logfile console initialisation function
114
+ */
115
+struct init_fn vmconsole_init_fn __init_fn ( INIT_CONSOLE ) = {
116
+	.initialise = vmconsole_init,
117
+};

+ 3
- 0
src/config/config.c Parādīt failu

@@ -86,6 +86,9 @@ REQUIRE_OBJECT ( efi_console );
86 86
 #ifdef CONSOLE_LINUX
87 87
 REQUIRE_OBJECT ( linux_console );
88 88
 #endif
89
+#ifdef CONSOLE_VMWARE
90
+REQUIRE_OBJECT ( vmconsole );
91
+#endif
89 92
 
90 93
 /*
91 94
  * Drag in all requested network protocols

+ 1
- 0
src/config/console.h Parādīt failu

@@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
20 20
 //#define	CONSOLE_BTEXT		/* Who knows what this does? */
21 21
 //#define	CONSOLE_PC_KBD		/* Direct access to PC keyboard */
22 22
 //#define	CONSOLE_SYSLOG		/* Syslog console */
23
+//#define	CONSOLE_VMWARE		/* VMware logfile console */
23 24
 
24 25
 #define	KEYBOARD_MAP	us
25 26
 

Notiek ielāde…
Atcelt
Saglabāt