ia64/xen-unstable

changeset 2983:9edb3993dabc

bitkeeper revision 1.1159.170.26 (41994c77d7MyAnUlSeibYJqQo1ADCA)

Clean up write interface for balloon proc file somewhat.
author mwilli2@equilibrium.research
date Tue Nov 16 00:40:23 2004 +0000 (2004-11-16)
parents b49a4a760280
children 0cf9476c362d
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	Mon Nov 15 15:33:15 2004 +0000
     1.2 +++ b/linux-2.6.9-xen-sparse/drivers/xen/balloon/balloon.c	Tue Nov 16 00:40:23 2004 +0000
     1.3 @@ -534,10 +534,13 @@ static void balloon_ctrlif_rx(ctrl_msg_t
     1.4      ctrl_if_send_response(msg);
     1.5  }
     1.6  
     1.7 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
     1.8 +typedef size_t count_t;
     1.9 +#else
    1.10 +typedef u_long count_t;
    1.11 +#endif
    1.12  
    1.13 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    1.14 -static int balloon_write(struct file *file, const char *buffer,
    1.15 -                         size_t count, loff_t *offp)
    1.16 +static int do_balloon_write(const char *buffer, count_t count)
    1.17  {
    1.18      char memstring[64], *endchar;
    1.19      int len, i;
    1.20 @@ -571,6 +574,17 @@ static int balloon_write(struct file *fi
    1.21  
    1.22      if ( i <= 0 ) return i;
    1.23  
    1.24 +    return len;
    1.25 +}
    1.26 +
    1.27 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    1.28 +static int balloon_write(struct file *file, const char *buffer,
    1.29 +                         size_t count, loff_t *offp)
    1.30 +{
    1.31 +    int len = do_balloon_write(buffer, count);
    1.32 +    
    1.33 +    if ( len <= 0 ) return len;
    1.34 +
    1.35      *offp += len;
    1.36      return len;
    1.37  }
    1.38 @@ -605,71 +619,7 @@ static struct file_operations balloon_fo
    1.39  static int balloon_write(struct file *file, const char *buffer,
    1.40                           u_long count, void *data)
    1.41  {
    1.42 -    char memstring[64], *endchar;
    1.43 -    int len, i;
    1.44 -    unsigned long target;
    1.45 -    unsigned long long targetbytes;
    1.46 -
    1.47 -    /* Only admin can play with the balloon :) */
    1.48 -    if ( !capable(CAP_SYS_ADMIN) )
    1.49 -        return -EPERM;
    1.50 -
    1.51 -    if ( count > sizeof(memstring) )
    1.52 -        return -EFBIG;
    1.53 -
    1.54 -    len = strnlen_user(buffer, count);
    1.55 -    if ( len == 0 ) return -EBADMSG;
    1.56 -    if ( len == 1 ) return 1; /* input starts with a NUL char */
    1.57 -    if ( strncpy_from_user(memstring, buffer, len) < 0 )
    1.58 -        return -EFAULT;
    1.59 -
    1.60 -    endchar = memstring;
    1.61 -    for ( i = 0; i < len; ++i, ++endchar )
    1.62 -        if ( (memstring[i] < '0') || (memstring[i] > '9') )
    1.63 -            break;
    1.64 -    if ( i == 0 )
    1.65 -        return -EBADMSG;
    1.66 -
    1.67 -    targetbytes = memparse(memstring,&endchar);
    1.68 -    target = targetbytes >> PAGE_SHIFT;
    1.69 -
    1.70 -    if ( target < current_pages )
    1.71 -    {
    1.72 -        int change = inflate_balloon(current_pages-target);
    1.73 -        if ( change <= 0 )
    1.74 -            return change;
    1.75 -
    1.76 -        current_pages -= change;
    1.77 -        printk(KERN_INFO "Relinquish %dMB to xen. Domain now has %luMB\n",
    1.78 -            change>>PAGE_TO_MB_SHIFT, current_pages>>PAGE_TO_MB_SHIFT);
    1.79 -    }
    1.80 -    else if ( target > current_pages )
    1.81 -    {
    1.82 -        int change, reclaim = min(target,most_seen_pages) - current_pages;
    1.83 -
    1.84 -        if ( reclaim )
    1.85 -        {
    1.86 -            change = deflate_balloon( reclaim);
    1.87 -            if ( change <= 0 )
    1.88 -                return change;
    1.89 -            current_pages += change;
    1.90 -            printk(KERN_INFO "Reclaim %dMB from xen. Domain now has %luMB\n",
    1.91 -                change>>PAGE_TO_MB_SHIFT, current_pages>>PAGE_TO_MB_SHIFT);
    1.92 -        }
    1.93 -
    1.94 -        if ( most_seen_pages < target )
    1.95 -        {
    1.96 -            int growth = claim_new_pages(target-most_seen_pages);
    1.97 -            if ( growth <= 0 )
    1.98 -                return growth;
    1.99 -            most_seen_pages += growth;
   1.100 -            current_pages += growth;
   1.101 -            printk(KERN_INFO "Granted %dMB new mem. Dom now has %luMB\n",
   1.102 -                growth>>PAGE_TO_MB_SHIFT, current_pages>>PAGE_TO_MB_SHIFT);
   1.103 -        }
   1.104 -    }
   1.105 -
   1.106 -    return len;
   1.107 +    return do_balloon_write(buffer, count);
   1.108  }
   1.109  
   1.110  static int balloon_read(char *page, char **start, off_t off,