ia64/xen-unstable

changeset 11024:c1850c659e40

Make ballon and backend drivers fail gracefully if they are unable to initialize
due to missing hypervisor support.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian.Campbell@xensource.com
date Wed Aug 09 11:27:28 2006 +0100 (2006-08-09)
parents 9f70d57aadcf
children b16252dbcb1f
files linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Wed Aug 09 11:26:11 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Wed Aug 09 11:27:28 2006 +0100
     1.3 @@ -563,10 +563,14 @@ struct page *balloon_alloc_empty_page_ra
     1.4  		set_xen_guest_handle(reservation.extent_start, &gmfn);
     1.5  		ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
     1.6  					   &reservation);
     1.7 +		if (ret == -ENOSYS)
     1.8 +			goto err;
     1.9  		BUG_ON(ret != 1);
    1.10  	} else {
    1.11  		ret = apply_to_page_range(&init_mm, vstart, PAGE_SIZE << order,
    1.12  					  dealloc_pte_fn, NULL);
    1.13 +		if (ret == -ENOSYS)
    1.14 +			goto err;
    1.15  		BUG_ON(ret);
    1.16  	}
    1.17  	current_pages -= 1UL << order;
    1.18 @@ -583,6 +587,11 @@ struct page *balloon_alloc_empty_page_ra
    1.19  		set_page_count(page + i, 1);
    1.20  
    1.21  	return page;
    1.22 +
    1.23 + err:
    1.24 +	free_pages(vstart, order);
    1.25 +	balloon_unlock(flags);
    1.26 +	return NULL;
    1.27  }
    1.28  
    1.29  void balloon_dealloc_empty_page_range(
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Wed Aug 09 11:26:11 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Wed Aug 09 11:27:28 2006 +0100
     2.3 @@ -518,6 +518,19 @@ static int __init blkif_init(void)
     2.4  		return -ENODEV;
     2.5  
     2.6  	mmap_pages            = blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST;
     2.7 +
     2.8 +#ifdef CONFIG_XEN_IA64_DOM0_NON_VP
     2.9 +	extern unsigned long alloc_empty_foreign_map_page_range(
    2.10 +		unsigned long pages);
    2.11 +	mmap_vstart = (unsigned long)
    2.12 +		alloc_empty_foreign_map_page_range(mmap_pages);
    2.13 +#else /* ! ia64 */
    2.14 +	page = balloon_alloc_empty_page_range(mmap_pages);
    2.15 +	if (page == NULL)
    2.16 +		return -ENOMEM;
    2.17 +	mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    2.18 +#endif
    2.19 +
    2.20  	pending_reqs          = kmalloc(sizeof(pending_reqs[0]) *
    2.21  					blkif_reqs, GFP_KERNEL);
    2.22  	pending_grant_handles = kmalloc(sizeof(pending_grant_handles[0]) *
    2.23 @@ -534,16 +547,6 @@ static int __init blkif_init(void)
    2.24  
    2.25  	blkif_interface_init();
    2.26  	
    2.27 -#ifdef CONFIG_XEN_IA64_DOM0_NON_VP
    2.28 -	extern unsigned long alloc_empty_foreign_map_page_range(
    2.29 -		unsigned long pages);
    2.30 -	mmap_vstart = (unsigned long)
    2.31 -		alloc_empty_foreign_map_page_range(mmap_pages);
    2.32 -#else /* ! ia64 */
    2.33 -	page = balloon_alloc_empty_page_range(mmap_pages);
    2.34 -	BUG_ON(page == NULL);
    2.35 -	mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    2.36 -#endif
    2.37  	printk("%s: reqs=%d, pages=%d, mmap_vstart=0x%lx\n",
    2.38  	       __FUNCTION__, blkif_reqs, mmap_pages, mmap_vstart);
    2.39  	BUG_ON(mmap_vstart == 0);
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Wed Aug 09 11:26:11 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Wed Aug 09 11:27:28 2006 +0100
     3.3 @@ -709,30 +709,19 @@ static void make_response(blkif_t *blkif
     3.4  /******************************************************************
     3.5   * misc small helpers
     3.6   */
     3.7 -/* FIXME: Return ENOMEM properly on failure to allocate additional reqs. */
     3.8 -static void req_increase(void)
     3.9 +static int req_increase(void)
    3.10  {
    3.11  	int i, j;
    3.12  	struct page *page;
    3.13  	unsigned long flags;
    3.14 +	int ret;
    3.15  
    3.16  	spin_lock_irqsave(&pending_free_lock, flags);
    3.17  
    3.18 +	ret = -EINVAL;
    3.19  	if (mmap_alloc >= MAX_PENDING_REQS || mmap_lock) 
    3.20  		goto done;
    3.21  
    3.22 -	pending_reqs[mmap_alloc]  = kzalloc(sizeof(pending_req_t) *
    3.23 -					blkif_reqs, GFP_KERNEL);
    3.24 -	pending_addrs[mmap_alloc] = kzalloc(sizeof(unsigned long) *
    3.25 -					mmap_pages, GFP_KERNEL);
    3.26 -
    3.27 -	if (!pending_reqs[mmap_alloc] || !pending_addrs[mmap_alloc]) {
    3.28 -		kfree(pending_reqs[mmap_alloc]);
    3.29 -		kfree(pending_addrs[mmap_alloc]);
    3.30 -		WPRINTK("%s: out of memory\n", __FUNCTION__); 
    3.31 -		goto done;
    3.32 -	}
    3.33 -
    3.34  #ifdef __ia64__
    3.35  	extern unsigned long alloc_empty_foreign_map_page_range(
    3.36  		unsigned long pages);
    3.37 @@ -740,7 +729,11 @@ static void req_increase(void)
    3.38  		alloc_empty_foreign_map_page_range(mmap_pages);
    3.39  #else /* ! ia64 */
    3.40  	page = balloon_alloc_empty_page_range(mmap_pages);
    3.41 -	BUG_ON(page == NULL);
    3.42 +	ret = -ENOMEM;
    3.43 +	if (page == NULL) {
    3.44 +		printk("%s balloon_alloc_empty_page_range gave NULL\n", __FUNCTION__);
    3.45 +		goto done;
    3.46 +	}
    3.47  
    3.48  	/* Pin all of the pages. */
    3.49  	for (i=0; i<mmap_pages; i++)
    3.50 @@ -751,6 +744,23 @@ static void req_increase(void)
    3.51  	mmap_start[mmap_alloc].mpage = page;
    3.52  
    3.53  #endif
    3.54 +
    3.55 +	pending_reqs[mmap_alloc]  = kzalloc(sizeof(pending_req_t) *
    3.56 +					blkif_reqs, GFP_KERNEL);
    3.57 +	pending_addrs[mmap_alloc] = kzalloc(sizeof(unsigned long) *
    3.58 +					mmap_pages, GFP_KERNEL);
    3.59 +
    3.60 +	ret = -ENOMEM;
    3.61 +	if (!pending_reqs[mmap_alloc] || !pending_addrs[mmap_alloc]) {
    3.62 +		kfree(pending_reqs[mmap_alloc]);
    3.63 +		kfree(pending_addrs[mmap_alloc]);
    3.64 +		WPRINTK("%s: out of memory\n", __FUNCTION__); 
    3.65 +		ret = -ENOMEM;
    3.66 +		goto done;
    3.67 +	}
    3.68 +
    3.69 +	ret = 0;
    3.70 +
    3.71  	DPRINTK("%s: reqs=%d, pages=%d, mmap_vstart=0x%lx\n",
    3.72  	        __FUNCTION__, blkif_reqs, mmap_pages, 
    3.73  	       mmap_start[mmap_alloc].start);
    3.74 @@ -774,7 +784,7 @@ static void req_increase(void)
    3.75  	DPRINTK("# MMAPs increased to %d\n",mmap_alloc);
    3.76   done:
    3.77  	spin_unlock_irqrestore(&pending_free_lock, flags);
    3.78 -
    3.79 +	return ret;
    3.80  }
    3.81  
    3.82  static void mmap_req_del(int mmap)
    3.83 @@ -1394,7 +1404,13 @@ static int __init blkif_init(void)
    3.84  		return -ENODEV;
    3.85  
    3.86  	INIT_LIST_HEAD(&pending_free);
    3.87 -        for(i = 0; i < 2; i++) req_increase();
    3.88 +        for(i = 0; i < 2; i++) {
    3.89 +		ret = req_increase();
    3.90 +		if (ret)
    3.91 +			break;
    3.92 +	}
    3.93 +	if (i == 0)
    3.94 +		return ret;
    3.95  
    3.96  	tap_blkif_interface_init();
    3.97  
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Wed Aug 09 11:26:11 2006 +0100
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Wed Aug 09 11:27:28 2006 +0100
     4.3 @@ -1306,7 +1306,9 @@ static int __init netback_init(void)
     4.4  	net_timer.function = net_alarm;
     4.5      
     4.6  	page = balloon_alloc_empty_page_range(MAX_PENDING_REQS);
     4.7 -	BUG_ON(page == NULL);
     4.8 +	if (page == NULL)
     4.9 +		return -ENOMEM;
    4.10 +
    4.11  	mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    4.12  
    4.13  	for (i = 0; i < MAX_PENDING_REQS; i++) {