direct-io.hg

changeset 523:65cdeae1932c

bitkeeper revision 1.290 (3f098d9aV-utpH62PCMaflI0ggwCXQ)

Use ioctl rather than /proc/xeno/new_dom_data when creating a new
domain.
author sos22@labyrinth.cl.cam.ac.uk
date Mon Jul 07 15:11:22 2003 +0000 (2003-07-07)
parents 07cb518caf2f
children 66de2841a3d3
files tools/internal/xi_create.c xen/include/hypervisor-ifs/dom0_ops.h xenolinux-2.4.21-sparse/arch/xeno/drivers/dom0/dom0_core.c
line diff
     1.1 --- a/tools/internal/xi_create.c	Mon Jul 07 14:45:15 2003 +0000
     1.2 +++ b/tools/internal/xi_create.c	Mon Jul 07 15:11:22 2003 +0000
     1.3 @@ -12,6 +12,9 @@
     1.4  #include <sys/types.h>
     1.5  #include <sys/stat.h>
     1.6  #include <stdlib.h>
     1.7 +#include <sys/ioctl.h>
     1.8 +#include <errno.h>
     1.9 +#include <string.h>
    1.10  
    1.11  #include "hypervisor_defs.h"
    1.12  #include "dom0_ops.h"
    1.13 @@ -36,46 +39,36 @@ static void PERROR (char *message)
    1.14  
    1.15  /***********************************************************************/
    1.16  
    1.17 -static dom0_newdomain_t * create_new_domain(long req_mem, char *name)
    1.18 +static int create_new_domain(long req_mem, char *name)
    1.19  {
    1.20 -    dom0_newdomain_t * dom_data;
    1.21      char cmd_path[MAX_PATH];
    1.22 -    char dom_id_path[MAX_PATH];
    1.23 -    dom0_op_t dop;
    1.24      int cmd_fd;
    1.25 -    int id_fd;
    1.26 +    int dom_id;
    1.27 +    struct dom0_createdomain_args argbuf;
    1.28  
    1.29      /* open the /proc command interface */
    1.30      sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
    1.31 -    cmd_fd = open(cmd_path, O_WRONLY);
    1.32 +    cmd_fd = open(cmd_path, O_RDWR);
    1.33      if(cmd_fd < 0){
    1.34          PERROR ("Could not open PROC_CMD interface");
    1.35 -        return 0;
    1.36 +        return -1;
    1.37      }
    1.38  
    1.39 -    dop.cmd = DOM0_CREATEDOMAIN;
    1.40 -    dop.u.newdomain.memory_kb = req_mem;
    1.41 -    strncpy (dop.u.newdomain.name, name, MAX_DOMAIN_NAME - 1);
    1.42 -    dop.u.newdomain.name[MAX_DOMAIN_NAME - 1] = 0;
    1.43 -
    1.44 -    write(cmd_fd, &dop, sizeof(dom0_op_t));
    1.45 +    argbuf.kb_mem = req_mem;
    1.46 +    argbuf.name = name;
    1.47 +    dom_id = ioctl(cmd_fd, IOCTL_DOM0_CREATEDOMAIN, &argbuf);
    1.48 +    if (dom_id < 0) {
    1.49 +      PERROR("creating new domain");
    1.50 +    }
    1.51      close(cmd_fd);
    1.52 -
    1.53 -    sprintf(dom_id_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", 
    1.54 -        PROC_DOM_DATA);
    1.55 -    while((id_fd = open(dom_id_path, O_RDONLY)) < 0) continue;
    1.56 -    dom_data = (dom0_newdomain_t *)malloc(sizeof(dom0_newdomain_t));
    1.57 -    read(id_fd, dom_data, sizeof(dom0_newdomain_t));
    1.58 -    close(id_fd);
    1.59 -    
    1.60 -    return dom_data;
    1.61 +    return dom_id;
    1.62  }    
    1.63  
    1.64  /***********************************************************************/
    1.65  
    1.66  int main(int argc, char **argv)
    1.67  {
    1.68 -  dom0_newdomain_t * dom_data;
    1.69 +  int dom_id;
    1.70  
    1.71    if (argv[0] != NULL) 
    1.72      {
    1.73 @@ -88,11 +81,13 @@ int main(int argc, char **argv)
    1.74        return -1;
    1.75      }
    1.76  
    1.77 -  if(!(dom_data = create_new_domain(atol(argv[1]), argv[2]))) 
    1.78 +  dom_id = create_new_domain(atol(argv[1]), argv[2]);
    1.79 +
    1.80 +  if(dom_id < 0)
    1.81      {
    1.82        return -1;
    1.83      }
    1.84  
    1.85 -  fprintf (stdout, "%d\n", dom_data -> domain);
    1.86 +  fprintf (stdout, "%d\n", dom_id);
    1.87    return 0;
    1.88  }
     2.1 --- a/xen/include/hypervisor-ifs/dom0_ops.h	Mon Jul 07 14:45:15 2003 +0000
     2.2 +++ b/xen/include/hypervisor-ifs/dom0_ops.h	Mon Jul 07 15:11:22 2003 +0000
     2.3 @@ -24,6 +24,8 @@
     2.4  #define MAX_CMD_LEN       256
     2.5  #define MAX_DOMAIN_NAME    16
     2.6  
     2.7 +#define IOCTL_DOM0_CREATEDOMAIN _IOC(_IOC_NONE, 'x', 0, 0)
     2.8 +
     2.9  typedef struct dom0_newdomain_st 
    2.10  {
    2.11      unsigned int domain;    // return parameter
    2.12 @@ -112,4 +114,12 @@ typedef struct dom0_op_st
    2.13  } dom0_op_t;
    2.14  #endif
    2.15  
    2.16 +/* Arguments to the CREATEDOMAIN ioctl on /proc/xeno/dom0_cmd.
    2.17 +   Probably belongs in a Linux include file somewhere... */
    2.18 +struct dom0_createdomain_args
    2.19 +{
    2.20 +  unsigned int kb_mem;
    2.21 +  const char *name;
    2.22 +};
    2.23 +
    2.24  #endif
     3.1 --- a/xenolinux-2.4.21-sparse/arch/xeno/drivers/dom0/dom0_core.c	Mon Jul 07 14:45:15 2003 +0000
     3.2 +++ b/xenolinux-2.4.21-sparse/arch/xeno/drivers/dom0/dom0_core.c	Mon Jul 07 15:11:22 2003 +0000
     3.3 @@ -57,14 +57,20 @@ int direct_disc_unmap(unsigned long, uns
     3.4  
     3.5  static unsigned char readbuf[1204];
     3.6  
     3.7 -static int cmd_read_proc(char *page, char **start, off_t off,
     3.8 -                         int count, int *eof, void *data)
     3.9 +static int dom0_cmd_read(struct file *fp, char *buf, size_t count, loff_t *off)
    3.10  {
    3.11 -    strcpy(page, readbuf);
    3.12 +    int copied, maxlen;
    3.13 +    if (count > 1024)
    3.14 +        count = 1024;
    3.15 +    maxlen = strlen(readbuf);
    3.16 +    if (count > maxlen)
    3.17 +      count = maxlen;
    3.18 +    copied = count - copy_to_user(buf, readbuf, count);
    3.19      *readbuf = '\0';
    3.20 -    *eof = 1;
    3.21 -    *start = page;
    3.22 -    return strlen(page);
    3.23 +    if (copied != count)
    3.24 +      return -EFAULT;
    3.25 +    else
    3.26 +      return copied;
    3.27  }
    3.28  
    3.29  static ssize_t dom_usage_read(struct file * file, char * buff, size_t size, loff_t * off)
    3.30 @@ -265,13 +271,11 @@ struct file_operations newdom_data_fops 
    3.31      read:    dom_data_read,
    3.32  };
    3.33  
    3.34 -static int cmd_write_proc(struct file *file, const char *buffer, 
    3.35 -                          u_long count, void *data)
    3.36 +static int dom0_cmd_write(struct file *file, const char *buffer, size_t size,
    3.37 +			  loff_t *off)
    3.38  {
    3.39      dom0_op_t op;
    3.40      int ret = 0;
    3.41 -    struct proc_dir_entry * new_dom_id;
    3.42 -    dom0_newdomain_t * params;
    3.43      
    3.44      copy_from_user(&op, buffer, sizeof(dom0_op_t));
    3.45  
    3.46 @@ -285,34 +289,18 @@ static int cmd_write_proc(struct file *f
    3.47          ret = HYPERVISOR_pt_update((void *)op.u.pgupdate.pgt_update_arr,
    3.48                                     op.u.pgupdate.num_pgt_updates);
    3.49      }
    3.50 +    else if (op.cmd == DOM0_CREATEDOMAIN)
    3.51 +    {
    3.52 +        /* This is now handled through an ioctl interface. Trying to
    3.53 +	   do it this way means the /proc files for the new domain
    3.54 +	   don't get created properly. */
    3.55 +        ret = -EOPNOTSUPP;
    3.56 +    }
    3.57      else
    3.58      {
    3.59          ret = HYPERVISOR_dom0_op(&op);
    3.60 -
    3.61 -        /* if new domain created, create proc entries */
    3.62 -        if(op.cmd == DOM0_CREATEDOMAIN) {
    3.63 -            create_proc_dom_entries(ret);
    3.64 -
    3.65 -            params = (dom0_newdomain_t *)kmalloc(sizeof(dom0_newdomain_t),
    3.66 -                                                 GFP_KERNEL);
    3.67 -            params->memory_kb = op.u.newdomain.memory_kb;
    3.68 -            params->pg_head = op.u.newdomain.pg_head;
    3.69 -            params->num_vifs = op.u.newdomain.num_vifs;
    3.70 -            params->domain = op.u.newdomain.domain;
    3.71 -
    3.72 -            /* now notify user space of the new domain's id */
    3.73 -            new_dom_id = create_proc_entry("new_dom_data", 0600, xeno_base);
    3.74 -            if ( new_dom_id != NULL )
    3.75 -            {
    3.76 -                new_dom_id->owner      = THIS_MODULE;
    3.77 -                new_dom_id->nlink      = 1;
    3.78 -                new_dom_id->proc_fops  = &newdom_data_fops; 
    3.79 -                new_dom_id->data       = (void *)params; 
    3.80 -            }
    3.81 -        }
    3.82      }
    3.83      
    3.84 - out:
    3.85      return ret;   
    3.86  }
    3.87  
    3.88 @@ -384,7 +372,7 @@ static int xeno_domains_show(struct seq_
    3.89                  di -> u.getdominfo.state,
    3.90                  di -> u.getdominfo.hyp_events,
    3.91                  di -> u.getdominfo.mcu_advance,
    3.92 -                di -> u.getdominfo.pg_head,
    3.93 +                (void *)di -> u.getdominfo.pg_head,
    3.94                  di -> u.getdominfo.tot_pages,
    3.95                  di -> u.getdominfo.name);
    3.96  
    3.97 @@ -410,9 +398,70 @@ static struct file_operations proc_xeno_
    3.98      release:        seq_release,
    3.99  };
   3.100  
   3.101 +static int handle_dom0_cmd_createdomain(unsigned long data)
   3.102 +{
   3.103 +  struct dom0_createdomain_args argbuf;
   3.104 +  int namelen;
   3.105 +  dom0_op_t op;
   3.106 +  int ret;
   3.107 +
   3.108 +  if (copy_from_user(&argbuf, (void *)data, sizeof(argbuf))) {
   3.109 +    printk("fault getting argbuf.\n");
   3.110 +    return -EFAULT;
   3.111 +  }
   3.112 +
   3.113 +  op.cmd = DOM0_CREATEDOMAIN;
   3.114 +  op.u.newdomain.domain = -666;
   3.115 +  op.u.newdomain.memory_kb = argbuf.kb_mem;
   3.116 +  op.u.newdomain.num_vifs = 0; /* Not used anymore, I hope... */
   3.117 +  namelen = strnlen_user(argbuf.name, MAX_DOMAIN_NAME);
   3.118 +  if (copy_from_user(op.u.newdomain.name, argbuf.name, namelen + 1)) {
   3.119 +    printk("Fault getting domain name\n");
   3.120 +    return -EFAULT;
   3.121 +  }
   3.122 +
   3.123 +  /* Error checking?  The old code deosn't appear to do any, and I
   3.124 +     can't see where the return values are documented... */
   3.125 +  ret = HYPERVISOR_dom0_op(&op);
   3.126 +
   3.127 +  if (op.u.newdomain.domain == -666) {
   3.128 +    /* HACK: We use this to detect whether the create actually
   3.129 +       succeeded, because Xen doesn't appear to want to tell us... */
   3.130 +
   3.131 +    /* The only time I've actually got this to happen was when trying
   3.132 +       to crate a domain with more memory than is actually in the
   3.133 +       machine, so we guess the error code is ENOMEM. */
   3.134 +    return -ENOMEM;
   3.135 +  }
   3.136 +
   3.137 +  /* Create proc entries */
   3.138 +  ret = op.u.newdomain.domain;
   3.139 +  create_proc_dom_entries(ret);
   3.140 +
   3.141 +  return ret;
   3.142 +}
   3.143 +
   3.144 +static int dom0_cmd_ioctl(struct inode *inode, struct file *file,
   3.145 +			  unsigned int cmd, unsigned long data)
   3.146 +{
   3.147 +  printk("dom0_cmd ioctl command %x\n", cmd);
   3.148 +  switch (cmd) {
   3.149 +  case IOCTL_DOM0_CREATEDOMAIN:
   3.150 +    return handle_dom0_cmd_createdomain(data);
   3.151 +  default:
   3.152 +    printk("Unknown dom0_cmd ioctl!\n");
   3.153 +    return -EINVAL;
   3.154 +  }
   3.155 +}
   3.156 +
   3.157  /***********************************************************************/
   3.158  
   3.159  
   3.160 +static struct file_operations dom0_cmd_file_ops = {
   3.161 +  read : dom0_cmd_read,
   3.162 +  write : dom0_cmd_write,
   3.163 +  ioctl : dom0_cmd_ioctl
   3.164 +};
   3.165  
   3.166  static int __init init_module(void)
   3.167  {
   3.168 @@ -422,12 +471,12 @@ static int __init init_module(void)
   3.169      /* xeno control interface */
   3.170      *readbuf = '\0';
   3.171      dom0_cmd_intf = create_proc_entry("dom0_cmd", 0600, xeno_base);
   3.172 +
   3.173      if ( dom0_cmd_intf != NULL )
   3.174      {
   3.175          dom0_cmd_intf->owner      = THIS_MODULE;
   3.176          dom0_cmd_intf->nlink      = 1;
   3.177 -        dom0_cmd_intf->read_proc  = cmd_read_proc;
   3.178 -        dom0_cmd_intf->write_proc = cmd_write_proc;
   3.179 +	dom0_cmd_intf->proc_fops  = &dom0_cmd_file_ops;
   3.180      }
   3.181  
   3.182      /* domain list interface */