ia64/xen-unstable

changeset 18577:788ed94f8fe4

[IA64] make use of rcu_lock_target_domain_by_id()

reduce code duplication by using rcu_lock_target_domain_by_id()

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Fri Oct 03 12:24:49 2008 +0900 (2008-10-03)
parents 591734b38585
children ba543f51c6f1
files xen/arch/ia64/vmx/vmx_hypercall.c xen/arch/ia64/xen/mm.c
line diff
     1.1 --- a/xen/arch/ia64/vmx/vmx_hypercall.c	Fri Oct 03 11:49:07 2008 +0900
     1.2 +++ b/xen/arch/ia64/vmx/vmx_hypercall.c	Fri Oct 03 12:24:49 2008 +0900
     1.3 @@ -50,16 +50,9 @@ static int hvmop_set_isa_irq_level(
     1.4      if ( op.isa_irq > 15 )
     1.5          return -EINVAL;
     1.6  
     1.7 -    if ( op.domid == DOMID_SELF )
     1.8 -        op.domid = current->domain->domain_id;
     1.9 -
    1.10 -    d = rcu_lock_domain_by_id(op.domid);
    1.11 -    if ( d == NULL )
    1.12 -        return -ESRCH;
    1.13 -
    1.14 -    rc = -EPERM;
    1.15 -    if ( !IS_PRIV_FOR(current->domain, d) && d != current->domain )
    1.16 -        goto out;
    1.17 +    rc = rcu_lock_target_domain_by_id(op.domid, &d);
    1.18 +    if ( rc != 0 )
    1.19 +        return rc;
    1.20  
    1.21      rc = -EINVAL;
    1.22      if ( !is_hvm_domain(d) )
    1.23 @@ -86,16 +79,9 @@ static int hvmop_set_pci_intx_level(
    1.24      if ( (op.domain > 0) || (op.bus > 0) || (op.device > 31) || (op.intx > 3) )
    1.25          return -EINVAL;
    1.26  
    1.27 -    if ( op.domid == DOMID_SELF )
    1.28 -        op.domid = current->domain->domain_id;
    1.29 -
    1.30 -    d = rcu_lock_domain_by_id(op.domid);
    1.31 -    if ( d == NULL )
    1.32 -        return -ESRCH;
    1.33 -
    1.34 -    rc = -EPERM;
    1.35 -    if ( !IS_PRIV_FOR(current->domain, d) && d != current->domain )
    1.36 -        goto out;
    1.37 +    rc = rcu_lock_target_domain_by_id(op.domid, &d);
    1.38 +    if ( rc != 0 )
    1.39 +        return rc;
    1.40  
    1.41      rc = -EINVAL;
    1.42      if ( !is_hvm_domain(d) )
    1.43 @@ -129,18 +115,9 @@ do_hvm_op(unsigned long op, XEN_GUEST_HA
    1.44          if (a.index >= HVM_NR_PARAMS)
    1.45              return -EINVAL;
    1.46  
    1.47 -        if (a.domid == DOMID_SELF) {
    1.48 -            d = rcu_lock_current_domain();
    1.49 -        }
    1.50 -        else {
    1.51 -            d = rcu_lock_domain_by_id(a.domid);
    1.52 -            if (d == NULL)
    1.53 -                return -ESRCH;
    1.54 -            if (!IS_PRIV_FOR(current->domain, d)) {
    1.55 -                rcu_unlock_domain(d);
    1.56 -                return -EPERM;
    1.57 -            }
    1.58 -        }
    1.59 +        rc = rcu_lock_target_domain_by_id(a.domid, &d);
    1.60 +        if (rc != 0)
    1.61 +            return rc;
    1.62  
    1.63          if (op == HVMOP_set_param) {
    1.64              struct vmx_ioreq_page *iorp;
    1.65 @@ -213,20 +190,9 @@ do_hvm_op(unsigned long op, XEN_GUEST_HA
    1.66          if ( copy_from_guest(&a, arg, 1) )
    1.67              return -EFAULT;
    1.68  
    1.69 -        if ( a.domid == DOMID_SELF )
    1.70 -        {
    1.71 -            d = rcu_lock_current_domain();
    1.72 -        }
    1.73 -        else
    1.74 -        {
    1.75 -            if ( (d = rcu_lock_domain_by_id(a.domid)) == NULL )
    1.76 -                return -ESRCH;
    1.77 -            if ( !IS_PRIV_FOR(current->domain, d) )
    1.78 -            {
    1.79 -                rc = -EPERM;
    1.80 -                goto param_fail3;
    1.81 -            }
    1.82 -        }
    1.83 +        rc = rcu_lock_target_domain_by_id(a.domid, &d);
    1.84 +        if ( rc != 0 )
    1.85 +            break;
    1.86  
    1.87          rc = -EINVAL;
    1.88          if ( !is_hvm_domain(d) )
     2.1 --- a/xen/arch/ia64/xen/mm.c	Fri Oct 03 11:49:07 2008 +0900
     2.2 +++ b/xen/arch/ia64/xen/mm.c	Fri Oct 03 12:24:49 2008 +0900
     2.3 @@ -2815,6 +2815,7 @@ long
     2.4  arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg)
     2.5  {
     2.6      struct page_info *page = NULL;
     2.7 +    long rc;
     2.8  
     2.9      switch (op) {
    2.10      case XENMEM_add_to_physmap:
    2.11 @@ -2826,16 +2827,9 @@ arch_memory_op(int op, XEN_GUEST_HANDLE(
    2.12          if (copy_from_guest(&xatp, arg, 1))
    2.13              return -EFAULT;
    2.14  
    2.15 -        if (xatp.domid == DOMID_SELF)
    2.16 -            d = rcu_lock_current_domain();
    2.17 -        else {
    2.18 -            if ((d = rcu_lock_domain_by_id(xatp.domid)) == NULL)
    2.19 -                return -ESRCH;
    2.20 -            if (!IS_PRIV_FOR(current->domain,d)) {
    2.21 -                rcu_lock_domain(d);
    2.22 -                return -EPERM;
    2.23 -            }
    2.24 -        }
    2.25 +        rc = rcu_lock_target_domain_by_id(xatp.domid, &d);
    2.26 +        if (rc)
    2.27 +            return rc;
    2.28  
    2.29          /* This hypercall is used for VT-i domain only */
    2.30          if (!is_hvm_domain(d)) {
    2.31 @@ -2926,20 +2920,9 @@ arch_memory_op(int op, XEN_GUEST_HANDLE(
    2.32          if ( copy_from_guest(&xrfp, arg, 1) )
    2.33              return -EFAULT;
    2.34  
    2.35 -        if ( xrfp.domid == DOMID_SELF )
    2.36 -        {
    2.37 -            d = rcu_lock_current_domain();
    2.38 -        }
    2.39 -        else
    2.40 -        {
    2.41 -            if ( (d = rcu_lock_domain_by_id(xrfp.domid)) == NULL )
    2.42 -                return -ESRCH;
    2.43 -            if ( !IS_PRIV_FOR(current->domain, d) )
    2.44 -            {
    2.45 -                rcu_unlock_domain(d);
    2.46 -                return -EPERM;
    2.47 -            }
    2.48 -        }
    2.49 +        rc = rcu_lock_target_domain_by_id(xrfp.domid, &d);
    2.50 +        if ( rc != 0 )
    2.51 +            return rc;
    2.52  
    2.53          domain_lock(d);
    2.54