Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for iSCSI.
  • Loading branch information
rwmjones committed May 10, 2013
1 parent 7a9ebd7 commit 8b27110
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fish/guestfish.pod
Expand Up @@ -1127,6 +1127,14 @@ The equivalent API command would be:

><fs> add /disk protocol:gluster server:tcp:example.com

=head2 B<-a iscsi://example.com[:port]/target-iqn-name[/lun]>

Add a disk located on an iSCSI server.

The equivalent API command would be:

><fs> add target-iqn-name/lun protocol:iscsi server:tcp:example.com

=head2 B<-a nbd://example.com[:port]>

=head2 B<-a nbd://example.com[:port]/exportname>
Expand Down
7 changes: 7 additions & 0 deletions generator/actions.ml
Expand Up @@ -1341,6 +1341,13 @@ The C<server> parameter must also be supplied - see below.
See also: L<guestfs(3)/GLUSTER>
=item C<protocol = \"iscsi\">
Connect to the iSCSI server.
The C<server> parameter must also be supplied - see below.
See also: L<guestfs(3)/ISCSI>.
=item C<protocol = \"nbd\">
Connect to the Network Block Device server.
Expand Down
70 changes: 70 additions & 0 deletions src/drives.c
Expand Up @@ -354,6 +354,53 @@ create_drive_ssh (guestfs_h *g,
use_cache_none);
}

static struct drive *
create_drive_iscsi (guestfs_h *g,
struct drive_server *servers, size_t nr_servers,
const char *exportname,
const char *username, const char *secret,
bool readonly, const char *format,
const char *iface, const char *name,
const char *disk_label,
bool use_cache_none)
{
if (username != NULL) {
error (g, _("iscsi: you cannot specify a username with this protocol"));
return NULL;
}

if (secret != NULL) {
error (g, _("iscsi: you cannot specify a secret with this protocol"));
return NULL;
}

if (nr_servers != 1) {
error (g, _("iscsi: you must specify exactly one server"));
return NULL;
}

if (servers[0].transport != drive_transport_none &&
servers[0].transport != drive_transport_tcp) {
error (g, _("iscsi: only tcp transport is supported"));
return NULL;
}

/* If the exportname begins with a '/', skip it. */
if (exportname[0] == '/')
exportname++;

if (STREQ (exportname, "")) {
error (g, _("iscsi: target name should not be an empty string"));
return NULL;
}

return create_drive_non_file (g, drive_protocol_iscsi,
servers, nr_servers, exportname,
username, secret,
readonly, format, iface, name, disk_label,
use_cache_none);
}

/* Traditionally you have been able to use /dev/null as a filename, as
* many times as you like. Ancient KVM (RHEL 5) cannot handle adding
* /dev/null readonly. qemu 1.2 + virtio-scsi segfaults when you use
Expand Down Expand Up @@ -818,6 +865,12 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
readonly, format, iface, name,
disk_label, false);
}
else if (STREQ (protocol, "iscsi")) {
drv = create_drive_iscsi (g, servers, nr_servers, filename,
username, secret,
readonly, format, iface, name,
disk_label, false);
}
else if (STREQ (protocol, "nbd")) {
drv = create_drive_nbd (g, servers, nr_servers, filename,
username, secret,
Expand Down Expand Up @@ -1100,6 +1153,23 @@ guestfs___drive_source_qemu_param (guestfs_h *g, const struct drive_source *src)
src->u.exportname, src->servers[0].u.socket);
}

case drive_protocol_iscsi: {
char *ret;

/* XXX quoting */
if (src->servers[0].port == 0)
ret = safe_asprintf (g, "iscsi://%s/%s",
src->servers[0].u.hostname,
src->u.exportname);
else
ret = safe_asprintf (g, "iscsi://%s:%d/%s",
src->servers[0].u.hostname,
src->servers[0].port,
src->u.exportname);

return ret;
}

case drive_protocol_nbd: {
CLEANUP_FREE char *p = NULL;
char *ret;
Expand Down
1 change: 1 addition & 0 deletions src/guestfs-internal.h
Expand Up @@ -116,6 +116,7 @@ struct event {
enum drive_protocol {
drive_protocol_file,
drive_protocol_gluster,
drive_protocol_iscsi,
drive_protocol_nbd,
drive_protocol_rbd,
drive_protocol_sheepdog,
Expand Down
18 changes: 18 additions & 0 deletions src/guestfs.pod
Expand Up @@ -680,6 +680,24 @@ single element. The single element is a string defining the Gluster
server. The format of this string is documented in
L</guestfs_add_drive_opts>.

=head3 ISCSI

Libguestfs can access iSCSI disks remotely.

To do this, set the optional C<protocol> and C<server> parameters like
this:

char **server = { "iscsi.example.org:3000", NULL };
guestfs_add_drive_opts (g, "target-iqn-name/lun",
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "iscsi",
GUESTFS_ADD_DRIVE_OPTS_SERVER, server,
-1);

The C<server> parameter is a list which must have a single element.
The single element is a string defining the iSCSI server. The format
of this string is documented in L</guestfs_add_drive_opts>.

=head3 NETWORK BLOCK DEVICE

Libguestfs can access Network Block Device (NBD) disks remotely.
Expand Down
3 changes: 3 additions & 0 deletions src/launch-libvirt.c
Expand Up @@ -1112,6 +1112,8 @@ construct_libvirt_xml_disk (guestfs_h *g,
*/
case drive_protocol_gluster:
protocol_str = "gluster"; goto network_protocols;
case drive_protocol_iscsi:
protocol_str = "iscsi"; goto network_protocols;
case drive_protocol_nbd:
protocol_str = "nbd"; goto network_protocols;
case drive_protocol_rbd:
Expand Down Expand Up @@ -1598,6 +1600,7 @@ make_drive_priv (guestfs_h *g, struct drive *drv,
break;

case drive_protocol_gluster:
case drive_protocol_iscsi:
case drive_protocol_nbd:
case drive_protocol_rbd:
case drive_protocol_sheepdog:
Expand Down

0 comments on commit 8b27110

Please sign in to comment.