direct-io.hg

changeset 5520:7d9339b717d6

bitkeeper revision 1.1722 (42b7bcc4JmG_ITQ35E28L1mWc_g_ZQ)

[PATCH] ioemu-monitor.patch

The following patch adds back qemu monitor commands to qemu-dm which
make sense. That is, eject and change devices, and show some device
state.

Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com>

===== tools/ioemu/monitor.c 1.1 vs edited =====
author leendert@watson.ibm.com[iap10]
date Tue Jun 21 07:07:48 2005 +0000 (2005-06-21)
parents dbca2f11731d
children f2b4ab649a13
files tools/ioemu/hw/i8259.c tools/ioemu/monitor.c
line diff
     1.1 --- a/tools/ioemu/hw/i8259.c	Tue Jun 21 07:06:04 2005 +0000
     1.2 +++ b/tools/ioemu/hw/i8259.c	Tue Jun 21 07:07:48 2005 +0000
     1.3 @@ -27,7 +27,7 @@
     1.4  //#define DEBUG_PIC
     1.5  
     1.6  //#define DEBUG_IRQ_LATENCY
     1.7 -//#define DEBUG_IRQ_COUNT
     1.8 +#define DEBUG_IRQ_COUNT
     1.9  
    1.10  typedef struct PicState {
    1.11      uint8_t last_irr; /* edge detection */
     2.1 --- a/tools/ioemu/monitor.c	Tue Jun 21 07:06:04 2005 +0000
     2.2 +++ b/tools/ioemu/monitor.c	Tue Jun 21 07:07:48 2005 +0000
     2.3 @@ -123,6 +123,108 @@ static int compare_cmd(const char *name,
     2.4      return 0;
     2.5  }
     2.6  
     2.7 +static void help_cmd1(term_cmd_t *cmds, const char *prefix, const char *name)
     2.8 +{
     2.9 +    term_cmd_t *cmd;
    2.10 +
    2.11 +    for(cmd = cmds; cmd->name != NULL; cmd++) {
    2.12 +        if (!name || !strcmp(name, cmd->name))
    2.13 +            term_printf("%s%s %s -- %s\n", prefix, cmd->name, cmd->params, cmd->help);
    2.14 +    }
    2.15 +}
    2.16 +
    2.17 +static void help_cmd(const char *name)
    2.18 +{
    2.19 +    if (name && !strcmp(name, "info")) {
    2.20 +        help_cmd1(info_cmds, "info ", NULL);
    2.21 +    } else {
    2.22 +        help_cmd1(term_cmds, "", name);
    2.23 +        if (name && !strcmp(name, "log")) {
    2.24 +            CPULogItem *item;
    2.25 +            term_printf("Log items (comma separated):\n");
    2.26 +            term_printf("%-10s %s\n", "none", "remove all logs");
    2.27 +            for(item = cpu_log_items; item->mask != 0; item++) {
    2.28 +                term_printf("%-10s %s\n", item->name, item->help);
    2.29 +            }
    2.30 +        }
    2.31 +    }
    2.32 +}
    2.33 +
    2.34 +static void do_help(const char *name)
    2.35 +{
    2.36 +    help_cmd(name);
    2.37 +}
    2.38 +
    2.39 +static void do_commit(void)
    2.40 +{
    2.41 +    int i;
    2.42 +
    2.43 +    for (i = 0; i < MAX_DISKS; i++) {
    2.44 +        if (bs_table[i]) {
    2.45 +            bdrv_commit(bs_table[i]);
    2.46 +        }
    2.47 +    }
    2.48 +}
    2.49 +
    2.50 +static void do_info(const char *item)
    2.51 +{
    2.52 +    term_cmd_t *cmd;
    2.53 +
    2.54 +    if (!item)
    2.55 +        goto help;
    2.56 +    for(cmd = info_cmds; cmd->name != NULL; cmd++) {
    2.57 +        if (compare_cmd(item, cmd->name))
    2.58 +            goto found;
    2.59 +    }
    2.60 + help:
    2.61 +    help_cmd("info");
    2.62 +    return;
    2.63 + found:
    2.64 +    cmd->handler();
    2.65 +}
    2.66 +
    2.67 +static void do_info_version(void)
    2.68 +{
    2.69 +  term_printf("%s\n", QEMU_VERSION);
    2.70 +}
    2.71 +
    2.72 +static void do_info_network(void)
    2.73 +{
    2.74 +    int i, j;
    2.75 +    NetDriverState *nd;
    2.76 +
    2.77 +    for(i = 0; i < nb_nics; i++) {
    2.78 +        nd = &nd_table[i];
    2.79 +        term_printf("%d: ifname=%s macaddr=", i, nd->ifname);
    2.80 +        for(j = 0; j < 6; j++) {
    2.81 +            if (j > 0)
    2.82 +                term_printf(":");
    2.83 +            term_printf("%02x", nd->macaddr[j]);
    2.84 +        }
    2.85 +        term_printf("\n");
    2.86 +    }
    2.87 +}
    2.88 +
    2.89 +static void do_info_block(void)
    2.90 +{
    2.91 +    bdrv_info();
    2.92 +}
    2.93 +
    2.94 +static void do_info_history (void)
    2.95 +{
    2.96 +    int i;
    2.97 +    const char *str;
    2.98 +
    2.99 +    i = 0;
   2.100 +    for(;;) {
   2.101 +        str = readline_get_history(i);
   2.102 +        if (!str)
   2.103 +            break;
   2.104 +        term_printf("%d: '%s'\n", i, str);
   2.105 +        i++;
   2.106 +    }
   2.107 +}
   2.108 +
   2.109  static void do_quit(void)
   2.110  {
   2.111      extern int domid;
   2.112 @@ -134,12 +236,191 @@ static void do_quit(void)
   2.113      exit(0);
   2.114  }
   2.115  
   2.116 +static int eject_device(BlockDriverState *bs, int force)
   2.117 +{
   2.118 +    if (bdrv_is_inserted(bs)) {
   2.119 +        if (!force) {
   2.120 +            if (!bdrv_is_removable(bs)) {
   2.121 +                term_printf("device is not removable\n");
   2.122 +                return -1;
   2.123 +            }
   2.124 +            if (bdrv_is_locked(bs)) {
   2.125 +                term_printf("device is locked\n");
   2.126 +                return -1;
   2.127 +            }
   2.128 +        }
   2.129 +        bdrv_close(bs);
   2.130 +    }
   2.131 +    return 0;
   2.132 +}
   2.133 +
   2.134 +static void do_eject(int force, const char *filename)
   2.135 +{
   2.136 +    BlockDriverState *bs;
   2.137 +
   2.138 +    bs = bdrv_find(filename);
   2.139 +    if (!bs) {
   2.140 +        term_printf("device not found\n");
   2.141 +        return;
   2.142 +    }
   2.143 +    eject_device(bs, force);
   2.144 +}
   2.145 +
   2.146 +static void do_change(const char *device, const char *filename)
   2.147 +{
   2.148 +    BlockDriverState *bs;
   2.149 +#if 0
   2.150 +    int i;
   2.151 +    char password[256];
   2.152 +#endif
   2.153 +
   2.154 +    bs = bdrv_find(device);
   2.155 +    if (!bs) {
   2.156 +        term_printf("device not found\n");
   2.157 +        return;
   2.158 +    }
   2.159 +    if (eject_device(bs, 0) < 0)
   2.160 +        return;
   2.161 +    bdrv_open(bs, filename, 0);
   2.162 +#if 0
   2.163 +    if (bdrv_is_encrypted(bs)) {
   2.164 +        term_printf("%s is encrypted.\n", device);
   2.165 +        for(i = 0; i < 3; i++) {
   2.166 +            monitor_readline("Password: ", 1, password, sizeof(password));
   2.167 +            if (bdrv_set_key(bs, password) == 0)
   2.168 +                break;
   2.169 +            term_printf("invalid password\n");
   2.170 +        }
   2.171 +    }
   2.172 +#endif
   2.173 +}
   2.174 +
   2.175 +static void do_screen_dump(const char *filename)
   2.176 +{
   2.177 +    vga_screen_dump(filename);
   2.178 +}
   2.179 +
   2.180 +static void do_log(const char *items)
   2.181 +{
   2.182 +    int mask;
   2.183 +
   2.184 +    if (!strcmp(items, "none")) {
   2.185 +        mask = 0;
   2.186 +    } else {
   2.187 +        mask = cpu_str_to_log_mask(items);
   2.188 +        if (!mask) {
   2.189 +            help_cmd("log");
   2.190 +            return;
   2.191 +        }
   2.192 +    }
   2.193 +    cpu_set_log(mask);
   2.194 +}
   2.195 +
   2.196  static term_cmd_t term_cmds[] = {
   2.197 +    { "help|?", "s?", do_help,
   2.198 +      "[cmd]", "show the help" },
   2.199 +    { "commit", "", do_commit,
   2.200 +      "", "commit changes to the disk images (if -snapshot is used)" },
   2.201 +    { "info", "s?", do_info,
   2.202 +      "subcommand", "show various information about the system state" },
   2.203 +    { "q|quit", "", do_quit,
   2.204 +      "", "quit the emulator" },
   2.205 +    { "eject", "-fB", do_eject,
   2.206 +      "[-f] device", "eject a removable media (use -f to force it)" },
   2.207 +    { "change", "BF", do_change,
   2.208 +      "device filename", "change a removable media" },
   2.209 +    { "screendump", "F", do_screen_dump,
   2.210 +      "filename", "save screen into PPM image 'filename'" },
   2.211 +    { "log", "s", do_log,
   2.212 +      "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
   2.213      { "q|quit", "", do_quit,
   2.214        "", "quit the emulator" },
   2.215      { NULL, NULL, }, 
   2.216  };
   2.217  
   2.218 +static term_cmd_t info_cmds[] = {
   2.219 +    { "version", "", do_info_version,
   2.220 +      "", "show the version of qemu" },
   2.221 +    { "network", "", do_info_network,
   2.222 +      "", "show the network state" },
   2.223 +    { "block", "", do_info_block,
   2.224 +      "", "show the block devices" },
   2.225 +    { "history", "", do_info_history,
   2.226 +      "", "show the command line history", },
   2.227 +    { "irq", "", irq_info,
   2.228 +      "", "show the interrupts statistics (if available)", },
   2.229 +    { "pic", "", pic_info,
   2.230 +      "", "show i8259 (PIC) state", },
   2.231 +    { "pci", "", pci_info,
   2.232 +      "", "show PCI info", },
   2.233 +    { NULL, NULL, },
   2.234 +};
   2.235 +
   2.236 +static int get_str(char *buf, int buf_size, const char **pp)
   2.237 +{
   2.238 +    const char *p;
   2.239 +    char *q;
   2.240 +    int c;
   2.241 +
   2.242 +    q = buf;
   2.243 +    p = *pp;
   2.244 +    while (isspace(*p))
   2.245 +        p++;
   2.246 +    if (*p == '\0') {
   2.247 +    fail:
   2.248 +        *q = '\0';
   2.249 +        *pp = p;
   2.250 +        return -1;
   2.251 +    }
   2.252 +    if (*p == '\"') {
   2.253 +        p++;
   2.254 +        while (*p != '\0' && *p != '\"') {
   2.255 +            if (*p == '\\') {
   2.256 +                p++;
   2.257 +                c = *p++;
   2.258 +                switch(c) {
   2.259 +                case 'n':
   2.260 +                    c = '\n';
   2.261 +                    break;
   2.262 +                case 'r':
   2.263 +                    c = '\r';
   2.264 +                    break;
   2.265 +                case '\\':
   2.266 +                case '\'':
   2.267 +                case '\"':
   2.268 +                    break;
   2.269 +                default:
   2.270 +                    qemu_printf("unsupported escape code: '\\%c'\n", c);
   2.271 +                    goto fail;
   2.272 +                }
   2.273 +                if ((q - buf) < buf_size - 1) {
   2.274 +                    *q++ = c;
   2.275 +                }
   2.276 +            } else {
   2.277 +                if ((q - buf) < buf_size - 1) {
   2.278 +                    *q++ = *p;
   2.279 +                }
   2.280 +                p++;
   2.281 +            }
   2.282 +        }
   2.283 +        if (*p != '\"') {
   2.284 +            qemu_printf("unterminated string\n");
   2.285 +            goto fail;
   2.286 +        }
   2.287 +        p++;
   2.288 +    } else {
   2.289 +        while (*p != '\0' && !isspace(*p)) {
   2.290 +            if ((q - buf) < buf_size - 1) {
   2.291 +                *q++ = *p;
   2.292 +            }
   2.293 +            p++;
   2.294 +        }
   2.295 +    }
   2.296 +    *q = '\0';
   2.297 +    *pp = p;
   2.298 +    return 0;
   2.299 +}
   2.300 +
   2.301  #define MAX_ARGS 16
   2.302  
   2.303  static void monitor_handle_command(const char *cmdline)
   2.304 @@ -149,6 +430,7 @@ static void monitor_handle_command(const
   2.305      int c, nb_args, len, i;
   2.306      term_cmd_t *cmd;
   2.307      char cmdname[256];
   2.308 +    char buf[1024];
   2.309      void *str_allocated[MAX_ARGS];
   2.310      void *args[MAX_ARGS];
   2.311  
   2.312 @@ -193,10 +475,53 @@ static void monitor_handle_command(const
   2.313              break;
   2.314          typestr++;
   2.315          switch(c) {
   2.316 -        /* TODO: add more commands we need here to support vmx device model */
   2.317          case 'F':
   2.318          case 'B':
   2.319          case 's':
   2.320 +            {
   2.321 +                int ret;
   2.322 +                char *str;
   2.323 +
   2.324 +                while (isspace(*p))
   2.325 +                    p++;
   2.326 +                if (*typestr == '?') {
   2.327 +                    typestr++;
   2.328 +                    if (*p == '\0') {
   2.329 +                        /* no optional string: NULL argument */
   2.330 +                        str = NULL;
   2.331 +                        goto add_str;
   2.332 +                    }
   2.333 +                }
   2.334 +                ret = get_str(buf, sizeof(buf), &p);
   2.335 +                if (ret < 0) {
   2.336 +                    switch(c) {
   2.337 +                    case 'F':
   2.338 +                        term_printf("%s: filename expected\n", cmdname);
   2.339 +                        break;
   2.340 +                    case 'B':
   2.341 +                        term_printf("%s: block device name expected\n", cmdname);
   2.342 +                        break;
   2.343 +                    default:
   2.344 +                        term_printf("%s: string expected\n", cmdname);
   2.345 +                        break;
   2.346 +                    }
   2.347 +                    goto fail;
   2.348 +                }
   2.349 +                str = qemu_malloc(strlen(buf) + 1);
   2.350 +                strcpy(str, buf);
   2.351 +                str_allocated[nb_args] = str;
   2.352 +            add_str:
   2.353 +                if (nb_args >= MAX_ARGS) {
   2.354 +#if 0
   2.355 +                error_args:
   2.356 +#endif
   2.357 +                    term_printf("%s: too many arguments\n", cmdname);
   2.358 +                    goto fail;
   2.359 +                }
   2.360 +                args[nb_args++] = str;
   2.361 +            }
   2.362 +            break;
   2.363 +        /* TODO: add more commands we need here to support vmx device model */
   2.364          case '/':
   2.365          case 'i':
   2.366          case '-':