From: Stefan Berger Subject: [PATCH] [Xen-API] [2/3] Extension of the Xen-API for managing the ACM policy (and others) Date: Tue, 08 May 2007 09:47:20 -0400 Message-ID: <1178632040.4294.10.camel@gsal-3.watson.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-LPtpDdpZmMfqffvwo6K3" 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 Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org --=-LPtpDdpZmMfqffvwo6K3 Content-Type: text/plain Content-Transfer-Encoding: 7bit This patch provides an interface for using recently-added Xen functionality from python. Signed-off-by: Stefan Berger --=-LPtpDdpZmMfqffvwo6K3 Content-Disposition: attachment; filename=xend-xspolicy-xapi-if.diff Content-Type: text/x-patch; name=xend-xspolicy-xapi-if.diff; charset=utf-8 Content-Transfer-Encoding: 7bit --- xen-unstable.hg/tools/python/xen/lowlevel/acm/acm.c | 114 +++++++++++++++++++- 1 file changed, 111 insertions(+), 3 deletions(-) Index: root/xen-unstable.hg/tools/python/xen/lowlevel/acm/acm.c =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/lowlevel/acm/acm.c +++ root/xen-unstable.hg/tools/python/xen/lowlevel/acm/acm.c @@ -1,10 +1,11 @@ /**************************************************************** * acm.c * - * Copyright (C) 2006 IBM Corporation + * Copyright (C) 2006,2007 IBM Corporation * * Authors: * Reiner Sailer + * Stefan Berger * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -197,13 +198,120 @@ static PyObject *getdecision(PyObject * return Py_BuildValue("s", decision); } +/* error messages for exceptions */ +const char bad_arg[] = "Bad function argument."; +const char ctrlif_op[] = "Could not open control interface."; +const char hv_op_err[] = "Error from hypervisor operation."; + + +static PyObject *chgpolicy(PyObject *self, PyObject *args) +{ + struct acm_change_policy chgpolicy; + int xc_handle, rc; + char *bin_pol = NULL, *del_arr = NULL, *chg_arr = NULL; + int bin_pol_len = 0, del_arr_len = 0, chg_arr_len = 0; + uint errarray_mbrs = 20 * 2; + uint32_t error_array[errarray_mbrs]; + PyObject *result; + uint len; + + memset(&chgpolicy, 0x0, sizeof(chgpolicy)); + + if (!PyArg_ParseTuple(args, "s#s#s#" ,&bin_pol, &bin_pol_len, + &del_arr, &del_arr_len, + &chg_arr, &chg_arr_len)) { + PyErr_SetString(PyExc_TypeError, bad_arg); + return NULL; + } + + chgpolicy.policy_pushcache_size = bin_pol_len; + chgpolicy.delarray_size = del_arr_len; + chgpolicy.chgarray_size = chg_arr_len; + chgpolicy.errarray_size = sizeof(error_array); + + set_xen_guest_handle(chgpolicy.policy_pushcache, bin_pol); + set_xen_guest_handle(chgpolicy.del_array, del_arr); + set_xen_guest_handle(chgpolicy.chg_array, chg_arr); + set_xen_guest_handle(chgpolicy.err_array, error_array); + + if ((xc_handle = xc_interface_open()) <= 0) { + PyErr_SetString(PyExc_IOError, ctrlif_op); + return NULL; + } + + rc = xc_acm_op(xc_handle, ACMOP_chgpolicy, &chgpolicy, sizeof(chgpolicy)); + + xc_interface_close(xc_handle); + + /* only pass the filled error codes */ + for (len = 0; (len + 1) < errarray_mbrs; len += 2) { + if (error_array[len] == 0) { + len *= sizeof(error_array[0]); + break; + } + } + + result = Py_BuildValue("is#", rc, error_array, len); + return result; +} + + +static PyObject *relabel_domains(PyObject *self, PyObject *args) +{ + struct acm_relabel_doms reldoms; + int xc_handle, rc; + char *relabel_rules = NULL; + int rel_rules_len = 0; + uint errarray_mbrs = 20 * 2; + uint32_t error_array[errarray_mbrs]; + PyObject *result; + uint len; + + memset(&reldoms, 0x0, sizeof(reldoms)); + + if (!PyArg_ParseTuple(args, "s#" ,&relabel_rules, &rel_rules_len)) { + PyErr_SetString(PyExc_TypeError, bad_arg); + return NULL; + } + + reldoms.relabel_map_size = rel_rules_len; + reldoms.errarray_size = sizeof(error_array); + + set_xen_guest_handle(reldoms.relabel_map, relabel_rules); + set_xen_guest_handle(reldoms.err_array, error_array); + + if ((xc_handle = xc_interface_open()) <= 0) { + PyErr_SetString(PyExc_IOError, ctrlif_op); + return NULL; + } + + rc = xc_acm_op(xc_handle, ACMOP_relabeldoms, &reldoms, sizeof(reldoms)); + + xc_interface_close(xc_handle); + + + /* only pass the filled error codes */ + for (len = 0; (len + 1) < errarray_mbrs; len += 2) { + if (error_array[len] == 0) { + len *= sizeof(error_array[0]); + break; + } + } + + result = Py_BuildValue("is#", rc, error_array, len); + return result; +} + + /*=================General Python Extension Declarations=================*/ /* methods */ static PyMethodDef acmMethods[] = { - {"policy", policy, METH_VARARGS, "Retrieve Active ACM Policy Reference Name"}, - {"getssid", getssid, METH_VARARGS, "Retrieve label information and ssidref for a domain"}, + {"policy", policy, METH_VARARGS, "Retrieve Active ACM Policy Reference Name"}, + {"getssid", getssid, METH_VARARGS, "Retrieve label information and ssidref for a domain"}, {"getdecision", getdecision, METH_VARARGS, "Retrieve ACM access control decision"}, + {"chgpolicy", chgpolicy, METH_VARARGS, "Change the policy in one step"}, + {"relabel_domains", relabel_domains, METH_VARARGS, "Relabel domains"}, /* end of list (extend list above this line) */ {NULL, NULL, 0, NULL} }; --=-LPtpDdpZmMfqffvwo6K3 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 --=-LPtpDdpZmMfqffvwo6K3--