Two more states for the Xenbus: Suspend/Resume
PATCH 1/1 Two more states for the Xenbus: Suspend/Resume
The attached patch adds two more states to the xenbus state machine for notifying the backend about suspending and resuming of a frontend. Without these explicit states a backend driver does currently not know whether a frontend is disappearing due to a suspend or because the domain has been shut down/killed. The same is true for the appearing of a front-end driver due to either creation of a domain or resumption. For some backend drivers and hotplug scripts it is useful to know about the actual reason, though.
I have made the necessary modifications to the block, network and TPM device drivers. The block and network drivers ignore this additional state.
xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c +2 -0
@@ -257,6 +257,8 @@ static void frontend_changed(struct xenbswitch (frontend_state) {case XenbusStateInitialising:case XenbusStateConnected: +case XenbusStateSuspend: +case XenbusStateResume:break ;case XenbusStateInitialised:
xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +2 -0
@@ -273,6 +273,8 @@ static void backend_changed(struct xenbucase XenbusStateInitWait:case XenbusStateInitialised:case XenbusStateClosed: +case XenbusStateSuspend: +case XenbusStateResume:break ;case XenbusStateConnected:
xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c +2 -0
@@ -205,6 +205,8 @@ static void frontend_changed(struct xenbswitch (frontend_state) {case XenbusStateInitialising:case XenbusStateInitialised: +case XenbusStateSuspend: +case XenbusStateResume:break ;case XenbusStateConnected:
xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c +2 -0
@@ -402,6 +402,8 @@ static void backend_changed(struct xenbucase XenbusStateConnected:case XenbusStateUnknown:case XenbusStateClosed: +case XenbusStateSuspend: +case XenbusStateResume:break ;case XenbusStateClosing:
xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c +38 -0
@@ -31,6 +31,7 @@ struct backend_infolong int frontend_id;long int instance;// instance of TPM u8 is_instance_set;// whether instance number has been set +u8 is_suspending;/* watch front end for changes */ struct xenbus_watch backend_watch;
@@ -99,6 +100,30 @@ fail:return err; } +static int tpmback_hotplug (struct xenbus_device *xdev,char **envp, +int num_envp,char *buffer,int buffer_size) +{ +struct backend_info *be = xdev->data; +int i =0 ; +int length =0 ; +int idx =0 ; +static const char *reason[2 ] = + {"REASON=hibernate" , +"REASON=create" }; + +if (be->frontend_state != XenbusStateSuspend && + be->frontend_state != XenbusStateResume) { + idx =1 ; + } + +add_hotplug_env_var (envp, num_envp, &i, + buffer, buffer_size, &length, + reason[idx]); + + envp[i] =NULL ; +return 0 ; +} +static void backend_changed (struct xenbus_watch *watch,const char **vec,unsigned int len)
@@ -173,6 +204,8 @@ static void frontend_changed(struct xenbif (err) {return ; } +if (be->is_suspending ==0 ) +kobject_hotplug (&dev->dev.kobj,KOBJ_ONLINE );maybe_connect (be);break ;
@@ -180,6 +213,16 @@ static void frontend_changed(struct xenbxenbus_switch_state (dev,NULL , XenbusStateClosing);break ; +case XenbusStateSuspend: + be->is_suspending =1 ; +kobject_hotplug (&dev->dev.kobj,KOBJ_OFFLINE ); +break ; + +case XenbusStateResume: + be->is_suspending =1 ; +kobject_hotplug (&dev->dev.kobj,KOBJ_ONLINE ); +break ; +case XenbusStateClosed:/* * Notify the vTPM manager about the front-end
@@ -309,6 +352,7 @@ static struct xenbus_driver tpmback = { .ids = tpmback_ids, .probe = tpmback_probe, .remove = tpmback_remove, + .hotplug = tpmback_hotplug, .otherend_changed = frontend_changed, };
xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +3 -0
@@ -802,6 +802,7 @@ static int suspend_dev(struct device *deif (err)printk (KERN_WARNING "xenbus: suspend %s failed: %i\n" , dev->bus_id, err); +xenbus_switch_state (xdev,NULL , XenbusStateSuspend);return 0 ; }
@@ -826,6 +827,8 @@ static int resume_dev(struct device *devreturn err; } +xenbus_switch_state (xdev,NULL , XenbusStateResume); +if (drv->resume) err = drv->resume (xdev);if (err)
xen-unstable.hg/xen/include/public/io/xenbus.h +3 -1
@@ -26,7 +26,9 @@ typedef enum XenbusStateConnected =4 , XenbusStateClosing =5 ,/* The device is being closed due to an error or an unplug event. */ - XenbusStateClosed = 6 + XenbusStateClosed =6 , + XenbusStateSuspend =7 , + XenbusStateResume = 8 } XenbusState;
xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c +2 -0
@@ -338,6 +338,8 @@ static void backend_changed(struct xenbucase XenbusStateInitWait:case XenbusStateInitialised:case XenbusStateUnknown: +case XenbusStateSuspend: +case XenbusStateResume:break ;case XenbusStateConnected:
xen-unstable.hg/tools/examples/vtpm +6 -6
@@ -5,18 +5,18 @@ dir=$(dirname "$0") case "$command" in - online | offline) - exit 0 - ;; -esac - -case "$command" in add) vtpm_create_instance ;; + online) + vtpm_create_instance + ;; remove) vtpm_remove_instance ;; + offline) + vtpm_remove_instance + ;; esac log debug "Successful vTPM operation '$command'."
xen-unstable.hg/tools/examples/vtpm-common.sh +2 -1
@@ -256,7 +256,8 @@ function vtpm_create_instance () { vtpm_setup $instance else #default case for 'now' - vtpm_reset $instance + #vtpm_reset $instance + true fi xenstore_write $XENBUS_PATH/instance $instance set -e
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel