From: Mark Williamson Subject: [RFC] Xen paravirtual watchdog device [3/4] Date: Fri, 1 Jun 2007 04:50:07 +0100 Message-ID: <200706010450.08113.mark.williamson@cl.cam.ac.uk> References: <200706010444.29583.mark.williamson@cl.cam.ac.uk> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_wd5XGRJ0UHcGhlT" Return-path: In-Reply-To: <200706010444.29583.mark.williamson@cl.cam.ac.uk> 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 --Boundary-00=_wd5XGRJ0UHcGhlT Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Tools support for the virtual watchdog device. Currently, this is used to support some extra status information for the guest, which may be useful in some circumstances. The tools could usefully be extended to have more interaction with the watchdog for management purposes. Cheers, Mark -- Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel! --Boundary-00=_wd5XGRJ0UHcGhlT Content-Type: all/allfiles; name="watchdog3-tools.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="watchdog3-tools.patch" diff --exclude=.hg -rupN xen-incoming.hg/tools/libxc/xc_domain.c xen-watchdog-ref.hg/tools/libxc/xc_domain.c --- xen-incoming.hg/tools/libxc/xc_domain.c 2007-04-12 18:00:09.000000000 +0100 +++ xen-watchdog-ref.hg/tools/libxc/xc_domain.c 2007-06-01 04:23:03.000000000 +0100 @@ -9,6 +9,7 @@ #include "xc_private.h" #include #include +#include int xc_domain_create(int xc_handle, uint32_t ssidref, @@ -696,6 +697,53 @@ int xc_get_hvm_param(int handle, domid_t return rc; } + + + +int xc_query_watchdog(int xc_handle, uint32_t domid, + unsigned long *timeout, uint64_t *features, uint64_t *status) +{ + DECLARE_HYPERCALL; + xen_query_watchdog_op_t q_op; + int ret; + + hypercall.op = __HYPERVISOR_watchdog_op; + hypercall.arg[0] = XEN_WATCHDOG_CMD_QUERY; + hypercall.arg[1] = (unsigned long)&q_op; + + q_op.domid = domid; + + ret = do_xen_hypercall(xc_handle, &hypercall); + + if ( ret != 0 ) + return ret; + + *timeout = q_op.timeout; + *features = q_op.features; + *status = q_op.status; + + return 0; +} + +int xc_set_watchdog(int xc_handle, uint32_t domid, u64 status) +{ + DECLARE_HYPERCALL; + xen_set_watchdog_op_t s_op; + int ret; + + hypercall.op = __HYPERVISOR_watchdog_op; + hypercall.arg[0] = XEN_WATCHDOG_CMD_SET; + hypercall.arg[1] = (unsigned long)&s_op; + + s_op.domid = domid; + s_op.status = status; + + ret = do_xen_hypercall(xc_handle, &hypercall); + + return ret; +} + + /* * Local variables: * mode: C diff --exclude=.hg -rupN xen-incoming.hg/tools/libxc/xenctrl.h xen-watchdog-ref.hg/tools/libxc/xenctrl.h --- xen-incoming.hg/tools/libxc/xenctrl.h 2007-05-30 23:00:34.000000000 +0100 +++ xen-watchdog-ref.hg/tools/libxc/xenctrl.h 2007-06-01 04:23:03.000000000 +0100 @@ -29,6 +29,8 @@ #include #include +typedef uint64_t u64; /* MAW: this is a bit gross, anyone know a better way? */ + #ifdef __ia64__ #define XC_PAGE_SHIFT 14 #else @@ -528,6 +530,12 @@ int xc_domain_iomem_permission(int xc_ha unsigned long nr_mfns, uint8_t allow_access); +int xc_query_watchdog(int xc_handle, uint32_t domid, + unsigned long *timeout, uint64_t *features, + uint64_t *status); + +int xc_set_watchdog(int xc_handle, uint32_t domid, uint64_t status); + unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid, unsigned long mfn); diff --exclude=.hg -rupN xen-incoming.hg/tools/python/xen/lowlevel/xc/xc.c xen-watchdog-ref.hg/tools/python/xen/lowlevel/xc/xc.c --- xen-incoming.hg/tools/python/xen/lowlevel/xc/xc.c 2007-05-30 23:00:34.000000000 +0100 +++ xen-watchdog-ref.hg/tools/python/xen/lowlevel/xc/xc.c 2007-06-01 04:23:04.000000000 +0100 @@ -19,6 +19,7 @@ #include "xenctrl.h" #include +#include #include "xc_dom.h" #include #include @@ -1077,6 +1078,23 @@ static PyObject *pyxc_domain_send_trigge return zero; } +static PyObject *pyxc_domain_watchdog_set_lastboot(XcObject *self, PyObject *args) +{ + int bool; + uint32_t dom; + + if (!PyArg_ParseTuple(args, "ii", &dom, &bool)) + return NULL; + + if(xc_set_watchdog(self->xc_handle, dom, bool ? XEN_WATCHDOG_LASTBOOT : 0) != 0) + return pyxc_error_to_exception(); + + Py_INCREF(zero); + return zero; +} + + + static PyObject *pyxc_send_debug_keys(XcObject *self, PyObject *args, PyObject *kwds) @@ -1488,6 +1506,13 @@ static PyMethodDef pyxc_methods[] = { " trigger [int]: Trigger type number.\n" " vcpu [int]: VCPU to be sent trigger.\n" "Returns: [int] 0 on success; -1 on error.\n" }, + { "domain_watchdog_set_lastboot", + (PyCFunction)pyxc_domain_watchdog_set_lastboot, + METH_VARARGS | METH_KEYWORDS, "\n" + "Set a domain's lastboot watchdog flag\n" + " dom [int]: Domain whose watchdog flag is to be set\n" + " val [bool]: Whether the flag should be set true or false.\n" + "Returns: [int] 0 on success; -1 on error.\n"}, { "send_debug_keys", (PyCFunction)pyxc_send_debug_keys, diff --exclude=.hg -rupN xen-incoming.hg/tools/python/xen/xend/XendAPI.py xen-watchdog-ref.hg/tools/python/xen/xend/XendAPI.py --- xen-incoming.hg/tools/python/xen/xend/XendAPI.py 2007-05-17 20:00:11.000000000 +0100 +++ xen-watchdog-ref.hg/tools/python/xen/xend/XendAPI.py 2007-06-01 04:23:04.000000000 +0100 @@ -1161,6 +1161,7 @@ class XendAPI(object): 'actions_after_reboot', 'actions_after_suspend', 'actions_after_crash', + 'actions_after_watchdog', 'PV_bootloader', 'PV_kernel', 'PV_ramdisk', @@ -1221,6 +1222,7 @@ class XendAPI(object): 'actions_after_reboot', 'actions_after_suspend', 'actions_after_crash', + 'actions_after_watchdog', 'PV_bootloader', 'PV_kernel', 'PV_ramdisk', @@ -1338,6 +1340,10 @@ class XendAPI(object): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_on_crash()) + def VM_get_actions_after_watchdog(self, session, vm_ref): + dom = XendDomain.instance().get_vm_by_uuid(vm_ref) + return xen_api_success(dom.get_on_crash()) + def VM_get_PV_bootloader(self, session, vm_ref): return self.VM_get('PV_bootloader', session, vm_ref) @@ -1515,12 +1521,11 @@ class XendAPI(object): return self.VM_set('HVM_boot_params', session, vm_ref, value) def VM_add_to_HVM_boot_params(self, session, vm_ref, key, value): - dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'HVM_boot_params' not in dom.info: dom.info['HVM_boot_params'] = {} dom.info['HVM_boot_params'][key] = value return self._VM_save(dom) - + return xen_api_todo() def VM_remove_from_HVM_boot_params(self, session, vm_ref, key): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'HVM_boot_params' in dom.info \ @@ -1631,6 +1636,7 @@ class XendAPI(object): 'actions_after_reboot': xeninfo.get_on_reboot(), 'actions_after_suspend': xeninfo.get_on_suspend(), 'actions_after_crash': xeninfo.get_on_crash(), + 'actions_after_watchdog': xeninfo.get_on_watchdog(), 'consoles': xeninfo.get_consoles(), 'VIFs': xeninfo.get_vifs(), 'VBDs': xeninfo.get_vbds(), diff --exclude=.hg -rupN xen-incoming.hg/tools/python/xen/xend/XendConfig.py xen-watchdog-ref.hg/tools/python/xen/xend/XendConfig.py --- xen-incoming.hg/tools/python/xen/xend/XendConfig.py 2007-05-30 23:00:34.000000000 +0100 +++ xen-watchdog-ref.hg/tools/python/xen/xend/XendConfig.py 2007-06-01 04:23:04.000000000 +0100 @@ -110,6 +110,7 @@ XENAPI_CFG_TO_LEGACY_CFG = { 'actions_after_shutdown': 'on_poweroff', 'actions_after_reboot': 'on_reboot', 'actions_after_crash': 'on_crash', + 'actions_after_watchdog': 'on_watchdog', 'PV_bootloader': 'bootloader', 'PV_bootloader_args': 'bootloader_args', } @@ -146,6 +147,7 @@ XENAPI_CFG_TYPES = { 'actions_after_shutdown': str, 'actions_after_reboot': str, 'actions_after_crash': str, + 'actions_after_watchdog': str, 'PV_bootloader': str, 'PV_kernel': str, 'PV_ramdisk': str, @@ -201,6 +203,7 @@ LEGACY_CFG_TYPES = { 'on_poweroff': str, 'on_reboot': str, 'on_crash': str, + 'on_watchdog': str, 'on_xend_stop': str, 'on_xend_start': str, 'online_vcpus': int, @@ -223,6 +226,7 @@ LEGACY_XENSTORE_VM_PARAMS = [ 'on_poweroff', 'on_crash', 'on_reboot', + 'on_watchdog', 'on_xend_start', 'on_xend_stop', ] @@ -301,6 +305,7 @@ class XendConfig(dict): 'actions_after_crash': 'restart', 'actions_after_suspend': '', 'is_a_template': False, + 'actions_after_watchdog': 'restart', 'is_control_domain': False, 'features': '', 'PV_bootloader': '', @@ -464,11 +469,12 @@ class XendConfig(dict): cfg['on_poweroff'] = 'destroy' cfg['on_reboot'] = 'restart' cfg['on_crash'] = 'destroy' + cfg['on_watchdog'] = 'restart' elif restart == 'always': - for opt in ('on_poweroff', 'on_reboot', 'on_crash'): + for opt in ('on_poweroff', 'on_reboot', 'on_crash', 'on_watchdog'): cfg[opt] = 'restart' elif restart == 'never': - for opt in ('on_poweroff', 'on_reboot', 'on_crash'): + for opt in ('on_poweroff', 'on_reboot', 'on_crash', 'on_watchdog'): cfg[opt] = 'never' else: log.warn('Ignoring unrecognised value for deprecated option:' diff --exclude=.hg -rupN xen-incoming.hg/tools/python/xen/xend/XendConstants.py xen-watchdog-ref.hg/tools/python/xen/xend/XendConstants.py --- xen-incoming.hg/tools/python/xen/xend/XendConstants.py 2007-05-30 23:00:34.000000000 +0100 +++ xen-watchdog-ref.hg/tools/python/xen/xend/XendConstants.py 2007-06-01 04:23:04.000000000 +0100 @@ -26,13 +26,15 @@ DOMAIN_REBOOT = 1 DOMAIN_SUSPEND = 2 DOMAIN_CRASH = 3 DOMAIN_HALT = 4 +DOMAIN_WATCHDOG = 5 DOMAIN_SHUTDOWN_REASONS = { DOMAIN_POWEROFF: "poweroff", DOMAIN_REBOOT : "reboot", DOMAIN_SUSPEND : "suspend", DOMAIN_CRASH : "crash", - DOMAIN_HALT : "halt" + DOMAIN_HALT : "halt", + DOMAIN_WATCHDOG : "watchdog" } REVERSE_DOMAIN_SHUTDOWN_REASONS = \ dict([(y, x) for x, y in DOMAIN_SHUTDOWN_REASONS.items()]) diff --exclude=.hg -rupN xen-incoming.hg/tools/python/xen/xend/XendDomainInfo.py xen-watchdog-ref.hg/tools/python/xen/xend/XendDomainInfo.py --- xen-incoming.hg/tools/python/xen/xend/XendDomainInfo.py 2007-05-30 23:00:34.000000000 +0100 +++ xen-watchdog-ref.hg/tools/python/xen/xend/XendDomainInfo.py 2007-06-01 04:23:04.000000000 +0100 @@ -367,6 +367,8 @@ class XendDomainInfo: self.state_updated = threading.Condition() self.refresh_shutdown_lock = threading.Condition() self._stateSet(DOM_STATE_HALTED) + if not info.has_key('watchdog_lastboot'): + self.info['watchdog_lastboot'] = False self._deviceControllers = {} @@ -871,7 +873,7 @@ class XendDomainInfo: # Check whether values in the configuration have # changed in Xenstore. - cfg_vm = ['name', 'on_poweroff', 'on_reboot', 'on_crash', + cfg_vm = ['name', 'on_poweroff', 'on_reboot', 'on_crash', 'on_watchdog', 'rtc/timeoffset'] vm_details = self._readVMDetails([(k,XendConfig.LEGACY_CFG_TYPES[k]) @@ -1103,9 +1105,12 @@ class XendDomainInfo: else: reason = shutdown_reason(xeninfo['shutdown_reason']) + log.info log.info('Domain has shutdown: name=%s id=%d reason=%s.', self.info['name_label'], self.domid, reason) + + # Set the domain's watchdog / lastreboot flag here, if appropriate. self._writeVm(LAST_SHUTDOWN_REASON, reason) self._clearRestart() @@ -1118,6 +1123,10 @@ class XendDomainInfo: # watch for the old domain, and one for the new. self._unwatchVm() elif reason in ('poweroff', 'reboot'): + self.info['watchdog_lastboot'] = False + restart_reason = reason + elif reason == 'watchdog': + self.info['watchdog_lastboot'] = True restart_reason = reason else: self.destroy() @@ -1147,6 +1156,7 @@ class XendDomainInfo: self.refresh_shutdown_lock.release() if restart_reason: + log.debug("Restarted with a reason!") threading.Thread(target = self._maybeRestart, args = (restart_reason,)).start() @@ -1171,6 +1181,7 @@ class XendDomainInfo: 'poweroff': 'actions_after_shutdown', 'reboot': 'actions_after_reboot', 'crash': 'actions_after_crash', + 'watchdog': 'actions_after_watchdog' } action_target = self.info.get(action_conf.get(reason)) @@ -1494,6 +1505,9 @@ class XendDomainInfo: xc.domain_setcpuweight(self.domid, self.info['cpu_weight']) + r = xc.domain_watchdog_set_lastboot(self.domid, + self.info['watchdog_lastboot']) + # repin domain vcpus if a restricted cpus list is provided # this is done prior to memory allocation to aide in memory # distribution for NUMA systems. @@ -2220,6 +2234,12 @@ class XendDomainInfo: return XEN_API_ON_CRASH_BEHAVIOUR[0] return after_crash + def get_on_watchdog(self): + after_watchdog = self.info.get('action_after_watchdog') + if not after_watchdog or after_watchdog not in XEN_API_ON_NORMAL_EXIT: + return XEN_API_ON_NORMAL_EXIT[-1] + return after_watchdog + def get_dev_config_by_uuid(self, dev_class, dev_uuid): """ Get's a device configuration either from XendConfig or from the DevController. diff --exclude=.hg -rupN xen-incoming.hg/tools/python/xen/xm/create.py xen-watchdog-ref.hg/tools/python/xen/xm/create.py --- xen-incoming.hg/tools/python/xen/xm/create.py 2007-04-27 23:00:09.000000000 +0100 +++ xen-watchdog-ref.hg/tools/python/xen/xm/create.py 2007-06-01 04:23:04.000000000 +0100 @@ -262,6 +262,17 @@ gopts.var('on_crash', val='destroy|resta renamed and a new domain started in its place. """) +gopts.var('on_watchdog', val='destroy|restart|preserve|rename-restart', + fn=set_value, default=None, + use="""Behaviour when a domain exits with reason 'watchdog'. + - destroy: the domain is cleaned up as normal; + - restart: a new domain is started in place of the old one; + - preserve: no clean-up is done until the domain is manually + destroyed (using xm destroy, for example); + - rename-restart: the old domain is not cleaned up, but is + renamed and a new domain started in its place. + """) + gopts.var('blkif', val='no|yes', fn=set_bool, default=0, use="Make the domain a block device backend.") @@ -747,7 +758,7 @@ def make_config(vals): map(add_conf, ['name', 'memory', 'maxmem', 'shadow_memory', 'restart', 'on_poweroff', - 'on_reboot', 'on_crash', 'vcpus', 'vcpu_avail', 'features', + 'on_reboot', 'on_crash', 'on_watchdog', 'vcpus', 'vcpu_avail', 'features', 'on_xend_start', 'on_xend_stop']) if vals.uuid is not None: --Boundary-00=_wd5XGRJ0UHcGhlT 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 --Boundary-00=_wd5XGRJ0UHcGhlT--