direct-io.hg

changeset 7390:938f209d886b

Detect failure to create shutdown process and retry twice
per second until it succeeds.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat Oct 15 16:25:05 2005 +0100 (2005-10-15)
parents 4c9dbbb5fe3d
children 9d51c5afda92
files linux-2.6-xen-sparse/arch/xen/kernel/reboot.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c	Sat Oct 15 12:56:07 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c	Sat Oct 15 16:25:05 2005 +0100
     1.3 @@ -26,7 +26,6 @@
     1.4  // the distinction when we return the reason code to them.
     1.5  #define SHUTDOWN_HALT      4
     1.6  
     1.7 -
     1.8  void machine_restart(char * __unused)
     1.9  {
    1.10  	/* We really want to get pending console data out before we die. */
    1.11 @@ -60,6 +59,8 @@ EXPORT_SYMBOL(machine_power_off);
    1.12  
    1.13  /* Ignore multiple shutdown requests. */
    1.14  static int shutting_down = SHUTDOWN_INVALID;
    1.15 +static void __shutdown_handler(void *unused);
    1.16 +static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
    1.17  
    1.18  #ifndef CONFIG_HOTPLUG_CPU
    1.19  #define cpu_down(x) (-EOPNOTSUPP)
    1.20 @@ -243,41 +244,47 @@ static int shutdown_process(void *__unus
    1.21  	return 0;
    1.22  }
    1.23  
    1.24 -static struct task_struct *kthread_create_on_cpu(int (*f)(void *arg),
    1.25 -						 void *arg,
    1.26 -						 const char *name,
    1.27 -						 int cpu)
    1.28 +static int kthread_create_on_cpu(int (*f)(void *arg),
    1.29 +				 void *arg,
    1.30 +				 const char *name,
    1.31 +				 int cpu)
    1.32  {
    1.33  	struct task_struct *p;
    1.34  	p = kthread_create(f, arg, name);
    1.35 +	if (IS_ERR(p))
    1.36 +		return PTR_ERR(p);
    1.37  	kthread_bind(p, cpu);
    1.38  	wake_up_process(p);
    1.39 -	return p;
    1.40 +	return 0;
    1.41  }
    1.42  
    1.43  static void __shutdown_handler(void *unused)
    1.44  {
    1.45  	int err;
    1.46  
    1.47 -	if (shutting_down != SHUTDOWN_SUSPEND) {
    1.48 +	if (shutting_down != SHUTDOWN_SUSPEND)
    1.49  		err = kernel_thread(shutdown_process, NULL,
    1.50  				    CLONE_FS | CLONE_FILES);
    1.51 -		if ( err < 0 )
    1.52 -			printk(KERN_ALERT "Error creating shutdown "
    1.53 -			       "process!\n");
    1.54 -	} else {
    1.55 -		kthread_create_on_cpu(__do_suspend, NULL, "suspender", 0);
    1.56 +	else
    1.57 +		err = kthread_create_on_cpu(__do_suspend, NULL, "suspend", 0);
    1.58 +
    1.59 +	if ( err < 0 ) {
    1.60 +		printk(KERN_WARNING "Error creating shutdown process (%d): "
    1.61 +		       "retrying...\n", -err);
    1.62 +		schedule_delayed_work(&shutdown_work, HZ/2);
    1.63  	}
    1.64  }
    1.65  
    1.66  static void shutdown_handler(struct xenbus_watch *watch,
    1.67  			     const char **vec, unsigned int len)
    1.68  {
    1.69 -	static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
    1.70  	char *str;
    1.71  	struct xenbus_transaction *xbt;
    1.72  	int err;
    1.73  
    1.74 +	if (shutting_down != SHUTDOWN_INVALID)
    1.75 +		goto out;
    1.76 +
    1.77   again:
    1.78  	xbt = xenbus_transaction_start();
    1.79  	if (IS_ERR(xbt))
    1.80 @@ -312,6 +319,7 @@ static void shutdown_handler(struct xenb
    1.81  
    1.82  	kfree(str);
    1.83  
    1.84 + out:
    1.85  	if (shutting_down != SHUTDOWN_INVALID)
    1.86  		schedule_work(&shutdown_work);
    1.87  }