forked from xapi-project/xen-api
/
block
executable file
·83 lines (67 loc) · 1.58 KB
/
block
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
TYPE=`echo ${XENBUS_PATH} | cut -f 2 -d '/'`
DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
DEVNAME=$TYPE-$DOMID-$DEVID
SYSFS_PATH=/sys/devices/xen-backend/$DEVNAME
XAPI=/xapi/${DOMID}/hotplug/${TYPE}/${DEVID}
HOTPLUG="${XAPI}/hotplug"
KTHREAD_PID="${XENBUS_PATH}/kthread-pid"
PAUSE="${XENBUS_PATH}/pause"
PAUSE_DONE="${XENBUS_PATH}/pause-done"
SHUTDOWN="${XENBUS_PATH}/shutdown-request"
SHUTDOWN_DONE="${XENBUS_PATH}/shutdown-done"
syslog ()
{
logger -pdaemon.info -tscripts-block -- "$DEVNAME[$ACTION]: $*"
}
case "$ACTION" in
add)
syslog "writing $HOTPLUG = online"
xenstore write "$HOTPLUG" "online"
# RUNNING (1<<0)
# PAUSE_DONE (1<<1)
# SHUTDOWN_DONE (1<<2)
# PAUSE_REQUEST (1<<3)
# SHUTDOWN_REQUEST (1<<4)
# echo $(((1<<1) | (1<<3))) > $SYSFS_PATH/queue_events # unpaused|paused
;;
change)
if pid=$(xenstore read "$KTHREAD_PID" 2>/dev/null)
then
state=running
else
state=stopped
fi
syslog "kthread-pid = '$pid'"
case "$state" in
stopped)
if xenstore exists "$PAUSE"
then
syslog "writing $PAUSE_DONE"
xenstore write "$PAUSE_DONE" ""
fi
if xenstore exists "$SHUTDOWN"
then
syslog "writing $SHUTDOWN_DONE"
xenstore write "$SHUTDOWN_DONE" ""
fi
;;
running)
if xenstore exists "$PAUSE_DONE"
then
syslog "removing $PAUSE_DONE"
xenstore rm "$PAUSE_DONE"
fi
if xenstore exists "$SHUTDOWN_DONE"
then
syslog "WARNING: queue restart in shutdown state."
fi
;;
esac
;;
remove)
syslog "removing $HOTPLUG"
xenstore rm "$HOTPLUG"
;;
esac