From: "Satoshi Uchida" Subject: [PATCH][Take 2] Sysfs Interface for balloon driver Date: Mon, 25 Sep 2006 20:51:39 +0900 Message-ID: <002601c6e098$f632c110$4c87380a@ad.spf.cl.nec.co.jp> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0027_01C6E0E4.661A6910" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. ------=_NextPart_000_0027_01C6E0E4.661A6910 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi. This patch provides a sysfs interface for the balloon driver (Take 2). Currently, the interface for the balloon driver is provided by procfs. However, I was suggested by Kier and Anthony that procfs should handle only process information and other information should be located in = sysfs, when I made the interface for virtual block devices. The information for the balloon driver also should be moved to sysfs. So, I have made a sysfs interface for the balloon driver. The information for balloon driver is placed in = /sys/devices/system/memory/. Example outputs of the sysfs interface of the balloon driver are as = follows: Example 1. Show each information [root@Dom0 ~]# ls /sys/devices/system/memory/memory0/ balloon_high current_pages hard_limit balloon_low driver_pages target_pages [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/current_pages=20 262144 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/target_pages=20 262144 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/balloon_high=20 0 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/balloon_low=20 509952 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/hard_limit=20 ???=20 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/driver_pages=20 1024 Example 2. Set memory size of a domain [root@Dom0 ~]# echo 1024M > = /sys/devices/system/memory/memory0/target_pages=20 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/target_pages=20 1048576 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/current_pages=20 758192 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/hard_limit=20 758192 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/driver_pages=20 1024 Regards Satoshi UCHIDA=20 NEC Corporation, Japan ------=_NextPart_000_0027_01C6E0E4.661A6910 Content-Type: application/octet-stream; name="balloon_sysfs.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="balloon_sysfs.patch" # HG changeset patch=0A= # User root@noir.spf.cl.nec.co.jp=0A= # Node ID 381fa5366f71bd2762290f5506d1d67be25519aa=0A= # Parent c4f3f719d997522ae82e065d4f93d5af6494a750=0A= [Balloon]Add sysfs interface.=0A= =0A= This patch provides sysfs interface for balloon driver.=0A= Information is located under /sys/devices/system/memory.=0A= =0A= Signed-off-by: Satoshi UCHIDA =0A= =0A= diff -r c4f3f719d997 -r 381fa5366f71 = linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c=0A= --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c Sat Sep 23 = 14:54:58 2006 +0100=0A= +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c Mon Sep 25 = 20:40:30 2006 +0900=0A= @@ -53,6 +53,7 @@=0A= #include =0A= #include =0A= #include =0A= +#include =0A= =0A= #include =0A= =0A= @@ -456,6 +457,116 @@ static int balloon_read(char *page, char=0A= }=0A= #endif=0A= =0A= +/*****************************************************=0A= + * sysfs interface for balloon driver.=0A= + */=0A= +=0A= +#define BALLOON_CLASS_NAME "memory"=0A= +=0A= +struct balloon {=0A= + struct sys_device sysdev;=0A= +};=0A= +=0A= +#define to_balloon(sys_device) container_of(sys_device, struct balloon, = sysdev)=0A= +=0A= +#define BALLOON_SHOW(name, format, args...) \=0A= + static ssize_t show_##name(struct sys_device *dev, \=0A= + char *buf) \=0A= + { \=0A= + return sprintf(buf, format, ##args); \=0A= + } \=0A= + static SYSDEV_ATTR(name, S_IRUGO, show_##name, NULL)=0A= +=0A= +BALLOON_SHOW(current_pages, "%8lu\n", PAGES2KB(current_pages));=0A= +BALLOON_SHOW(balloon_low, "%8lu\n", PAGES2KB(balloon_low));=0A= +BALLOON_SHOW(balloon_high, "%8lu\n", PAGES2KB(balloon_high));=0A= +BALLOON_SHOW(hard_limit,=0A= + (hard_limit!=3D~0UL)?"%8lu\n":"???\n" ,=0A= + (hard_limit!=3D~0UL)?PAGES2KB(hard_limit):0);=0A= +BALLOON_SHOW(driver_pages, "%8lu\n", PAGES2KB(driver_pages));=0A= +=0A= +static ssize_t show_target_pages(struct sys_device *dev, =0A= + char *buf)=0A= +{ =0A= + return sprintf(buf, "%8lu\n", PAGES2KB(target_pages)); =0A= +} =0A= +=0A= +static ssize_t store_target_pages(struct sys_device *dev,=0A= + const char *buf,=0A= + size_t count)=0A= +{=0A= + char memstring[64], *endchar;=0A= + unsigned long long target_bytes;=0A= +=0A= + if (!capable(CAP_SYS_ADMIN))=0A= + return -EPERM;=0A= + =0A= + if (count <=3D 1)=0A= + return -EBADMSG; /* runt */=0A= + if (count > sizeof(memstring))=0A= + return -EFBIG; /* too long */=0A= + strcpy(memstring, buf);=0A= + =0A= + target_bytes =3D memparse(memstring, &endchar);=0A= + set_new_target(target_bytes >> PAGE_SHIFT);=0A= + =0A= + return count;=0A= +}=0A= +=0A= +static SYSDEV_ATTR(target_pages, S_IRUGO | S_IWUSR,=0A= + show_target_pages, store_target_pages);=0A= +=0A= +static struct sysdev_attribute *balloon_attrs[] =3D {=0A= + &attr_current_pages,=0A= + &attr_target_pages,=0A= + &attr_balloon_low,=0A= + &attr_balloon_high,=0A= + &attr_hard_limit,=0A= + &attr_driver_pages=0A= +};=0A= +=0A= +static struct sysdev_class balloon_sysdev_class =3D {=0A= + set_kset_name(BALLOON_CLASS_NAME),=0A= +};=0A= +=0A= +=0A= +static int register_balloon(struct balloon *bln)=0A= +{=0A= + int error;=0A= + int i;=0A= +=0A= + bln->sysdev.id =3D 0;=0A= + bln->sysdev.cls =3D &balloon_sysdev_class;=0A= + error =3D sysdev_register(&bln->sysdev);=0A= +=0A= + if (!error) {=0A= + for (i=3D0 ; i < ARRAY_SIZE(balloon_attrs) ; i++)=0A= + sysdev_create_file(&bln->sysdev, balloon_attrs[i]);=0A= + }=0A= + return error;=0A= +}=0A= +=0A= +static void unregister_balloon(struct balloon *bln)=0A= +{=0A= + int i;=0A= +=0A= + for (i=3D0 ; i < ARRAY_SIZE(balloon_attrs) ; i++)=0A= + sysdev_remove_file(&bln->sysdev, balloon_attrs[i]);=0A= + sysdev_unregister(&bln->sysdev);=0A= +}=0A= +=0A= +static int balloon_sysfs_init(void)=0A= +{=0A= + int ret =3D 0;=0A= + struct balloon *bln =3D kzalloc(sizeof(*bln), GFP_KERNEL);=0A= +=0A= + ret =3D sysdev_class_register(&balloon_sysdev_class);=0A= +=0A= + register_balloon(bln);=0A= +=0A= + return ret;=0A= +}=0A= +=0A= static struct notifier_block xenstore_notifier;=0A= =0A= static int __init balloon_init(void)=0A= @@ -489,6 +600,7 @@ static int __init balloon_init(void)=0A= balloon_pde->read_proc =3D balloon_read;=0A= balloon_pde->write_proc =3D balloon_write;=0A= #endif=0A= + balloon_sysfs_init();=0A= =0A= /* Initialise the balloon with excess memory space. */=0A= for (pfn =3D xen_start_info->nr_pages; pfn < max_pfn; pfn++) {=0A= ------=_NextPart_000_0027_01C6E0E4.661A6910 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel ------=_NextPart_000_0027_01C6E0E4.661A6910--