Skip to contentSkip to conversation

hotplug/NetBSD: check type of file to attach from params

PATCH Superseded Roger Pau Monne 2 participants 3 messages Aug 14, 2012

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 hotplug/NetBSD: check type of file to attach from params

xend used to set the xenbus backend entry "type" to either "phy" or "file", but now libxl sets it to "phy" for both file and block device. We have to manually check for the type of the "param" field in order to detect if we are trying to attach a file or a block device.

---
Changes since v2:

* Better error messages.

* Check if params is empty.

* Replace xenstore_write with xenstore-write in error function.

* Add quotation marks to xparams when testing.

Changes since v1:

* Check that file is either a block special file or a regular file and report error otherwise.

---
 tools/hotplug/NetBSD/block |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
tools/hotplug/NetBSD/block +11 -2
index cf5ff3a..5ffc334 100644
@@ -12,15 +12,24 @@ export PATH
 
 error() {
 	echo "$@" >&2
-	xenstore_write $xpath/hotplug-status error
+	xenstore-write $xpath/hotplug-status error
 	exit 1
 }
 	
 
 xpath=$1
 xstatus=$2
-xtype=$(xenstore-read "$xpath/type")
 xparams=$(xenstore-read "$xpath/params")
+if [ -b "$xparams" ]; then
+	xtype="phy"
+elif [ -f "$xparams" ]; then
+	xtype="file"
+elif [ -z "$xparams" ]; then
+	error "No image or block device found in $xpath/params"
+else
+	error "Invalid file type for block device." \
+	      "Only block and regular image files accepted."
+fi
 
 case $xstatus in
 6)
Signature · 1 line
1.7.7.5 (Apple Git-26)
#1 lore raw
Quoted 44 lines · Roger Pau Monne

xend used to set the xenbus backend entry "type" to either "phy" or "file", but now libxl sets it to "phy" for both file and block device. We have to manually check for the type of the "param" field in order to detect if we are trying to attach a file or a block device.

---
Changes since v2:

* Better error messages.

* Check if params is empty.

* Replace xenstore_write with xenstore-write in error function.

* Add quotation marks to xparams when testing.

Changes since v1:

* Check that file is either a block special file or a regular file and report error otherwise.

---
 tools/hotplug/NetBSD/block |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
tools/hotplug/NetBSD/block +1 -2
index cf5ff3a..5ffc334 100644
@@ -12,15 +12,24 @@ export PATH
 
 error() {
 	echo "$@" >&2
-	xenstore_write $xpath/hotplug-status error
+	xenstore-write $xpath/hotplug-status error
 	exit 1
 }
 
 
 xpath=$1
 xstatus=$2
-xtype=$(xenstore-read "$xpath/type")

tools/hotplug/NetBSD/block export PATH · line 31

Quoted 10 lines
tools/hotplug/NetBSD/block +9 -0
 xparams=$(xenstore-read "$xpath/params")
+if [ -b "$xparams" ]; then
+	xtype="phy"
+elif [ -f "$xparams" ]; then
+	xtype="file"
+elif [ -z "$xparams" ]; then
+	error "No image or block device found in $xpath/params"
+else
+	error "Invalid file type for block device." \
+	      "Only block and regular image files accepted."

Perhaps include $xparams in here somewhere? Perhaps $xpath too?

Quoted 4 lines
tools/hotplug/NetBSD/block +1 -0
+fi
 
 case $xstatus in
 6)
#2 lore raw
Quoted 42 lines · Ian Campbell
Quoted 41 lines · Roger Pau Monne

xend used to set the xenbus backend entry "type" to either "phy" or "file", but now libxl sets it to "phy" for both file and block device. We have to manually check for the type of the "param" field in order to detect if we are trying to attach a file or a block device.

---
Changes since v2:

* Better error messages.

* Check if params is empty.

* Replace xenstore_write with xenstore-write in error function.

* Add quotation marks to xparams when testing.

Changes since v1:

* Check that file is either a block special file or a regular file and report error otherwise.

---
 tools/hotplug/NetBSD/block |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
tools/hotplug/NetBSD/block +1 -1
index cf5ff3a..5ffc334 100644
@@ -12,15 +12,24 @@ export PATH
 
 error() {
 	echo "$@" >&2
-	xenstore_write $xpath/hotplug-status error
+	xenstore-write $xpath/hotplug-status error
 	exit 1
 }
 
 
Quoted 15 lines

tools/hotplug/NetBSD/block export PATH · line 31

Quoted 13 lines
tools/hotplug/NetBSD/block +9 -1
 xpath=$1
 xstatus=$2
-xtype=$(xenstore-read "$xpath/type")
 xparams=$(xenstore-read "$xpath/params")
+if [ -b "$xparams" ]; then
+	xtype="phy"
+elif [ -f "$xparams" ]; then
+	xtype="file"
+elif [ -z "$xparams" ]; then
+	error "No image or block device found in $xpath/params"
+else
+	error "Invalid file type for block device." \
+	      "Only block and regular image files accepted."

Perhaps include $xparams in here somewhere? Perhaps $xpath too?

Thanks for the review.

I think including $xparams should be enough (since it is not null).