From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yosuke Iwamatsu Subject: [PATCH] XM on XenAPI: Enable 'xm pci-attach/detach' via XenAPI Date: Thu, 31 Jul 2008 21:13:48 +0900 Message-ID: <4891AC7C.4090604@ab.jp.nec.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030808030200010302050800" 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. --------------030808030200010302050800 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit This patch enables 'xm pci-attach/detach' commands to be executed via xen-api. Regards, ----------------------- Yosuke Iwamatsu NEC Corporation --------------030808030200010302050800 Content-Type: all/allfiles; name="xm_xenapi_pci_attach_detach.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="xm_xenapi_pci_attach_detach.patch" xm on xenapi: Enable 'xm pci-{att,det}ach' commands to be executed via xen-api. Signed-off-by: Yosuke Iwamatsu diff -r 21dd1fdb73d8 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Wed Jul 30 16:22:45 2008 +0100 +++ b/tools/python/xen/xm/main.py Thu Jul 31 17:57:29 2008 +0900 @@ -2418,7 +2418,34 @@ def xm_pci_attach(args): def xm_pci_attach(args): arg_check(args, 'pci-attach', 2, 3) (dom, pci) = parse_pci_configuration(args, 'Initialising') - server.xend.domain.device_configure(dom, pci) + + if serverType == SERVER_XEN_API: + + pci_dev = sxp.children(pci, 'dev')[0] + domain = int(sxp.child_value(pci_dev, 'domain'), 16) + bus = int(sxp.child_value(pci_dev, 'bus'), 16) + slot = int(sxp.child_value(pci_dev, 'slot'), 16) + func = int(sxp.child_value(pci_dev, 'func'), 16) + vslt = int(sxp.child_value(pci_dev, 'vslt'), 16) + name = "%04x:%02x:%02x.%01x" % (domain, bus, slot, func) + + target_ref = None + for ppci_ref in server.xenapi.PPCI.get_all(): + if name == server.xenapi.PPCI.get_name(ppci_ref): + target_ref = ppci_ref + break + if target_ref is None: + raise OptionError("Device %s not found" % name) + + dpci_record = { + "VM": get_single_vm(dom), + "PPCI": target_ref, + "hotplug_slot": vslt + } + server.xenapi.DPCI.create(dpci_record) + + else: + server.xend.domain.device_configure(dom, pci) def xm_scsi_attach(args): xenapi_unsupported() @@ -2518,7 +2545,29 @@ def xm_pci_detach(args): def xm_pci_detach(args): arg_check(args, 'pci-detach', 2) (dom, pci) = parse_pci_configuration(args, 'Closing') - server.xend.domain.device_configure(dom, pci) + + if serverType == SERVER_XEN_API: + + pci_dev = sxp.children(pci, 'dev')[0] + domain = int(sxp.child_value(pci_dev, 'domain'), 16) + bus = int(sxp.child_value(pci_dev, 'bus'), 16) + slot = int(sxp.child_value(pci_dev, 'slot'), 16) + func = int(sxp.child_value(pci_dev, 'func'), 16) + vslt = int(sxp.child_value(pci_dev, 'vslt'), 16) + name = "%04x:%02x:%02x.%01x" % (domain, bus, slot, func) + + target_ref = None + for dpci_ref in server.xenapi.VM.get_DPCIs(get_single_vm(dom)): + ppci_ref = server.xenapi.DPCI.get_PPCI(dpci_ref) + if name == server.xenapi.PPCI.get_name(ppci_ref): + target_ref = ppci_ref + server.xenapi.DPCI.destroy(dpci_ref) + break + if target_ref is None: + raise OptionError("Device %s not assigned" % name) + + else: + server.xend.domain.device_configure(dom, pci) def xm_scsi_detach(args): xenapi_unsupported() --------------030808030200010302050800 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 --------------030808030200010302050800--