ia64/xen-unstable

changeset 3246:fc7b350be00f

bitkeeper revision 1.1159.183.45 (41af85fcTJCRQfTCqQfiHwslOD_f3Q)

Merge scramble.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xen-2.0-testing.bk
into scramble.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xen-unstable.bk
author kaf24@scramble.cl.cam.ac.uk
date Thu Dec 02 21:15:40 2004 +0000 (2004-12-02)
parents 204dcd674164 0e6cf5ea9f5c
children fff7508e0e56
files linux-2.6.9-xen-sparse/drivers/xen/balloon/balloon.c
line diff
     1.1 --- a/linux-2.6.9-xen-sparse/drivers/xen/balloon/balloon.c	Thu Dec 02 17:03:57 2004 +0000
     1.2 +++ b/linux-2.6.9-xen-sparse/drivers/xen/balloon/balloon.c	Thu Dec 02 21:15:40 2004 +0000
     1.3 @@ -91,7 +91,7 @@ static struct timer_list balloon_timer;
     1.4  #define LIST_TO_PAGE(l) ( list_entry(l, struct page, list) )
     1.5  #define UNLIST_PAGE(p)  ( list_del(&p->list) )
     1.6  #define pte_offset_kernel pte_offset
     1.7 -#define subsys_initcall(_fn) __initcall(fn)
     1.8 +#define subsys_initcall(_fn) __initcall(_fn)
     1.9  #endif
    1.10  
    1.11  #define IPRINTK(fmt, args...) \
    1.12 @@ -300,14 +300,14 @@ static void balloon_ctrlif_rx(ctrl_msg_t
    1.13      switch ( msg->subtype )
    1.14      {
    1.15      case CMSG_MEM_REQUEST_SET:
    1.16 +    {
    1.17 +        mem_request_t *req = (mem_request_t *)&msg->msg[0];
    1.18          if ( msg->length != sizeof(mem_request_t) )
    1.19              goto parse_error;
    1.20 -        {
    1.21 -            mem_request_t *req = (mem_request_t *)&msg->msg[0];
    1.22 -            set_new_target(req->target);
    1.23 -            req->status = 0;
    1.24 -        }
    1.25 -        break;        
    1.26 +        set_new_target(req->target);
    1.27 +        req->status = 0;
    1.28 +    }
    1.29 +    break;        
    1.30      default:
    1.31          goto parse_error;
    1.32      }
    1.33 @@ -320,93 +320,59 @@ static void balloon_ctrlif_rx(ctrl_msg_t
    1.34      ctrl_if_send_response(msg);
    1.35  }
    1.36  
    1.37 -static int balloon_write(struct file *file, const char *buffer,
    1.38 -                         size_t count, loff_t *offp)
    1.39 +static int balloon_write(struct file *file, const char __user *buffer,
    1.40 +                         unsigned long count, void *data)
    1.41  {
    1.42      char memstring[64], *endchar;
    1.43 -    int len, i;
    1.44      unsigned long long target_bytes;
    1.45  
    1.46      if ( !capable(CAP_SYS_ADMIN) )
    1.47          return -EPERM;
    1.48  
    1.49 +    if ( count <= 1 )
    1.50 +        return -EBADMSG; /* runt */
    1.51      if ( count > sizeof(memstring) )
    1.52 -        return -EFBIG;
    1.53 +        return -EFBIG;   /* too long */
    1.54  
    1.55 -    len = strnlen_user(buffer, count);
    1.56 -    if ( len == 0 )
    1.57 -        return -EBADMSG;
    1.58 -    if ( len == 1 )
    1.59 -        goto out; /* input starts with a NUL char */
    1.60 -    if ( strncpy_from_user(memstring, buffer, len) < 0 )
    1.61 +    if ( copy_from_user(memstring, buffer, count) )
    1.62          return -EFAULT;
    1.63 +    memstring[sizeof(memstring)-1] = '\0';
    1.64  
    1.65 -    endchar = memstring;
    1.66 -    for ( i = 0; i < len; ++i, ++endchar )
    1.67 -        if ( (memstring[i] < '0') || (memstring[i] > '9') )
    1.68 -            break;
    1.69 -    if ( i == 0 )
    1.70 -        return -EBADMSG;
    1.71 -
    1.72 -    target_bytes = memparse(memstring,&endchar);
    1.73 +    target_bytes = memparse(memstring, &endchar);
    1.74      set_new_target(target_bytes >> PAGE_SHIFT);
    1.75  
    1.76 - out:
    1.77 -    *offp += len;
    1.78 -    return len;
    1.79 +    return count;
    1.80  }
    1.81  
    1.82 -static int balloon_read(struct file *filp, char *buffer,
    1.83 -                        size_t count, loff_t *offp)
    1.84 +static int balloon_read(char *page, char **start, off_t off,
    1.85 +                        int count, int *eof, void *data)
    1.86  {
    1.87 -    char *priv_buf;
    1.88      int len;
    1.89  
    1.90 -    priv_buf = (char *)__get_free_page(GFP_KERNEL);
    1.91 -    if ( priv_buf == NULL )
    1.92 -        return -ENOMEM;
    1.93 -
    1.94  #define K(_p) ((_p)<<(PAGE_SHIFT-10))
    1.95      len = sprintf(
    1.96 -        priv_buf,
    1.97 +        page,
    1.98          "Current allocation: %8lu kB\n"
    1.99 -        "Target allocation:  %8lu kB / %8lu kB (actual / requested)\n"
   1.100 -        "Unused heap space:  %8lu kB / %8lu kB (low-mem / high-mem)\n"
   1.101 +        "Requested target:   %8lu kB\n"
   1.102 +        "Low-mem balloon:    %8lu kB\n"
   1.103 +        "High-mem balloon:   %8lu kB\n"
   1.104          "Xen hard limit:     ",
   1.105 -        K(current_pages),
   1.106 -        K(current_target()), K(target_pages),
   1.107 -        K(balloon_low), K(balloon_high));
   1.108 +        K(current_pages), K(target_pages), K(balloon_low), K(balloon_high));
   1.109  
   1.110      if ( hard_limit != ~0UL )
   1.111          len += sprintf(
   1.112 -            priv_buf + len, 
   1.113 +            page + len, 
   1.114              "%8lu kB (inc. %8lu kB driver headroom)\n",
   1.115              K(hard_limit), K(driver_pages));
   1.116      else
   1.117          len += sprintf(
   1.118 -            priv_buf + len,
   1.119 +            page + len,
   1.120              "     ??? kB\n");
   1.121  
   1.122 -    len -= *offp;
   1.123 -    if ( len > count)
   1.124 -        len = count;
   1.125 -    if ( len < 0 )
   1.126 -        len = 0;
   1.127 -
   1.128 -    if ( len != 0 )
   1.129 -        (void)copy_to_user(buffer, &priv_buf[*offp], len);
   1.130 -
   1.131 -    free_page((unsigned long)priv_buf);
   1.132 -
   1.133 -    *offp += len;
   1.134 +    *eof = 1;
   1.135      return len;
   1.136  }
   1.137  
   1.138 -static struct file_operations balloon_fops = {
   1.139 -    .read  = balloon_read,
   1.140 -    .write = balloon_write
   1.141 -};
   1.142 -
   1.143  static int __init balloon_init(void)
   1.144  {
   1.145      unsigned long pfn;
   1.146 @@ -431,7 +397,8 @@ static int __init balloon_init(void)
   1.147          return -1;
   1.148      }
   1.149  
   1.150 -    balloon_pde->proc_fops = &balloon_fops;
   1.151 +    balloon_pde->read_proc  = balloon_read;
   1.152 +    balloon_pde->write_proc = balloon_write;
   1.153  
   1.154      (void)ctrl_if_register_receiver(CMSG_MEM_REQUEST, balloon_ctrlif_rx, 0);
   1.155