summaryrefslogtreecommitdiffstats
path: root/fish
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-11-23 13:16:01 +0000
committerRichard W.M. Jones <rjones@redhat.com>2010-11-25 15:40:56 +0000
commit70faafe8d4f0c06c3e62c1e1469289255ee30c53 (patch)
treee18090adb68cb3bade62a3f25e58925a1376cdb2 /fish
parentdfa9d6cf32b23e34eeba916a9a263483990a3fce (diff)
downloadlibguestfs-70faafe8d4f0c06c3e62c1e1469289255ee30c53.tar.gz
libguestfs-70faafe8d4f0c06c3e62c1e1469289255ee30c53.tar.xz
libguestfs-70faafe8d4f0c06c3e62c1e1469289255ee30c53.zip
fish: Keep device names in options drives list.
In the 'struct drv *drvs' structure, keep a list of the device name(s) for each added drive or guest. The device name is the canonical name as that drive would be known inside libguestfs, eg. "/dev/sda"
Diffstat (limited to 'fish')
-rw-r--r--fish/fish.c5
-rw-r--r--fish/options.c16
-rw-r--r--fish/options.h15
3 files changed, 27 insertions, 9 deletions
diff --git a/fish/fish.c b/fish/fish.c
index 5d7aac6a..c1dbfb4d 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -339,6 +339,8 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
drv->type = drv_N;
+ drv->device = NULL;
+ drv->nr_drives = -1;
if (asprintf (&drv->N.filename, "test%d.img",
next_prepared_drive++) == -1) {
perror ("asprintf");
@@ -346,7 +348,6 @@ main (int argc, char *argv[])
}
drv->N.data = create_prepared_file (optarg, drv->N.filename);
drv->N.data_free = free_prep_data;
- drv->N.device = NULL; /* filled in by add_drives */
drv->next = drvs;
drvs = drv;
break;
@@ -554,7 +555,7 @@ prepare_drives (struct drv *drv)
if (drv) {
prepare_drives (drv->next);
if (drv->type == drv_N)
- prepare_drive (drv->N.filename, drv->N.data, drv->N.device);
+ prepare_drive (drv->N.filename, drv->N.data, drv->device);
}
}
diff --git a/fish/options.c b/fish/options.c
index 55bcf687..436e10d8 100644
--- a/fish/options.c
+++ b/fish/options.c
@@ -41,6 +41,11 @@ add_drives (struct drv *drv, char next_drive)
if (drv) {
next_drive = add_drives (drv->next, next_drive);
+ if (asprintf (&drv->device, "/dev/sd%c", next_drive) == -1) {
+ perror ("asprintf");
+ exit (EXIT_FAILURE);
+ }
+
switch (drv->type) {
case drv_a:
ad_optargs.bitmask = 0;
@@ -56,6 +61,7 @@ add_drives (struct drv *drv, char next_drive)
if (r == -1)
exit (EXIT_FAILURE);
+ drv->nr_drives = 1;
next_drive++;
break;
@@ -64,6 +70,7 @@ add_drives (struct drv *drv, char next_drive)
if (r == -1)
exit (EXIT_FAILURE);
+ drv->nr_drives = r;
next_drive += r;
break;
@@ -78,11 +85,7 @@ add_drives (struct drv *drv, char next_drive)
if (r == -1)
exit (EXIT_FAILURE);
- if (asprintf (&drv->N.device, "/dev/sd%c", next_drive) == -1) {
- perror ("asprintf");
- exit (EXIT_FAILURE);
- }
-
+ drv->nr_drives = 1;
next_drive++;
break;
@@ -133,12 +136,13 @@ free_drives (struct drv *drv)
if (!drv) return;
free_drives (drv->next);
+ free (drv->device);
+
switch (drv->type) {
case drv_a: /* a.filename and a.format are optargs, don't free them */ break;
case drv_d: /* d.filename is optarg, don't free it */ break;
case drv_N:
free (drv->N.filename);
- free (drv->N.device);
drv->N.data_free (drv->N.data);
break;
default: ; /* keep GCC happy */
diff --git a/fish/options.h b/fish/options.h
index 155aad89..728df04a 100644
--- a/fish/options.h
+++ b/fish/options.h
@@ -77,6 +77,16 @@ extern const char *program_name;
/* List of drives added via -a, -d or -N options. */
struct drv {
struct drv *next;
+
+ char *device; /* Device name inside the appliance (eg. /dev/sda).
+ * This is filled in when we add the drives in
+ * add_drives. Note that guests (-d option) may
+ * have multiple drives, in which case this is the
+ * first drive, and nr_drives is the number of
+ * drives used.
+ */
+ int nr_drives; /* number of drives for this guest */
+
enum { drv_a, drv_d, drv_N } type;
union {
struct {
@@ -90,7 +100,6 @@ struct drv {
char *filename; /* disk filename (testX.img) */
void *data; /* prepared type */
void (*data_free)(void*); /* function to free 'data' */
- char *device; /* device inside the appliance */
} N;
};
};
@@ -131,6 +140,8 @@ extern int add_libvirt_drives (const char *guest);
exit (EXIT_FAILURE); \
} \
drv->type = drv_a; \
+ drv->device = NULL; \
+ drv->nr_drives = -1; \
drv->a.filename = optarg; \
drv->a.format = format; \
drv->next = drvs; \
@@ -146,6 +157,8 @@ extern int add_libvirt_drives (const char *guest);
exit (EXIT_FAILURE); \
} \
drv->type = drv_d; \
+ drv->device = NULL; \
+ drv->nr_drives = -1; \
drv->d.guest = optarg; \
drv->next = drvs; \
drvs = drv