2 * (C) Copyright 2007-2011 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
), // FIXME?
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 con_printf(con
, "DASD %04X 3390 %6d CYL ON DASD %04X SCH = %05X\n",
72 0, /* FIXME: cyl count */
77 con_printf(con
, "LINK %04X TO %s %04X SCH = %05X\n",
79 "????", /* FIXME: userid */
80 0xffff, /* FIXME: user's vdev # */
84 con_printf(con
, "???? unknown device type (%04X, %05X)\n",
85 vdev
->pmcw
.dev_num
, vdev
->sch
);
89 mutex_unlock(&vdev
->lock
);
92 static void display_task(struct task
*task
, void *priv
)
94 struct virt_cons
*con
= priv
;
98 case TASK_RUNNING
: state
= 'R'; break;
99 case TASK_SLEEPING
: state
= 'S'; break;
100 case TASK_LOCKED
: state
= 'L'; break;
101 case TASK_ZOMBIE
: state
= 'Z'; break;
102 default: state
= '?'; break;
105 con_printf(con
, "%*s %p %c %016llX\n", -TASK_NAME_LEN
, task
->name
,
106 task
, state
, task
->regs
.psw
.ptr
);
112 *! \tok{\sc Query} \tok{\sc TIME}
116 *! Displays the current time
118 static int cmd_query_cplevel(struct virt_sys
*sys
, char *cmd
, int len
)
120 SHELL_CMD_AUTH(sys
, G
);
122 con_printf(sys
->con
, "HVF version " VERSION
"\n");
123 con_printf(sys
->con
, "IPL at %02d:%02d:%02d UTC %04d-%02d-%02d\n",
124 ipltime
.th
, ipltime
.tm
, ipltime
.ts
, ipltime
.dy
,
125 ipltime
.dm
, ipltime
.dd
);
133 *! \tok{\sc Query} \tok{\sc CPLEVEL}
137 *! Displays the HVF version and time of IPL
139 static int cmd_query_time(struct virt_sys
*sys
, char *cmd
, int len
)
143 SHELL_CMD_AUTH(sys
, G
);
147 con_printf(sys
->con
, "TIME IS %02d:%02d:%02d UTC %04d-%02d-%02d\n",
148 dt
.th
, dt
.tm
, dt
.ts
, dt
.dy
, dt
.dm
, dt
.dd
);
156 *! \tok{\sc Query} \tok{\sc ARCHMODE}
160 *! Displays the virtual machine's current architecture mode.
162 static int cmd_query_archmode(struct virt_sys
*sys
, char *cmd
, int len
)
166 SHELL_CMD_AUTH(sys
, G
);
168 mode
= (VCPU_ZARCH(sys
->task
->cpu
)) ? "z/Arch" : "ESA390";
170 con_printf(sys
->con
, "ARCHMODE = %s\n", mode
);
178 *! \tok{\sc Query} \tok{\sc Virtual}
182 *! Lists all of the guest's virtual devices
184 static int cmd_query_virtual(struct virt_sys
*sys
, char *cmd
, int len
)
186 struct virt_device
*vdev
;
188 SHELL_CMD_AUTH(sys
, G
);
190 con_printf(sys
->con
, "CPU 00 ID %016llX %s\n",
191 sys
->task
->cpu
->cpuid
,
192 __guest_state_to_str(sys
->task
->cpu
->state
));
193 con_printf(sys
->con
, "STORAGE = %lluM\n", sys
->directory
->storage_size
>> 20);
195 for_each_vdev(sys
, vdev
)
196 display_vdev(sys
->con
, vdev
);
201 static void __cmd_query_real_cpus(struct virt_sys
*sys
)
203 con_printf(sys
->con
, "CPU %02d ID %016llX RUNNING\n",
208 static void __cmd_query_real_stor(struct virt_sys
*sys
)
210 con_printf(sys
->con
, "STORAGE = %lluM\n", memsize
>> 20);
217 QUERY_DEVNUM
= 1 << 3,
223 *! \tok{\sc Query} \tok{\sc Real}
226 *! \tok{\sc\bf ALL} \\
228 *! \tok{\sc STORage} \\
235 *! Lists the host's real devices, CPUs, and storage
239 *! \item Specifying real device numbers is not supported at the moment.
240 *! Instead, use QUERY REAL ALL to display all devices attached to the
245 static int cmd_query_real(struct virt_sys
*sys
, char *cmd
, int len
)
250 SHELL_CMD_AUTH(sys
, B
);
252 if (strnlen(cmd
, len
) == 0) {
253 what
= QUERY_CPUS
| QUERY_STOR
| QUERY_DEVS
;
254 } else if (!strcasecmp(cmd
, "ALL")) {
255 what
= QUERY_CPUS
| QUERY_STOR
| QUERY_DEVS
;
256 } else if (!strcasecmp(cmd
, "CPUS")) {
258 } else if (!strcasecmp(cmd
, "STOR") ||
259 !strcasecmp(cmd
, "STORA") ||
260 !strcasecmp(cmd
, "STORAG") ||
261 !strcasecmp(cmd
, "STORAGE")) {
264 cmd
= __extract_hex(cmd
, &devnum
);
268 /* sch number must be: X'0000____' */
269 if (devnum
& ~0xffffull
)
275 if (what
& QUERY_CPUS
)
276 __cmd_query_real_cpus(sys
);
278 if (what
& QUERY_STOR
)
279 __cmd_query_real_stor(sys
);
281 if (what
& QUERY_DEVS
)
282 list_devices(display_rdev
, sys
->con
);
283 if (what
& QUERY_DEVNUM
)
284 con_printf(sys
->con
, "not implemented\n");
292 *! \tok{\sc Query} \tok{\sc Task}
296 *! Lists all of the tasks running on the host. This includes guest virtual
297 *! cpu tasks, as well as system helper tasks.
299 static int cmd_query_task(struct virt_sys
*sys
, char *cmd
, int len
)
301 SHELL_CMD_AUTH(sys
, E
);
303 list_tasks(display_task
, sys
->con
);
308 static void display_names(struct virt_cons
*con
, struct virt_sys
*sys
)
310 con_printf(con
, "%s %04X %-8s\n", type2name(sys
->con
->dev
->type
),
311 sys
->con
->dev
->ccuu
, sys
->directory
->userid
);
317 *! \tok{\sc Query} \tok{\sc NAMes}
321 *! Lists all of the logged in users.
323 static int cmd_query_names(struct virt_sys
*sys
, char *cmd
, int len
)
325 SHELL_CMD_AUTH(sys
, G
);
327 list_users(sys
->con
, display_names
);
335 *! \tok{\sc Query} \tok{\sc USERID}
339 *! Displays the current user id.
341 static int cmd_query_userid(struct virt_sys
*sys
, char *cmd
, int len
)
343 SHELL_CMD_AUTH(sys
, G
);
345 con_printf(sys
->con
, "%s\n", sys
->directory
->userid
);
349 static struct cpcmd cmd_tbl_query
[] = {
350 {"ARCHMODE", cmd_query_archmode
, NULL
},
352 {"CPLEVEL", cmd_query_cplevel
, NULL
},
354 {"TIME", cmd_query_time
, NULL
},
356 {"VIRTUAL", cmd_query_virtual
, NULL
},
357 {"VIRTUA", cmd_query_virtual
, NULL
},
358 {"VIRTU", cmd_query_virtual
, NULL
},
359 {"VIRT", cmd_query_virtual
, NULL
},
360 {"VIR", cmd_query_virtual
, NULL
},
361 {"VI", cmd_query_virtual
, NULL
},
362 {"V", cmd_query_virtual
, NULL
},
364 {"REAL", cmd_query_real
, NULL
},
365 {"REA", cmd_query_real
, NULL
},
366 {"RE", cmd_query_real
, NULL
},
367 {"R", cmd_query_real
, NULL
},
369 {"NAMES", cmd_query_names
, NULL
},
370 {"NAME", cmd_query_names
, NULL
},
371 {"NAM", cmd_query_names
, NULL
},
373 {"TASK", cmd_query_task
, NULL
},
375 {"USERID", cmd_query_userid
, NULL
},