Skip to contentSkip to conversation

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

PATCH In review Roger Pau Monne 3 participants 4 messages Aug 14, 2012 – Aug 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v4 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 v3:

* Add $xparams (that contains the path to the disk file) to the error message.

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..f849fe4 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 "$xpath/params is empty, unable to attach block device."
+else
+	error "$xparams is not a valid file type to use as 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

Fine with me.
Christoph

Quoted 63 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 v3:

* Add $xparams (that contains the path to the disk file) to the error message.

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..f849fe4 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 "$xpath/params is empty, unable to attach block device."
+else
+	error "$xparams is not a valid file type to use as block device." \
+	      "Only block and regular image files accepted."
+fi
 
 case $xstatus in
 6)
Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#2 lore raw
In reply to Roger Pau Monne
Quoted 1 line · Roger Pau Monne

Changes since v2:

[...]

Quoted 1 line

* Replace xenstore_write with xenstore-write in error function.

[...]

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

Quoted 6 lines

error() {

tools/hotplug/NetBSD/block +1 -1
 	echo "$@" >&2
-	xenstore_write $xpath/hotplug-status error
+	xenstore-write $xpath/hotplug-status error
 	exit 1
 }

Why this seemingly unrelated change? I don't see anything in the comments on v2 explicitly about it.

If it is somehow necessary due to this patch then I think that deserves mention in the changelog proper.

Is it because xenstore_write is actually specific to the Linux hotplug scripts? (i.e. this function was just plain broken before).

While looking into this I noticed that the Linux equivalent to error() is:

        fatal() {
          _xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \
                          "$XENBUS_PATH/hotplug-status" error
          log err "$@"
          exit 1
        }

The write of the log message to hotplus-error seems like something worth replicating (in a separate patch).

I also wonder how much of this sort of infrastructure could actually be shared, but that's for another time.

Ian.

#3 lore raw
Quoted 5 lines · Ian Campbell
Quoted 1 line · Roger Pau Monne

Changes since v2:

[...]

Quoted 1 line

* Replace xenstore_write with xenstore-write in error function.

[...]

Quoted 9 lines

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

Quoted 6 lines

error() {

tools/hotplug/NetBSD/block +1 -1
 	echo "$@" >&2
-	xenstore_write $xpath/hotplug-status error
+	xenstore-write $xpath/hotplug-status error
 	exit 1
 }

Why this seemingly unrelated change? I don't see anything in the comments on v2 explicitly about it.

xenstore-write exists on NetBSD. xenstore_write does not exist.

Christoph

Quoted 25 lines

If it is somehow necessary due to this patch then I think that deserves mention in the changelog proper.

Is it because xenstore_write is actually specific to the Linux hotplug scripts? (i.e. this function was just plain broken before).

While looking into this I noticed that the Linux equivalent to error() is:

        fatal() {
          _xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \
                          "$XENBUS_PATH/hotplug-status" error
          log err "$@"
          exit 1
        }

The write of the log message to hotplus-error seems like something worth replicating (in a separate patch).

I also wonder how much of this sort of infrastructure could actually be shared, but that's for another time.

Ian.

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632