From 923fc581e06dcb104c23121133e16dc1206d5820 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 4 Feb 2008 09:16:51 +0000 Subject: [PATCH] xen: Add /proc/xen/capabilities /proc/xen/capabilities is used by the xend init script to check whether it is running on Dom0. Signed-off-by: Mark McLoughlin --- drivers/xen/xenctrl/Makefile | 1 + drivers/xen/xenctrl/capabilities.c | 68 ++++++++++++++++++++++++++++++++++++ drivers/xen/xenctrl/main.c | 11 ++++++ drivers/xen/xenctrl/xenctrl.h | 39 ++++++++++++++++++++ 4 files changed, 119 insertions(+), 0 deletions(-) create mode 100644 drivers/xen/xenctrl/capabilities.c create mode 100644 drivers/xen/xenctrl/xenctrl.h diff --git a/drivers/xen/xenctrl/Makefile b/drivers/xen/xenctrl/Makefile index 1f43a43..631f535 100644 --- a/drivers/xen/xenctrl/Makefile +++ b/drivers/xen/xenctrl/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_XENCTRL) += xenctrl.o xenctrl-objs = xenctrl-objs += main.o +xenctrl-objs += capabilities.o diff --git a/drivers/xen/xenctrl/capabilities.c b/drivers/xen/xenctrl/capabilities.c new file mode 100644 index 0000000..1ff078a --- /dev/null +++ b/drivers/xen/xenctrl/capabilities.c @@ -0,0 +1,68 @@ +/****************************************************************************** + * + * capabilities.c + * + * /proc/xen/capabilities + * + * Copyright (c) 2002-2004, K A Fraser, B Dragovic + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include +#include + +static int capabilities_read(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = 0; + *page = 0; + + if (is_initial_xendomain()) + len = sprintf(page, "control_d\n"); + + *eof = 1; + return len; +} + +int __init capabilities_create_proc_entry(void) +{ + struct proc_dir_entry *entry; + + entry = create_proc_entry("xen/capabilities", 0400, NULL); + if (!entry) + return -ENOMEM; + + entry->owner = THIS_MODULE; + entry->read_proc = capabilities_read; + + return 0; +} + +void __exit capabilities_remove_proc_entry(void) +{ + remove_proc_entry("xen/capabilities", NULL); +} diff --git a/drivers/xen/xenctrl/main.c b/drivers/xen/xenctrl/main.c index 2965ceb..0e42f7e 100644 --- a/drivers/xen/xenctrl/main.c +++ b/drivers/xen/xenctrl/main.c @@ -31,6 +31,8 @@ * IN THE SOFTWARE. */ +#include "xenctrl.h" + #include #include #include @@ -38,6 +40,7 @@ static int __init xenctrl_init(void) { struct proc_dir_entry *dir; + int ret; if (!is_running_on_xen()) return -ENODEV; @@ -48,11 +51,19 @@ static int __init xenctrl_init(void) dir->owner = THIS_MODULE; + ret = capabilities_create_proc_entry(); + if (ret) + goto fail1; + return 0; + + fail1: remove_proc_entry("xen", NULL); + return ret; } static void __exit xenctrl_exit(void) { + capabilities_remove_proc_entry(); remove_proc_entry("xen", NULL); } diff --git a/drivers/xen/xenctrl/xenctrl.h b/drivers/xen/xenctrl/xenctrl.h new file mode 100644 index 0000000..7378dde --- /dev/null +++ b/drivers/xen/xenctrl/xenctrl.h @@ -0,0 +1,39 @@ +/****************************************************************************** + * xenctl.h + * + * Xen userspace control interfaces + * + * Copyright (c) 2002-2004, K A Fraser, B Dragovic + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +/* + * capabilities.c + */ +int capabilities_create_proc_entry(void) __init; +void capabilities_remove_proc_entry(void) __exit; -- 1.5.4.1