[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] merge with xen-unstable.hg
# HG changeset patch # User Isaku Yamahata <yamahata@xxxxxxxxxxxxx> # Date 1223002147 -32400 # Node ID 591734b38585ef474cda87ca5a6a5b82436e1470 # Parent c8511a5e9a570c5086b96251fb97653ca6de5e88 # Parent 80365bc6df425c5c0a0b812d82f1ad84bc8c73d6 merge with xen-unstable.hg --- tools/blktap/lib/xs_api.c | 2 tools/libxc/xc_ptrace.c | 9 +--- tools/python/xen/xend/XendDomainInfo.py | 57 ++++++++++++++++++-------- tools/python/xen/xend/image.py | 4 - xen/arch/x86/hvm/hvm.c | 69 +++++--------------------------- xen/arch/x86/mm.c | 53 +++++------------------- xen/common/domain.c | 19 ++++++++ xen/common/event_channel.c | 51 ++++------------------- xen/common/memory.c | 35 ++-------------- xen/include/xen/sched.h | 7 +++ 10 files changed, 111 insertions(+), 195 deletions(-) diff -r c8511a5e9a57 -r 591734b38585 tools/blktap/lib/xs_api.c --- a/tools/blktap/lib/xs_api.c Thu Oct 02 17:27:57 2008 +0900 +++ b/tools/blktap/lib/xs_api.c Fri Oct 03 11:49:07 2008 +0900 @@ -132,7 +132,7 @@ int xs_printf(struct xs_handle *h, const return ENOMEM; } - ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1); + ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)); free(buf); free(path); diff -r c8511a5e9a57 -r 591734b38585 tools/libxc/xc_ptrace.c --- a/tools/libxc/xc_ptrace.c Thu Oct 02 17:27:57 2008 +0900 +++ b/tools/libxc/xc_ptrace.c Fri Oct 03 11:49:07 2008 +0900 @@ -112,17 +112,16 @@ get_online_cpumap(int xc_handle, struct get_online_cpumap(int xc_handle, struct xen_domctl_getdomaininfo *d, uint64_t *cpumap) { - int i, online, retval; + int i, online; *cpumap = 0; for (i = 0; i <= d->max_vcpu_id; i++) { - if ((retval = fetch_regs(xc_handle, i, &online))) - return retval; + fetch_regs(xc_handle, i, &online); if (online) *cpumap |= (1 << i); } - - return 0; + + return (*cpumap == 0) ? -1 : 0; } /* diff -r c8511a5e9a57 -r 591734b38585 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Thu Oct 02 17:27:57 2008 +0900 +++ b/tools/python/xen/xend/XendDomainInfo.py Fri Oct 03 11:49:07 2008 +0900 @@ -142,7 +142,9 @@ def recreate(info, priv): xeninfo['is_control_domain'] = priv xeninfo['is_a_template'] = False domid = xeninfo['domid'] - + uuid1 = uuid.fromString(xeninfo['uuid']) + needs_reinitialising = False + dompath = GetDomainPath(domid) if not dompath: raise XendError('No domain path in store for existing ' @@ -151,12 +153,42 @@ def recreate(info, priv): log.info("Recreating domain %d, UUID %s. at %s" % (domid, xeninfo['uuid'], dompath)) - vmpath = xstransact.Read("/vm_path", str(domid)) + # need to verify the path and uuid if not Domain-0 + # if the required uuid and vm aren't set, then that means + # we need to recreate the dom with our own values + # + # NOTE: this is probably not desirable, really we should just + # abort or ignore, but there may be cases where xenstore's + # entry disappears (eg. xenstore-rm /) + # + try: + vmpath = xstransact.Read(dompath, "vm") + if not vmpath: + if not priv: + log.warn('/local/domain/%d/vm is missing. recreate is ' + 'confused, trying our best to recover' % domid) + needs_reinitialising = True + raise XendError('reinit') + + uuid2_str = xstransact.Read(vmpath, "uuid") + if not uuid2_str: + log.warn('%s/uuid/ is missing. recreate is confused, ' + 'trying our best to recover' % vmpath) + needs_reinitialising = True + raise XendError('reinit') + + uuid2 = uuid.fromString(uuid2_str) + if uuid1 != uuid2: + log.warn('UUID in /vm does not match the UUID in /dom/%d.' + 'Trying out best to recover' % domid) + needs_reinitialising = True + except XendError: + pass # our best shot at 'goto' in python :) vm = XendDomainInfo(xeninfo, domid, dompath, augment = True, priv = priv, vmpath = vmpath) - - if not vmpath: + + if needs_reinitialising: vm._recreateDom() vm._removeVm() vm._storeVmDetails() @@ -1269,8 +1301,11 @@ class XendDomainInfo: def _recreateDomFunc(self, t): t.remove() t.mkdir() - t.set_permissions({'dom' : self.domid}) + t.set_permissions({'dom' : self.domid, 'read' : True}) t.write('vm', self.vmpath) + for i in [ 'device', 'control', 'error' ]: + t.mkdir(i) + t.set_permissions(i, {'dom' : self.domid}) def _storeDomDetails(self): to_store = { @@ -1776,7 +1811,6 @@ class XendDomainInfo: self._releaseDevices() # Remove existing vm node in xenstore self._removeVm() - self._removeVmPath() new_dom_info = self.info.copy() new_dom_info['name_label'] = self.info['name_label'] new_dom_info['uuid'] = self.info['uuid'] @@ -2357,7 +2391,6 @@ class XendDomainInfo: paths = self._prepare_phantom_paths() - self._removeVmPath() if self.dompath is not None: try: xc.domain_destroy_hook(self.domid) @@ -2660,15 +2693,6 @@ class XendDomainInfo: log.info("Dev still active but hit max loop timeout") break - def _storeVmPath(self): - log.info("storeVmPath(%s) => %s", self.domid, self.vmpath) - if self.domid is not None: - xstransact.Write('/vm_path', str(self.domid), self.vmpath) - - def _removeVmPath(self): - if self.domid is not None: - xstransact.Remove('/vm_path/%s' % str(self.domid)) - def _storeVmDetails(self): to_store = {} @@ -2693,7 +2717,6 @@ class XendDomainInfo: self._writeVm(to_store) self._setVmPermissions() - self._storeVmPath() def _setVmPermissions(self): """Allow the guest domain to read its UUID. We don't allow it to diff -r c8511a5e9a57 -r 591734b38585 tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py Thu Oct 02 17:27:57 2008 +0900 +++ b/tools/python/xen/xend/image.py Fri Oct 03 11:49:07 2008 +0900 @@ -418,7 +418,7 @@ class ImageHandler: os.close(null) os.close(logfd) sentinel_write.close() - self.vm.storeVm("image/device-model-pid", self.pid) + self.vm.storeDom("image/device-model-pid", self.pid) log.info("device model pid: %d", self.pid) # we would very much prefer not to have a thread here and instead # have a callback but sadly we don't have Twisted in xend @@ -502,7 +502,7 @@ class ImageHandler: if fifo_fd >= 0: self._openSentinel(sentinel_path_fifo) os.close(fifo_fd) - self.pid = self.vm._gatherVm(('image/device-model-pid', int)) + self.pid = self.vm._gatherDom(('image/device-model-pid', int)) log.debug("%s device model rediscovered, pid %s sentinel fifo %s", name, self.pid, sentinel_path_fifo) self.sentinel_thread = thread.start_new_thread(self._sentinel_watch,()) diff -r c8511a5e9a57 -r 591734b38585 xen/arch/x86/hvm/hvm.c --- a/xen/arch/x86/hvm/hvm.c Thu Oct 02 17:27:57 2008 +0900 +++ b/xen/arch/x86/hvm/hvm.c Fri Oct 03 11:49:07 2008 +0900 @@ -2339,21 +2339,9 @@ long do_hvm_op(unsigned long op, XEN_GUE if ( a.index >= HVM_NR_PARAMS ) return -EINVAL; - if ( a.domid == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(a.domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rc = -EPERM; - goto param_fail; - } - } - + rc = rcu_lock_target_domain_by_id(a.domid, &d); + if ( rc != 0 ) + return rc; rc = -EINVAL; if ( !is_hvm_domain(d) ) @@ -2521,20 +2509,9 @@ long do_hvm_op(unsigned long op, XEN_GUE if ( copy_from_guest(&a, arg, 1) ) return -EFAULT; - if ( a.domid == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(a.domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rc = -EPERM; - goto param_fail2; - } - } + rc = rcu_lock_target_domain_by_id(a.domid, &d); + if ( rc != 0 ) + return rc; rc = -EINVAL; if ( !is_hvm_domain(d) ) @@ -2570,20 +2547,9 @@ long do_hvm_op(unsigned long op, XEN_GUE if ( copy_from_guest(&a, arg, 1) ) return -EFAULT; - if ( a.domid == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(a.domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rc = -EPERM; - goto param_fail3; - } - } + rc = rcu_lock_target_domain_by_id(a.domid, &d); + if ( rc != 0 ) + return rc; rc = -EINVAL; if ( !is_hvm_domain(d) ) @@ -2637,20 +2603,9 @@ long do_hvm_op(unsigned long op, XEN_GUE if ( copy_from_guest(&a, arg, 1) ) return -EFAULT; - if ( a.domid == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(a.domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rc = -EPERM; - goto param_fail4; - } - } + rc = rcu_lock_target_domain_by_id(a.domid, &d); + if ( rc != 0 ) + return rc; rc = -EINVAL; if ( !is_hvm_domain(d) ) diff -r c8511a5e9a57 -r 591734b38585 xen/arch/x86/mm.c --- a/xen/arch/x86/mm.c Thu Oct 02 17:27:57 2008 +0900 +++ b/xen/arch/x86/mm.c Fri Oct 03 11:49:07 2008 +0900 @@ -3550,6 +3550,8 @@ long arch_memory_op(int op, XEN_GUEST_HA long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg) { struct page_info *page = NULL; + int rc; + switch ( op ) { case XENMEM_add_to_physmap: @@ -3561,20 +3563,9 @@ long arch_memory_op(int op, XEN_GUEST_HA if ( copy_from_guest(&xatp, arg, 1) ) return -EFAULT; - if ( xatp.domid == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(xatp.domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - } + rc = rcu_lock_target_domain_by_id(xatp.domid, &d); + if ( rc != 0 ) + return rc; if ( xsm_add_to_physmap(current->domain, d) ) { @@ -3661,20 +3652,9 @@ long arch_memory_op(int op, XEN_GUEST_HA if ( copy_from_guest(&xrfp, arg, 1) ) return -EFAULT; - if ( xrfp.domid == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(xrfp.domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - } + rc = rcu_lock_target_domain_by_id(xrfp.domid, &d); + if ( rc != 0 ) + return rc; if ( xsm_remove_from_physmap(current->domain, d) ) { @@ -3708,20 +3688,9 @@ long arch_memory_op(int op, XEN_GUEST_HA if ( fmap.map.nr_entries > ARRAY_SIZE(d->arch.e820) ) return -EINVAL; - if ( fmap.domid == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(fmap.domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - } + rc = rcu_lock_target_domain_by_id(fmap.domid, &d); + if ( rc != 0 ) + return rc; rc = xsm_domain_memory_map(d); if ( rc ) diff -r c8511a5e9a57 -r 591734b38585 xen/common/domain.c --- a/xen/common/domain.c Thu Oct 02 17:27:57 2008 +0900 +++ b/xen/common/domain.c Fri Oct 03 11:49:07 2008 +0900 @@ -332,6 +332,25 @@ struct domain *rcu_lock_domain_by_id(dom return NULL; } +int rcu_lock_target_domain_by_id(domid_t dom, struct domain **d) +{ + if ( dom == DOMID_SELF ) + { + *d = rcu_lock_current_domain(); + return 0; + } + + if ( (*d = rcu_lock_domain_by_id(dom)) == NULL ) + return -ESRCH; + + if ( !IS_PRIV_FOR(current->domain, *d) ) + { + rcu_unlock_domain(*d); + return -EPERM; + } + + return 0; +} int domain_kill(struct domain *d) { diff -r c8511a5e9a57 -r 591734b38585 xen/common/event_channel.c --- a/xen/common/event_channel.c Thu Oct 02 17:27:57 2008 +0900 +++ b/xen/common/event_channel.c Fri Oct 03 11:49:07 2008 +0900 @@ -129,20 +129,9 @@ static long evtchn_alloc_unbound(evtchn_ domid_t dom = alloc->dom; long rc; - if ( dom == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(dom)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - } + rc = rcu_lock_target_domain_by_id(dom, &d); + if ( rc ) + return rc; spin_lock(&d->evtchn_lock); @@ -663,20 +652,9 @@ static long evtchn_status(evtchn_status_ struct evtchn *chn; long rc = 0; - if ( dom == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(dom)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - } + rc = rcu_lock_target_domain_by_id(dom, &d); + if ( rc ) + return rc; spin_lock(&d->evtchn_lock); @@ -824,20 +802,9 @@ static long evtchn_reset(evtchn_reset_t struct domain *d; int i, rc; - if ( dom == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(dom)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rc = -EPERM; - goto out; - } - } + rc = rcu_lock_target_domain_by_id(dom, &d); + if ( rc ) + return rc; rc = xsm_evtchn_reset(current->domain, d); if ( rc ) diff -r c8511a5e9a57 -r 591734b38585 xen/common/memory.c --- a/xen/common/memory.c Thu Oct 02 17:27:57 2008 +0900 +++ b/xen/common/memory.c Fri Oct 03 11:49:07 2008 +0900 @@ -222,21 +222,9 @@ static long translate_gpfn_list( !guest_handle_subrange_okay(op.mfn_list, *progress, op.nr_gpfns-1) ) return -EFAULT; - if ( op.domid == DOMID_SELF ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(op.domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - } - + rc = rcu_lock_target_domain_by_id(op.domid, &d); + if ( rc ) + return rc; if ( !paging_mode_translate(d) ) { @@ -595,20 +583,9 @@ long do_memory_op(unsigned long cmd, XEN if ( copy_from_guest(&domid, arg, 1) ) return -EFAULT; - if ( likely(domid == DOMID_SELF) ) - { - d = rcu_lock_current_domain(); - } - else - { - if ( (d = rcu_lock_domain_by_id(domid)) == NULL ) - return -ESRCH; - if ( !IS_PRIV_FOR(current->domain, d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - } + rc = rcu_lock_target_domain_by_id(domid, &d); + if ( rc ) + return rc; rc = xsm_memory_stat_reservation(current->domain, d); if ( rc ) diff -r c8511a5e9a57 -r 591734b38585 xen/include/xen/sched.h --- a/xen/include/xen/sched.h Thu Oct 02 17:27:57 2008 +0900 +++ b/xen/include/xen/sched.h Fri Oct 03 11:49:07 2008 +0900 @@ -364,6 +364,13 @@ int construct_dom0( */ struct domain *rcu_lock_domain_by_id(domid_t dom); +/* + * As above function, but accounts for current domain context: + * - Translates target DOMID_SELF into caller's domain id; and + * - Checks that caller has permission to act on the target domain. + */ +int rcu_lock_target_domain_by_id(domid_t dom, struct domain **d); + /* Finish a RCU critical region started by rcu_lock_domain_by_id(). */ static inline void rcu_unlock_domain(struct domain *d) { _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |