mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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"
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user