2 * (C) Copyright 2007-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
8 static char *__guest_state_to_str(enum virt_cpustate st
)
11 case GUEST_STOPPED
: return "STOPPED";
12 case GUEST_OPERATING
: return "RUNNING";
13 case GUEST_LOAD
: return "LOADING";
14 case GUEST_CHECKSTOP
: return "CHECK-STOP";
20 static void display_rdev(struct device
*dev
, void *priv
)
22 struct virt_cons
*con
= priv
;
27 mutex_lock(&dev
->lock
);
29 if (dev
->dev
&& dev
->dev
->snprintf
)
30 dev
->dev
->snprintf(dev
, buf
, 40);
32 con_printf(con
, "%-4s %04X %04X %s%sSCH = %05X\n",
33 type2name(dev
->type
), dev
->ccuu
, dev
->type
, buf
,
34 dev
->in_use
? "" : "FREE ",
37 mutex_unlock(&dev
->lock
);
40 static void display_vdev(struct virt_cons
*con
, struct virt_device
*vdev
)
42 struct virt_sys
*sys
= container_of(con
, struct virt_sys
, console
);
44 mutex_lock(&vdev
->lock
);
46 switch (vdev
->vtype
) {
48 con_printf(con
, "CONS %04X 3215 ON %s %04X %s SCH = %05X\n",
50 type2name(con
->dev
->type
),
52 sys
->print_ts
? "TS" : "NOTS",
56 con_printf(con
, "%-4s %04X %04X ON DEV %04X SCH = %05X\n",
57 type2name(vdev
->type
),
60 vdev
->u
.dedicate
.rdev
->ccuu
,
64 con_printf(con
, "%-4s %04X %04X SCH = %05X\n",
65 type2name(vdev
->type
),
66 vdev
->pmcw
.dev_num
, vdev
->type
,
70 FIXME("cyl count & rdev");
71 con_printf(con
, "DASD %04X 3390 %6d CYL ON DASD %04X SCH = %05X\n",
73 0, /* FIXME: cyl count */
78 FIXME("userid & vdev #");
79 con_printf(con
, "LINK %04X TO %s %04X SCH = %05X\n",
81 "????", /* FIXME: userid */
82 0xffff, /* FIXME: user's vdev # */
86 con_printf(con
, "???? unknown device type (%04X, %05X)\n",
87 vdev
->pmcw
.dev_num
, vdev
->sch
);
91 mutex_unlock(&vdev
->lock
);
94 static void display_task(struct task
*task
, void *priv
)
96 struct virt_cons
*con
= priv
;
100 case TASK_RUNNING
: state
= 'R'; break;
101 case TASK_SLEEPING
: state
= 'S'; break;
102 case TASK_LOCKED
: state
= 'L'; break;
103 case TASK_ZOMBIE
: state
= 'Z'; break;
104 default: state
= '?'; break;
107 con_printf(con
, "%*s %p %c\n", -TASK_NAME_LEN
, task
->name
,
114 *! \tok{\sc Query} \tok{\sc TIME}
118 *! Displays the current time
120 static int cmd_query_cplevel(struct virt_sys
*sys
, char *cmd
, int len
)
122 SHELL_CMD_AUTH(sys
, G
);
124 con_printf(sys
->con
, "HVF version " VERSION
"\n");
125 con_printf(sys
->con
, "IPL at %02d:%02d:%02d UTC %04d-%02d-%02d\n",
126 ipltime
.th
, ipltime
.tm
, ipltime
.ts
, ipltime
.dy
,
127 ipltime
.dm
, ipltime
.dd
);
135 *! \tok{\sc Query} \tok{\sc CPLEVEL}
139 *! Displays the HVF version and time of IPL
141 static int cmd_query_time(struct virt_sys
*sys
, char *cmd
, int len
)
145 SHELL_CMD_AUTH(sys
, G
);
149 con_printf(sys
->con
, "TIME IS %02d:%02d:%02d UTC %04d-%02d-%02d\n",
150 dt
.th
, dt
.tm
, dt
.ts
, dt
.dy
, dt
.dm
, dt
.dd
);
158 *! \tok{\sc Query} \tok{\sc ARCHMODE}
162 *! Displays the virtual machine's current architecture mode.
164 static int cmd_query_archmode(struct virt_sys
*sys
, char *cmd
, int len
)
168 SHELL_CMD_AUTH(sys
, G
);
170 mode
= (VCPU_ZARCH(sys
->cpu
)) ? "z/Arch" : "ESA390";
172 con_printf(sys
->con
, "ARCHMODE = %s\n", mode
);
180 *! \tok{\sc Query} \tok{\sc Virtual}
184 *! Lists all of the guest's virtual devices
186 static int cmd_query_virtual(struct virt_sys
*sys
, char *cmd
, int len
)
188 struct virt_device
*vdev
;
190 SHELL_CMD_AUTH(sys
, G
);
192 con_printf(sys
->con
, "CPU 00 ID %016lX %s\n",
194 __guest_state_to_str(sys
->cpu
->state
));
195 con_printf(sys
->con
, "STORAGE = %luM\n", sys
->directory
->storage_size
>> 20);
197 for_each_vdev(sys
, vdev
)
198 display_vdev(sys
->con
, vdev
);
203 static void __cmd_query_real_cpus(struct virt_sys
*sys
)
205 con_printf(sys
->con
, "CPU %02d ID %016lX RUNNING\n",
210 static void __cmd_query_real_stor(struct virt_sys
*sys
)
212 con_printf(sys
->con
, "STORAGE = %luM\n", memsize
>> 20);
219 QUERY_DEVNUM
= 1 << 3,
225 *! \tok{\sc Query} \tok{\sc Real}
228 *! \tok{\sc\bf ALL} \\
230 *! \tok{\sc STORage} \\
237 *! Lists the host's real devices, CPUs, and storage
241 *! \item Specifying real device numbers is not supported at the moment.
242 *! Instead, use QUERY REAL ALL to display all devices attached to the
247 static int cmd_query_real(struct virt_sys
*sys
, char *cmd
, int len
)
252 SHELL_CMD_AUTH(sys
, B
);
254 if (strnlen(cmd
, len
) == 0) {
255 what
= QUERY_CPUS
| QUERY_STOR
| QUERY_DEVS
;
256 } else if (!strcasecmp(cmd
, "ALL")) {
257 what
= QUERY_CPUS
| QUERY_STOR
| QUERY_DEVS
;
258 } else if (!strcasecmp(cmd
, "CPUS")) {
260 } else if (!strcasecmp(cmd
, "STOR") ||
261 !strcasecmp(cmd
, "STORA") ||
262 !strcasecmp(cmd
, "STORAG") ||
263 !strcasecmp(cmd
, "STORAGE")) {
266 cmd
= __extract_hex(cmd
, &devnum
);
270 /* sch number must be: X'0000____' */
271 if (devnum
& ~0xffffull
)
277 if (what
& QUERY_CPUS
)
278 __cmd_query_real_cpus(sys
);
280 if (what
& QUERY_STOR
)
281 __cmd_query_real_stor(sys
);
283 if (what
& QUERY_DEVS
)
284 list_devices(display_rdev
, sys
->con
);
285 if (what
& QUERY_DEVNUM
)
286 con_printf(sys
->con
, "not implemented\n");
294 *! \tok{\sc Query} \tok{\sc Task}
298 *! Lists all of the tasks running on the host. This includes guest virtual
299 *! cpu tasks, as well as system helper tasks.
301 static int cmd_query_task(struct virt_sys
*sys
, char *cmd
, int len
)
303 SHELL_CMD_AUTH(sys
, E
);
305 list_tasks(display_task
, sys
->con
);
310 static void display_names(struct virt_cons
*con
, struct virt_sys
*sys
)
312 con_printf(con
, "%s %04X %-8s\n", type2name(sys
->con
->dev
->type
),
313 sys
->con
->dev
->ccuu
, sys
->directory
->userid
);
319 *! \tok{\sc Query} \tok{\sc NAMes}
323 *! Lists all of the logged in users.
325 static int cmd_query_names(struct virt_sys
*sys
, char *cmd
, int len
)
327 SHELL_CMD_AUTH(sys
, G
);
329 list_users(sys
->con
, display_names
);
337 *! \tok{\sc Query} \tok{\sc USERID}
341 *! Displays the current user id.
343 static int cmd_query_userid(struct virt_sys
*sys
, char *cmd
, int len
)
345 SHELL_CMD_AUTH(sys
, G
);
347 con_printf(sys
->con
, "%s\n", sys
->directory
->userid
);
351 static struct cpcmd cmd_tbl_query
[] = {
352 {"ARCHMODE", cmd_query_archmode
, NULL
},
354 {"CPLEVEL", cmd_query_cplevel
, NULL
},
356 {"TIME", cmd_query_time
, NULL
},
358 {"VIRTUAL", cmd_query_virtual
, NULL
},
359 {"VIRTUA", cmd_query_virtual
, NULL
},
360 {"VIRTU", cmd_query_virtual
, NULL
},
361 {"VIRT", cmd_query_virtual
, NULL
},
362 {"VIR", cmd_query_virtual
, NULL
},
363 {"VI", cmd_query_virtual
, NULL
},
364 {"V", cmd_query_virtual
, NULL
},
366 {"REAL", cmd_query_real
, NULL
},
367 {"REA", cmd_query_real
, NULL
},
368 {"RE", cmd_query_real
, NULL
},
369 {"R", cmd_query_real
, NULL
},
371 {"NAMES", cmd_query_names
, NULL
},
372 {"NAME", cmd_query_names
, NULL
},
373 {"NAM", cmd_query_names
, NULL
},
375 {"TASK", cmd_query_task
, NULL
},
377 {"USERID", cmd_query_userid
, NULL
},