loader: remove shouting from ORB's variable name
[hvf.git] / cp / shell / cmd_query.c
blob81d91a5f479d9397296a861ce307dd4c55760da3
1 /*
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
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),
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 FIXME("cyl count & rdev");
71 con_printf(con, "DASD %04X 3390 %6d CYL ON DASD %04X SCH = %05X\n",
72 vdev->pmcw.dev_num,
73 0, /* FIXME: cyl count */
74 0, /* FIXME: rdev */
75 vdev->sch);
76 break;
77 case VDEV_LINK:
78 FIXME("userid & vdev #");
79 con_printf(con, "LINK %04X TO %s %04X SCH = %05X\n",
80 vdev->pmcw.dev_num,
81 "????", /* FIXME: userid */
82 0xffff, /* FIXME: user's vdev # */
83 vdev->sch);
84 break;
85 default:
86 con_printf(con, "???? unknown device type (%04X, %05X)\n",
87 vdev->pmcw.dev_num, vdev->sch);
88 break;
91 mutex_unlock(&vdev->lock);
94 static void display_task(struct task *task, void *priv)
96 struct virt_cons *con = priv;
97 char state;
99 switch(task->state) {
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,
108 task, state);
112 *!!! QUERY TIME
113 *!! SYNTAX
114 *! \tok{\sc Query} \tok{\sc TIME}
115 *!! XATNYS
116 *!! AUTH G
117 *!! PURPOSE
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);
129 return 0;
133 *!!! QUERY CPLEVEL
134 *!! SYNTAX
135 *! \tok{\sc Query} \tok{\sc CPLEVEL}
136 *!! XATNYS
137 *!! AUTH G
138 *!! PURPOSE
139 *! Displays the HVF version and time of IPL
141 static int cmd_query_time(struct virt_sys *sys, char *cmd, int len)
143 struct datetime dt;
145 SHELL_CMD_AUTH(sys, G);
147 get_parsed_tod(&dt);
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);
152 return 0;
156 *!!! QUERY ARCHMODE
157 *!! SYNTAX
158 *! \tok{\sc Query} \tok{\sc ARCHMODE}
159 *!! XATNYS
160 *!! AUTH G
161 *!! PURPOSE
162 *! Displays the virtual machine's current architecture mode.
164 static int cmd_query_archmode(struct virt_sys *sys, char *cmd, int len)
166 char *mode;
168 SHELL_CMD_AUTH(sys, G);
170 mode = (VCPU_ZARCH(sys->cpu)) ? "z/Arch" : "ESA390";
172 con_printf(sys->con, "ARCHMODE = %s\n", mode);
174 return 0;
178 *!!! QUERY VIRTUAL
179 *!! SYNTAX
180 *! \tok{\sc Query} \tok{\sc Virtual}
181 *!! XATNYS
182 *!! AUTH G
183 *!! PURPOSE
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",
193 sys->cpu->cpuid,
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);
200 return 0;
203 static void __cmd_query_real_cpus(struct virt_sys *sys)
205 con_printf(sys->con, "CPU %02d ID %016lX RUNNING\n",
206 getcpuaddr(),
207 getcpuid());
210 static void __cmd_query_real_stor(struct virt_sys *sys)
212 con_printf(sys->con, "STORAGE = %luM\n", memsize >> 20);
215 enum {
216 QUERY_CPUS = 1 << 0,
217 QUERY_STOR = 1 << 1,
218 QUERY_DEVS = 1 << 2,
219 QUERY_DEVNUM = 1 << 3,
223 *!!! QUERY REAL
224 *!! SYNTAX
225 *! \tok{\sc Query} \tok{\sc Real}
226 *! \begin{stack}
227 *! \\
228 *! \tok{\sc\bf ALL} \\
229 *! \tok{\sc CPUS} \\
230 *! \tok{\sc STORage} \\
231 *! <rdev>
232 *! \end{stack}
233 *!! XATNYS
234 *!! AUTH B
235 *!! PURPOSE
236 *! \cbstart
237 *! Lists the host's real devices, CPUs, and storage
238 *! \cbend
239 *!! NOTES
240 *! \cbstart
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
243 *! system.
244 *! \cbend
245 *!! SETON
247 static int cmd_query_real(struct virt_sys *sys, char *cmd, int len)
249 int what = 0;
250 u64 devnum;
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")) {
259 what = QUERY_CPUS;
260 } else if (!strcasecmp(cmd, "STOR") ||
261 !strcasecmp(cmd, "STORA") ||
262 !strcasecmp(cmd, "STORAG") ||
263 !strcasecmp(cmd, "STORAGE")) {
264 what = QUERY_STOR;
265 } else {
266 cmd = __extract_hex(cmd, &devnum);
267 if (IS_ERR(cmd))
268 return PTR_ERR(cmd);
270 /* sch number must be: X'0000____' */
271 if (devnum & ~0xffffull)
272 return -EINVAL;
274 what = QUERY_DEVNUM;
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");
288 return 0;
292 *!!! QUERY TASK
293 *!! SYNTAX
294 *! \tok{\sc Query} \tok{\sc Task}
295 *!! XATNYS
296 *!! AUTH E
297 *!! PURPOSE
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);
307 return 0;
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);
317 *!!! QUERY NAMES
318 *!! SYNTAX
319 *! \tok{\sc Query} \tok{\sc NAMes}
320 *!! XATNYS
321 *!! AUTH G
322 *!! PURPOSE
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);
331 return 0;
335 *!!! QUERY USERID
336 *!! SYNTAX
337 *! \tok{\sc Query} \tok{\sc USERID}
338 *!! XATNYS
339 *!! AUTH G
340 *!! PURPOSE
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);
348 return 0;
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},
378 {"", NULL, NULL},