+ struct add_disk_data *data = datavp;
+ /* Copy whole struct so we can make local changes: */
+ struct guestfs_add_drive_opts_argv optargs = data->optargs;
+ int readonly, error = 0, skip = 0;
+
+ if (readonly_in_xml) { /* <readonly/> appears in the XML */
+ if (data->readonly) { /* asked to add disk read-only */
+ switch (data->readonlydisk) {
+ case readonlydisk_error: readonly = 1; break;
+ case readonlydisk_read: readonly = 1; break;
+ case readonlydisk_write: readonly = 1; break;
+ case readonlydisk_ignore: skip = 1; break;
+ default: abort ();
+ }
+ } else { /* asked to add disk for read/write */
+ switch (data->readonlydisk) {
+ case readonlydisk_error: error = 1; break;
+ case readonlydisk_read: readonly = 1; break;
+ case readonlydisk_write: readonly = 0; break;
+ case readonlydisk_ignore: skip = 1; break;
+ default: abort ();
+ }
+ }
+ } else /* no <readonly/> in XML */
+ readonly = data->readonly;
+
+ if (skip)
+ return 0;
+
+ if (error) {
+ error (g, _("%s: disk is marked <readonly/> in libvirt XML, and readonlydisk was set to \"error\""),
+ filename);
+ return -1;
+ }
+
+ optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK;
+ optargs.readonly = readonly;