xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@entel.upc.edu>
To: xen-devel@lists.xensource.com
Subject: [PATCH 1 of 9 v2] xenbackendd: pass type of block device to hotplug script
Date: Fri, 18 Nov 2011 12:59:37 +0100	[thread overview]
Message-ID: <23578c9942bcc8767adc.1321617577@loki.upc.es> (raw)
In-Reply-To: <patchbomb.1321617576@loki.upc.es>

# HG changeset patch
# User Roger Pau Monne <roger.pau@entel.upc.edu>
# Date 1317386335 -7200
# Node ID 23578c9942bcc8767adc4e435bb1fd1cd89f5e18
# Parent  fd3567cafe1c7ccd0ddba0ad7fb067d435e13529
xenbackendd: pass type of block device to hotplug script

Pass the type of block device to attach to the block script instead
of reading it from xenstore, since new Xen versions don't make a
difference between a block device or an image.

Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu>

diff -r fd3567cafe1c -r 23578c9942bc tools/hotplug/NetBSD/block
--- a/tools/hotplug/NetBSD/block	Tue Nov 15 14:50:18 2011 +0100
+++ b/tools/hotplug/NetBSD/block	Fri Sep 30 14:38:55 2011 +0200
@@ -19,7 +19,7 @@ error() {
 
 xpath=$1
 xstatus=$2
-xtype=$(xenstore-read "$xpath/type")
+xtype=$3
 xparams=$(xenstore-read "$xpath/params")
 
 case $xstatus in
diff -r fd3567cafe1c -r 23578c9942bc tools/xenbackendd/xenbackendd.c
--- a/tools/xenbackendd/xenbackendd.c	Tue Nov 15 14:50:18 2011 +0100
+++ b/tools/xenbackendd/xenbackendd.c	Fri Sep 30 14:38:55 2011 +0200
@@ -89,15 +89,15 @@ dodebug(const char *fmt, ...)
 }
 
 static void
-doexec(const char *cmd, const char *arg1, const char *arg2)
+doexec(const char *cmd, const char *arg1, const char *arg2, const char *arg3)
 {
-	dodebug("exec %s %s %s", cmd, arg1, arg2);
+	dodebug("exec %s %s %s %s", cmd, arg1, arg2, arg3);
 	switch(vfork()) {
 	case -1:
 		dolog(LOG_ERR, "can't vfork: %s", strerror(errno));
 		break;
 	case 0:
-		execl(cmd, cmd, arg1, arg2, NULL);
+		execl(cmd, cmd, arg1, arg2, arg3, NULL);
 		dolog(LOG_ERR, "can't exec %s: %s", cmd, strerror(errno));
 		exit(EXIT_FAILURE);
 		/* NOTREACHED */
@@ -145,11 +145,14 @@ xen_setup(void)
 int
 main(int argc, char * const argv[])
 {
+	struct stat stab;
 	char **vec;
 	unsigned int num;
 	char *s;
 	int state;
 	char *sstate;
+	char *stype;
+	char *params;
 	char *p;
 	char buf[80];
 	int type;
@@ -297,11 +300,38 @@ main(int argc, char * const argv[])
 				    strerror(errno));
 				goto next2;
 			}
-			doexec(s, vec[XS_WATCH_PATH], sstate);
+			doexec(s, vec[XS_WATCH_PATH], sstate, NULL);
 			break;
 
 		case DEVTYPE_VBD:
-			doexec(vbd_script, vec[XS_WATCH_PATH], sstate);
+			/* check if given file is a block device or a raw image */
+			snprintf(buf, sizeof(buf), "%s/params", vec[XS_WATCH_PATH]);
+			params = xs_read(xs, XBT_NULL, buf, 0);
+			if(params == NULL) {
+				dolog(LOG_ERR,
+					"Failed to read %s (%s)", buf, strerror(errno));
+				goto next2;
+			}
+			if (stat(params, &stab) < 0) {
+				dolog(LOG_ERR,
+					"Failed to get info about %s (%s)", params,
+					strerror(errno));
+				goto next3;
+			}
+			stype = NULL;
+			if (S_ISBLK(stab.st_mode))
+				stype = "phy";
+			if (S_ISREG(stab.st_mode))
+				stype = "file";
+			if (stype == NULL) {
+				dolog(LOG_ERR,
+					"Failed to attach %s (not a block device or raw image)",
+					params, strerror(errno));
+				goto next3;
+			}
+			doexec(vbd_script, vec[XS_WATCH_PATH], sstate, stype);
+next3:
+			free(params);
 			break;
 
 		default:

  reply	other threads:[~2011-11-18 11:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-18 11:59 [PATCH 0 of 9 v2] libxl: add support for hotplug script calling from libxl Roger Pau Monne
2011-11-18 11:59 ` Roger Pau Monne [this message]
2011-11-18 11:59 ` [PATCH 2 of 9 v2] libxl: add support for image files for NetBSD Roger Pau Monne
2011-11-18 13:27   ` Ian Campbell
2011-11-18 14:49     ` Roger Pau Monné
2011-11-18 15:20       ` Ian Campbell
2011-11-18 11:59 ` [PATCH 3 of 9 v2] libxl: add libxl__forkexec function to libxl_exec Roger Pau Monne
2011-11-18 13:31   ` Ian Campbell
2011-11-18 14:50     ` Roger Pau Monné
2011-11-24 18:11   ` Ian Jackson
2011-12-01 14:29     ` Roger Pau Monné
2011-12-01 14:57       ` Ian Jackson
2011-11-18 11:59 ` [PATCH 4 of 9 v2] libxl: introduce libxl__wait_for_device_state Roger Pau Monne
2011-11-18 13:34   ` Ian Campbell
2011-11-18 11:59 ` [PATCH 5 of 9 v2] libxl: wait for devices to initialize upon addition to the domain Roger Pau Monne
2011-11-18 13:38   ` Ian Campbell
2011-11-18 14:58     ` Roger Pau Monné
2011-11-18 11:59 ` [PATCH 6 of 9 v2] libxl: execute hotplug scripts directly from libxl Roger Pau Monne
2011-11-18 13:42   ` Ian Campbell
2011-11-21 11:42     ` Roger Pau Monné
2011-11-21 14:36       ` Ian Campbell
2011-11-24 12:19   ` Ian Campbell
2011-12-01  8:44     ` Roger Pau Monné
2011-11-18 11:59 ` [PATCH 7 of 9 v2] hotplug NetBSD: detach devices when state is 5 or 6 Roger Pau Monne
2011-11-18 11:59 ` [PATCH 8 of 9 v2] hotplug: remove debug messages from NetBSD hotplug scripts Roger Pau Monne
2011-11-18 11:59 ` [PATCH 9 of 9 v2] rc.d NetBSD: don't start xenbackendd by default, only when xend needs it Roger Pau Monne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23578c9942bcc8767adc.1321617577@loki.upc.es \
    --to=roger.pau@entel.upc.edu \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).