ia64/xen-unstable

changeset 3244:150e98023e13

bitkeeper revision 1.1159.187.55 (41af81710ePtgtFPsGTTUHYqD1qviA)

Simpler balloon proc entry.
author kaf24@scramble.cl.cam.ac.uk
date Thu Dec 02 20:56:17 2004 +0000 (2004-12-02)
parents 199e9c5ef609
children 0e6cf5ea9f5c
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:09 2004 +0000
     1.2 +++ b/linux-2.6.9-xen-sparse/drivers/xen/balloon/balloon.c	Thu Dec 02 20:56:17 2004 +0000
     1.3 @@ -320,55 +320,38 @@ static void balloon_ctrlif_rx(ctrl_msg_t
     1.4      ctrl_if_send_response(msg);
     1.5  }
     1.6  
     1.7 -static int balloon_write(struct file *file, const char *buffer,
     1.8 -                         size_t count, loff_t *offp)
     1.9 +static int balloon_write(struct file *file, const char __user *buffer,
    1.10 +                         unsigned long count, void *data)
    1.11  {
    1.12      char memstring[64], *endchar;
    1.13 -    int len, i;
    1.14      unsigned long long target_bytes;
    1.15  
    1.16      if ( !capable(CAP_SYS_ADMIN) )
    1.17          return -EPERM;
    1.18  
    1.19 +    if ( count <= 1 )
    1.20 +        return -EBADMSG; /* runt */
    1.21      if ( count > sizeof(memstring) )
    1.22 -        return -EFBIG;
    1.23 +        return -EFBIG;   /* too long */
    1.24  
    1.25 -    len = strnlen_user(buffer, count);
    1.26 -    if ( len == 0 )
    1.27 -        return -EBADMSG;
    1.28 -    if ( len == 1 )
    1.29 -        goto out; /* input starts with a NUL char */
    1.30 -    if ( strncpy_from_user(memstring, buffer, len) < 0 )
    1.31 +    if ( copy_from_user(memstring, buffer, count) )
    1.32          return -EFAULT;
    1.33 +    memstring[sizeof(memstring)-1] = '\0';
    1.34  
    1.35 -    endchar = memstring;
    1.36 -    for ( i = 0; i < len; ++i, ++endchar )
    1.37 -        if ( (memstring[i] < '0') || (memstring[i] > '9') )
    1.38 -            break;
    1.39 -    if ( i == 0 )
    1.40 -        return -EBADMSG;
    1.41 -
    1.42 -    target_bytes = memparse(memstring,&endchar);
    1.43 +    target_bytes = memparse(memstring, &endchar);
    1.44      set_new_target(target_bytes >> PAGE_SHIFT);
    1.45  
    1.46 - out:
    1.47 -    *offp += len;
    1.48 -    return len;
    1.49 +    return count;
    1.50  }
    1.51  
    1.52 -static int balloon_read(struct file *filp, char *buffer,
    1.53 -                        size_t count, loff_t *offp)
    1.54 +static int balloon_read(char *page, char **start, off_t off,
    1.55 +                        int count, int *eof, void *data)
    1.56  {
    1.57 -    char *priv_buf;
    1.58      int len;
    1.59  
    1.60 -    priv_buf = (char *)__get_free_page(GFP_KERNEL);
    1.61 -    if ( priv_buf == NULL )
    1.62 -        return -ENOMEM;
    1.63 -
    1.64  #define K(_p) ((_p)<<(PAGE_SHIFT-10))
    1.65      len = sprintf(
    1.66 -        priv_buf,
    1.67 +        page,
    1.68          "Current allocation: %8lu kB\n"
    1.69          "Target allocation:  %8lu kB / %8lu kB (actual / requested)\n"
    1.70          "Unused heap space:  %8lu kB / %8lu kB (low-mem / high-mem)\n"
    1.71 @@ -379,34 +362,18 @@ static int balloon_read(struct file *fil
    1.72  
    1.73      if ( hard_limit != ~0UL )
    1.74          len += sprintf(
    1.75 -            priv_buf + len, 
    1.76 +            page + len, 
    1.77              "%8lu kB (inc. %8lu kB driver headroom)\n",
    1.78              K(hard_limit), K(driver_pages));
    1.79      else
    1.80          len += sprintf(
    1.81 -            priv_buf + len,
    1.82 +            page + len,
    1.83              "     ??? kB\n");
    1.84  
    1.85 -    len -= *offp;
    1.86 -    if ( len > count)
    1.87 -        len = count;
    1.88 -    if ( len < 0 )
    1.89 -        len = 0;
    1.90 -
    1.91 -    if ( len != 0 )
    1.92 -        (void)copy_to_user(buffer, &priv_buf[*offp], len);
    1.93 -
    1.94 -    free_page((unsigned long)priv_buf);
    1.95 -
    1.96 -    *offp += len;
    1.97 +    *eof = 1;
    1.98      return len;
    1.99  }
   1.100  
   1.101 -static struct file_operations balloon_fops = {
   1.102 -    .read  = balloon_read,
   1.103 -    .write = balloon_write
   1.104 -};
   1.105 -
   1.106  static int __init balloon_init(void)
   1.107  {
   1.108      unsigned long pfn;
   1.109 @@ -431,7 +398,8 @@ static int __init balloon_init(void)
   1.110          return -1;
   1.111      }
   1.112  
   1.113 -    balloon_pde->proc_fops = &balloon_fops;
   1.114 +    balloon_pde->read_proc  = balloon_read;
   1.115 +    balloon_pde->write_proc = balloon_write;
   1.116  
   1.117      (void)ctrl_if_register_receiver(CMSG_MEM_REQUEST, balloon_ctrlif_rx, 0);
   1.118