cp: guest layer revamp, part 1
[hvf.git] / cp / shell / cmd_query.c
blob7ad2bde925a4b6e20a424df67e82910c70d5b3db
1 /*
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
5 * details.
6 */
8 static char *__guest_state_to_str(enum virt_cpustate st)
10 switch (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";
17 return "???";
20 static void display_rdev(struct device *dev, void *priv)
22 struct virt_cons *con = priv;
23 char buf[40];
25 buf[0] = '\0';
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 ",
35 dev->sch);
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) {
47 case VDEV_CONS:
48 con_printf(con, "CONS %04X 3215 ON %s %04X %s SCH = %05X\n",
49 vdev->pmcw.dev_num,
50 type2name(con->dev->type), // FIXME?
51 con->dev->ccuu,
52 sys->print_ts ? "TS" : "NOTS",
53 vdev->sch);
54 break;
55 case VDEV_DED:
56 con_printf(con, "%-4s %04X %04X ON DEV %04X SCH = %05X\n",
57 type2name(vdev->type),
58 vdev->pmcw.dev_num,
59 vdev->type,
60 vdev->u.dedicate.rdev->ccuu,
61 vdev->sch);
62 break;
63 case VDEV_SPOOL:
64 con_printf(con, "%-4s %04X %04X SCH = %05X\n",
65 type2name(vdev->type),
66 vdev->pmcw.dev_num, vdev->type,
67 vdev->sch);
68 break;
69 case VDEV_MDISK:
70 con_printf(con, "DASD %04X 3390 %6d CYL ON DASD %04X SCH = %05X\n",
71 vdev->pmcw.dev_num,
72 0, /* FIXME: cyl count */
73 0, /* FIXME: rdev */
74 vdev->sch);
75 break;
76 case VDEV_LINK:
77 con_printf(con, "LINK %04X TO %s %04X SCH = %05X\n",
78 vdev->pmcw.dev_num,
79 "????", /* FIXME: userid */
80 0xffff, /* FIXME: user's vdev # */
81 vdev->sch);
82 break;
83 default:
84 con_printf(con, "???? unknown device type (%04X, %05X)\n",
85 vdev->pmcw.dev_num, vdev->sch);
86 break;
89 mutex_unlock(&vdev->lock);
92 static void display_task(struct task *task, void *priv)
94 struct virt_cons *con = priv;
95 char state;
97 switch(task->state) {
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);
110 *!!! QUERY TIME
111 *!! SYNTAX
112 *! \tok{\sc Query} \tok{\sc TIME}
113 *!! XATNYS
114 *!! AUTH G
115 *!! PURPOSE
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);
127 return 0;
131 *!!! QUERY CPLEVEL
132 *!! SYNTAX
133 *! \tok{\sc Query} \tok{\sc CPLEVEL}
134 *!! XATNYS
135 *!! AUTH G
136 *!! PURPOSE
137 *! Displays the HVF version and time of IPL
139 static int cmd_query_time(struct virt_sys *sys, char *cmd, int len)
141 struct datetime dt;
143 SHELL_CMD_AUTH(sys, G);
145 get_parsed_tod(&dt);
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);
150 return 0;
154 *!!! QUERY ARCHMODE
155 *!! SYNTAX
156 *! \tok{\sc Query} \tok{\sc ARCHMODE}
157 *!! XATNYS
158 *!! AUTH G
159 *!! PURPOSE
160 *! Displays the virtual machine's current architecture mode.
162 static int cmd_query_archmode(struct virt_sys *sys, char *cmd, int len)
164 char *mode;
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);
172 return 0;
176 *!!! QUERY VIRTUAL
177 *!! SYNTAX
178 *! \tok{\sc Query} \tok{\sc Virtual}
179 *!! XATNYS
180 *!! AUTH G
181 *!! PURPOSE
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);
198 return 0;
201 static void __cmd_query_real_cpus(struct virt_sys *sys)
203 con_printf(sys->con, "CPU %02d ID %016llX RUNNING\n",
204 getcpuaddr(),
205 getcpuid());
208 static void __cmd_query_real_stor(struct virt_sys *sys)
210 con_printf(sys->con, "STORAGE = %lluM\n", memsize >> 20);
213 enum {
214 QUERY_CPUS = 1 << 0,
215 QUERY_STOR = 1 << 1,
216 QUERY_DEVS = 1 << 2,
217 QUERY_DEVNUM = 1 << 3,
221 *!!! QUERY REAL
222 *!! SYNTAX
223 *! \tok{\sc Query} \tok{\sc Real}
224 *! \begin{stack}
225 *! \\
226 *! \tok{\sc\bf ALL} \\
227 *! \tok{\sc CPUS} \\
228 *! \tok{\sc STORage} \\
229 *! <rdev>
230 *! \end{stack}
231 *!! XATNYS
232 *!! AUTH B
233 *!! PURPOSE
234 *! \cbstart
235 *! Lists the host's real devices, CPUs, and storage
236 *! \cbend
237 *!! NOTES
238 *! \cbstart
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
241 *! system.
242 *! \cbend
243 *!! SETON
245 static int cmd_query_real(struct virt_sys *sys, char *cmd, int len)
247 int what = 0;
248 u64 devnum;
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")) {
257 what = QUERY_CPUS;
258 } else if (!strcasecmp(cmd, "STOR") ||
259 !strcasecmp(cmd, "STORA") ||
260 !strcasecmp(cmd, "STORAG") ||
261 !strcasecmp(cmd, "STORAGE")) {
262 what = QUERY_STOR;
263 } else {
264 cmd = __extract_hex(cmd, &devnum);
265 if (IS_ERR(cmd))
266 return PTR_ERR(cmd);
268 /* sch number must be: X'0000____' */
269 if (devnum & ~0xffffull)
270 return -EINVAL;
272 what = QUERY_DEVNUM;
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");
286 return 0;
290 *!!! QUERY TASK
291 *!! SYNTAX
292 *! \tok{\sc Query} \tok{\sc Task}
293 *!! XATNYS
294 *!! AUTH E
295 *!! PURPOSE
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);
305 return 0;
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);
315 *!!! QUERY NAMES
316 *!! SYNTAX
317 *! \tok{\sc Query} \tok{\sc NAMes}
318 *!! XATNYS
319 *!! AUTH G
320 *!! PURPOSE
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);
329 return 0;
333 *!!! QUERY USERID
334 *!! SYNTAX
335 *! \tok{\sc Query} \tok{\sc USERID}
336 *!! XATNYS
337 *!! AUTH G
338 *!! PURPOSE
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);
346 return 0;
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},
376 {"", NULL, NULL},