summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README148
-rw-r--r--doc/iscsiadm.828
-rw-r--r--usr/idbm.c2
-rw-r--r--usr/iscsiadm.c180
4 files changed, 281 insertions, 77 deletions
diff --git a/README b/README
index 558058c..07468f5 100644
--- a/README
+++ b/README
@@ -178,18 +178,33 @@ For help, run:
Usage: iscsiadm [OPTION]
- -m, --mode <op> specify operational mode op = <discovery|node>
- -m discovery --type=[type] --interface=iscsi_ifacename \
- --portal=[ip:port] --login --print=[N] \
- --op=[op]=[NEW | UPDATE | DELETE | NONPERSISTENT]
- perform [type] discovery for target portal with
- ip-address [ip] and port [port].
-
- This command will not use the discovery record
- settings. It will use the iscsid.conf discovery
- settings and it will overwrite the discovery
- record with iscsid.conf discovery settings if it
- exists. By default, it will then remove records for
+ -m, --mode <op> specify operational mode op = <discovery2|node>
+ -m discovery2 --type=[type] --portal=[ip:port] --print=[N] \
+ [ --op=[op]=[NEW | DELETE | NONPERSISTENT] |
+ --op=UPDATE -n name -v value ]
+
+ Perform DB operation specified by --op on
+ the discovery record specified by
+ type=type and portal=[ip:port].
+
+ Note: op=NEW will create a new discovery record
+ using the iscsid.conf discovery settings. If it
+ already exists, it will be overwritten using
+ iscsid.conf discovery settings.
+
+ op=DELETE will delete the discovery record
+ and records for the targets found through
+ that discovery source.
+ -m discovery --interface=[iface...] --portal=[ip:port] --print=[N] \
+ --op=[op]=[NEW | UPDATE | DELETE | NONPERSISTENT] \ --discover
+
+ This command will use the discovery record settings
+ matching the record with type=type and
+ portal=ip:port]. If a record does not exist, it will
+ create a record using the iscsid.conf discovery
+ settings.
+
+ By default, it will then remove records for
portals no longer returned. And,
if a portal is returned by the target, then the
discovery command will create a new record or modify
@@ -223,11 +238,6 @@ Usage: iscsiadm [OPTION]
software iscsi or override the system defaults.
Multiple ifaces can be passed in during discovery.
- -m discovery --print=[N] display all discovery records from internal
- persistent discovery database.
- -m discovery --interface --portal=[ip:port] --print=[N] --discover
- perform discovery based on portal in database. See
- above for info in the interface argument.
For the above commands "print" is optional. If
used, N can be 0 or 1.
@@ -235,10 +245,11 @@ Usage: iscsiadm [OPTION]
1 = The tree style with the inteface info is used.
If print is not used the old flay style is used.
- -m discovery --interface --portal=[ip:port] --print=[N] --login
+ -m discovery --interface=[iface...] --portal=[ip:port] --print=[N] \
+ --op=[op]=[NEW | UPDATE | DELETE | NONPERSISTENT] \ --discover --login
perform discovery based on portal in database, and
log into portals found during discovery. See
- above for info in the interface argument.
+ above for info in the interface and op arguments.
For the above commands "print" is optional. If
used, N can be 0 or 1.
@@ -512,13 +523,13 @@ will not be tcp.
For example if you had defined two interface but only wanted to use one
you can use the --interface/-I argument:
-iscsiadm -m discovery -t st -p ip:port -I iface1 -P 1
+iscsiadm -m discovery2 -t st -p ip:port -I iface1 --discover -P 1
If you had defined interfaces but wanted the old behavior, where
we do not bind a session to a iface, then you can use the special iface
"default":
-iscsiadm -m discovery -t st -p ip:port -I default -P 1
+iscsiadm -m discovery2 -t st -p ip:port -I default --discover -P 1
And if you did not define any interfaces in /etc/iscsi/ifaces and do
not pass anything into iscsiadm, running iscsiadm will do the default
@@ -556,29 +567,38 @@ To now log into targets it is the same as with sofware iscsi. See section
Discovery mode:
- - SendTargets iSCSI Discovery using the default driver and interface:
+ - SendTargets iSCSI Discovery using the default driver and interface and
+ using the discovery settings for the discovery record with the
+ ID [192.168.1.1:3260].
+
+ ./iscsiadm -m discovery2 -t st -p 192.168.1.1:3260 --discover
- ./iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260
+ This will search /etc/iscsi/send_targets for a record with the
+ ID [portal = 192.168.1.1:3260 and type = sendtargets. If found it
+ will perform discovery using the settings stored in the record.
+ If a record does not exist, it will be created using the iscsid.conf
+ discovery settings.
- This will first search /etc/iscsi/ifaces for interfaces
- using software iscsi. If any are found then nodes found during
- discovery will be setup so that they can logged in through
- those interfaces.
+ For the ifaces, iscsiadm will first search /etc/iscsi/ifaces for
+ interfaces using software iscsi. If any are found then nodes found
+ during discovery will be setup so that they can logged in through
+ those interfaces. To specify a specific iface, pass the
+ -I argument for each iface.
- - SendTargets iSCSI Discovery updating existing records:
+ - SendTargets iSCSI Discovery updating existing target records:
- ./iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260 \
- -o update
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 \
+ -o update --discover
- If there a record for targetX and portalY exists in the DB, and
+ If there is a record for targetX and portalY exists in the DB, and
is returned during discovery, it will be updated with the info
from the iscsi.conf. No new portals will be added and stale
portals will not be removed.
- - SendTargets iSCSI Discovery deleting existing records:
+ - SendTargets iSCSI Discovery deleting existing target records:
- ./iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260 \
- -o delete
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 \
+ -o delete --discover
If there a record for targetX and portalY exists in the DB, but
is not returned during discovery it will be removed from the DB.
@@ -591,8 +611,8 @@ To now log into targets it is the same as with sofware iscsi. See section
- SendTargets iSCSI Discovery adding new records:
- ./iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260 \
- -o new
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 \
+ -o new --discover
If there targetX and portalY is returned during discovery and does
not have a record, it will be added. Existing records are not
@@ -600,8 +620,8 @@ To now log into targets it is the same as with sofware iscsi. See section
- SendTargets iSCSI Discovery using multiple ops:
- ./iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260 \
- -o new -o delete
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 \
+ -o new -o delete --discover
This command will add new portals and delete records for portals
no longer returned. It will not change the record information for
@@ -609,8 +629,8 @@ To now log into targets it is the same as with sofware iscsi. See section
- SendTargets iSCSI Discovery in nonpersistent mode:
- ./iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260 \
- -o nonpersistent
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 \
+ -o nonpersistent --discover
This command will perform discovery, but not manipulate the node DB.
@@ -618,8 +638,8 @@ To now log into targets it is the same as with sofware iscsi. See section
wish to only use a subset of the interfaces in /etc/iscsi/ifaces
then you can pass them in during discovery:
- ./iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260 \
- --interface=iface0 --interface=iface1
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 \
+ --interface=iface0 --interface=iface1 --discover
Note that for software iscsi, we let the network layer select
which NIC to use for discovery, but for later logins iscsiadm
@@ -629,22 +649,26 @@ To now log into targets it is the same as with sofware iscsi. See section
the record info in the card's FLASH or the node DB, so you must
rerun discovery every time the driver is reloaded.
- - SendTargets iSCSI Discovery using the default driver and interface and
- using the discovery settings for the discovery record with the
- ID [192.168.1.1:3260].
+ - Manipulate SendTargets DB.
- ./iscsiadm -m discovery -p 192.168.1.1:3260 --discover
+ Create new SendTargets discovery record or overwrite an existing
+ discovery record with iscsid.conf discovery settings.
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 -o new
- This will search /etc/iscsi/send_targets for a record with the
- ID [192.168.1.1:3260]. If found it will perform discovery using
- the settings stored in the record. For the ifaces,
- This will first search /etc/iscsi/ifaces for interfaces
- using software iscsi. If any are found then nodes found during
- discovery will be setup so that they can logged in through
- those interfaces.
-
- This command also accepts the -o new, delete and update settings
- like above.
+ See discovery settings.
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 -o show
+
+ See hidden discovery settings like CHAP passwords
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 \
+ -o show --show
+
+ Set discovery setting.
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 \
+ -o update -n name -v value
+
+ Delete discovery record. This will also delete the records for
+ the targets found through the discovery source.
+ ./iscsiadm -m discovery2 -t sendtargets -p 192.168.1.1:3260 -o delete
Node mode. In node mode you can specify which records you want to log
into by specifying the targetname, ip address, port or interface
@@ -778,10 +802,6 @@ To now log into targets it is the same as with sofware iscsi. See section
./iscsiadm -m discovery -P 1
- - Display discovery record setting:
-
- ./iscsiadm -m discovery -p 192.168.0.4:3260
-
- Display session statistics:
./iscsiadm -m session -r 1 --stats
@@ -968,19 +988,19 @@ In this example we would run
Once the iSCSI service is running, you can perform discovery using
SendTarget with:
-iscsiadm -m discovery -t sendtargets -p ip:port
+iscsiadm -m discovery2 -t sendtargets -p ip:port --discover
where "ip" is the address of the portal and port is the port.
To use iSNS you can run the discovery command with the type as "isns"
and pass in the ip:port:
-iscsiadm -m discovery -t isns -p ip:port
+iscsiadm -m discovery2 -t isns -p ip:port --discover
Both commands will print out the list of all discovered targets and their
portals:
-# iscsiadm -m discovery -t st -p 10.15.85.19:3260
+# iscsiadm -m discovery2 -t st -p 10.15.85.19:3260 --discover
10.15.84.19:3260,2 iqn.1992-08.com.netapp:sn.33615311
10.15.85.19:3260,3 iqn.1992-08.com.netapp:sn.33615311
@@ -995,7 +1015,7 @@ is iqn.1992-08.com.netapp:sn.33615311.
If you would also like to see the iscsi inteface which will be used
for each session then use the --print[N] option.
-iscsiadm -m discovery -t sendtargets -p ip:port -P 1
+iscsiadm -m discovery2 -t sendtargets -p ip:port -P 1 --discover
will print:
Target: iqn.1992-08.com.netapp:sn.33615311
diff --git a/doc/iscsiadm.8 b/doc/iscsiadm.8
index c46cd59..66bf3c1 100644
--- a/doc/iscsiadm.8
+++ b/doc/iscsiadm.8
@@ -2,8 +2,8 @@
.SH NAME
iscsiadm \- open-iscsi administration utility
.SH SYNOPSIS
-\fBiscsiadm\fR \-m discovery [ \-hV ] [ \-d debug_level ] [ \-P printlevel ] [ \-I iface \-t type \-p ip:port [ \-l ] ] | [ [ -p ip:port ] \
-[ \-o operation ] [ \-n name ] [ \-v value ] [ \-l | \-D ] ]
+\fBiscsiadm\fR \-m discovery2 [ \-hV ] [ \-d debug_level ] [ \-P printlevel ] [ \-I iface \-t type \-p ip:port [ \-lD ] ] | [ [ -p ip:port -t type ] \
+[ \-o operation ] [ \-n name ] [ \-v value ] [ \-lD ] ]
\fBiscsiadm\fR \-m node [ \-hV ] [ \-d debug_level ] [ \-P printlevel ] [ \-L all,manual,automatic ] [ \-U all,manual,automatic ] [ \-S ] [ [ \-T targetname \-p ip:port \-I iface ] [ \-l | \-u | \-R | \-s] ]
@@ -74,7 +74,7 @@ are experimental and the use is not supported as a stable interface yet.
In discovery mode multiple interfaces can be specified by passing in multiple
\-I/\-\-interface instances. For example,
-"iscsiadm \-m discovery \-t st \-p mytarget \-I iface0 \-I iface2"
+"iscsiadm \-m discovery2 \-t st \-p ip:port \-I iface0 \-I iface2 --discover"
Will direct iscsiadm to setup the node db to create records which will create
sessions though the two intefaces passed in.
@@ -93,8 +93,12 @@ is an error while iscsid is not running, the system may not be able to recover.
This command and iscsid's SIGTERM handling are experimental.
.TP
-\fB\-l\fR, \fB\-\-discover\fR
-Discover targets using discovery record info.
+\fB\-D\fR, \fB\-\-discover\fR
+Discover targets using the discovery record with the \fIrecid\fR matching
+the the discovery type and portal passed in. If there is no matching record,
+it will be created using the iscsid.conf discovery settings.
+This must be passed in \fIdiscovery2\fR mode to instruct iscsiadm to perform
+discovery.
.IP
This option is only valid for SendTargets discovery mode.
@@ -117,9 +121,9 @@ for session mode).
.TP
\fB\-m, \-\-mode \fIop\fR
specify the mode. \fIop\fR
-must be one of \fIdiscovery\fR, \fInode\fR, \fIfw\fR, \fIhost\fR \fIiface\fR or \fIsession\fR.
+must be one of \fIdiscovery2\fR, \fInode\fR, \fIfw\fR, \fIhost\fR \fIiface\fR or \fIsession\fR.
.IP
-If no other options are specified: for \fIdiscovery\fR and \fInode\fR, all
+If no other options are specified: for \fIdiscovery2\fR and \fInode\fR, all
of their respective records are displayed; for \fIsession\fR, all active
sessions and connections are displayed; for \fIfw\fR, all boot firmware
values are displayed; for \fIhost\fR, all iSCSI hosts are displayed; and
@@ -139,7 +143,13 @@ Specifies a database operator \fIop\fR. \fIop\fR must be one of
This option is valid for all modes except fw. Delete should not be used on a running session. If it is iscsiadm will stop the session and then delete the
record.
.IP
-\fInew\fR creates a new database record for a given \fIportal\fR (IP address and port number). In discovery mode, iscsiadm will create new records for portals returned by the target.
+\fInew\fR creates a new database record for a given object. In node mode, the
+\fIrecid\fR is the target name and portal (IP:port). In iface mode, the \fIrecid\fR
+is the iface name. In discovery mode, the \fIrecid\fR is the portal and
+discovery type.
+
+.IP
+In discovery mode, if the \fIrecid\fR and new operation is passed in, but the \fI--discover\fR argument is not, then iscsiadm will only create a discovery record (it will not perform discovery). If the \fI--discover\fR argument is passed in with the portal and discovery type, then iscsiadm will create the discovery record if needed, and it will create records for portals returned by the target that do not yet have a node DB record.
.IP
\fIdelete\fR deletes a specified \fIrecid\fR. In discovery node, if iscsiadm is performing discovery it will delete records for portals that are no longer returned.
.IP
@@ -289,7 +299,7 @@ discovery type. An SLP implementation is under development.
Discover targets at a given IP address:
.ft R
- iscsiadm \-\-mode discovery \-\-type sendtargets \-\-portal 192.168.1.10
+ iscsiadm \-\-mode discovery2 \-\-type sendtargets \-\-portal 192.168.1.10 \-\-discover
.nf
Login, must use a node record id found by the discovery:
diff --git a/usr/idbm.c b/usr/idbm.c
index 22928fa..f09d779 100644
--- a/usr/idbm.c
+++ b/usr/idbm.c
@@ -1071,7 +1071,7 @@ int idbm_print_all_discovery(int info_level)
drec = calloc(1, sizeof(*drec));
if (!drec)
- return ENOMEM;
+ return 0;
tmp = 0;
printf("SENDTARGETS:\n");
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
index 1bd1eb8..6e90f75 100644
--- a/usr/iscsiadm.c
+++ b/usr/iscsiadm.c
@@ -55,6 +55,7 @@ static char config_file[TARGET_NAME_MAXLEN];
enum iscsiadm_mode {
MODE_DISCOVERY,
+ MODE_DISCOVERY2,
MODE_NODE,
MODE_SESSION,
MODE_HOST,
@@ -107,8 +108,8 @@ static void usage(int status)
program_name);
else {
printf("\
-iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -l ] ] | [ [ -p ip:port ] \
-[ -o operation ] [ -n name ] [ -v value ] [ -l | -D ] ] \n\
+iscsiadm -m discovery2 [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -Dl ] ] | [ [ -p ip:port -t type] \
+[ -o operation ] [ -n name ] [ -v value ] [ -lD ] ] \n\
iscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ -S ] [ [ -T targetname -p ip:port -I ifaceN ] [ -l | -u | -R | -s] ] \
[ [ -o operation ] [ -n name ] [ -v value ] ]\n\
iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ]\n\
@@ -148,6 +149,8 @@ str_to_mode(char *str)
if (!strcmp("discovery", str))
mode = MODE_DISCOVERY;
+ else if (!strcmp("discovery2", str))
+ mode = MODE_DISCOVERY2;
else if (!strcmp("node", str))
mode = MODE_NODE;
else if (!strcmp("session", str))
@@ -1465,6 +1468,164 @@ static int exec_fw_op(discovery_rec_t *drec, struct list_head *ifaces,
return rc;
}
+static int exec_disc2_op(int disc_type, char *ip, int port,
+ struct list_head *ifaces, int info_level, int do_login,
+ int do_discover, int op, char *name, char *value,
+ int do_show)
+{
+ struct discovery_rec drec;
+ int rc = 0, sync_db;
+
+ memset(&drec, 0, sizeof(struct discovery_rec));
+
+ switch (disc_type) {
+ case DISCOVERY_TYPE_SENDTARGETS:
+ if (port < 0)
+ port = ISCSI_LISTEN_PORT;
+
+ if (ip == NULL) {
+ log_error("Please specify portal as "
+ "<ipaddr>[:<ipport>]");
+ rc = -1;
+ goto done;
+ }
+
+ if (op & OP_NEW && !do_discover) {
+ idbm_sendtargets_defaults(&drec.u.sendtargets);
+ strlcpy(drec.address, ip, sizeof(drec.address));
+ drec.port = port;
+ if (idbm_add_discovery(&drec)) {
+ log_error("Could not add new discovery "
+ "record.");
+ rc = -1;
+ } else
+ printf("New discovery record for [SendTargets: "
+ "%s,%d] added.\n", ip, port);
+ goto done;
+ }
+
+ sync_db = 0;
+ rc = idbm_discovery_read(&drec, ip, port);
+ if (rc) {
+ if (!do_discover) {
+ log_error("Discovery record [%s,%d] for "
+ "SendTargets not found!", ip, port);
+ rc = -1;
+ goto done;
+ }
+
+ /* Just add default rec */
+ log_debug(1, "Discovery record [%s,%d] not found!",
+ ip, port);
+ idbm_sendtargets_defaults(&drec.u.sendtargets);
+ strlcpy(drec.address, ip, sizeof(drec.address));
+ drec.port = port;
+ sync_db = 1;
+ } else {
+ if (!do_discover)
+ goto do_db_op;
+ }
+
+ if (do_sendtargets(&drec, ifaces, info_level, do_login, op,
+ sync_db)) {
+ rc = -1;
+ goto done;
+ }
+ goto done;
+ case DISCOVERY_TYPE_SLP:
+ log_error("SLP discovery is not fully implemented yet.");
+ rc = -1;
+ goto done;
+ case DISCOVERY_TYPE_ISNS:
+ if (!do_discover) {
+ log_error("Invalid command. Possibly missing "
+ "--discover argument.");
+ rc = -1;
+ goto done;
+ }
+
+ if (!ip) {
+ log_error("Please specify portal as "
+ "<ipaddr>:[<ipport>]");
+ rc = -1;
+ goto done;
+ }
+
+ strlcpy(drec.address, ip, sizeof(drec.address));
+ if (port < 0)
+ drec.port = ISNS_DEFAULT_PORT;
+ else
+ drec.port = port;
+
+ if (do_isns(&drec, ifaces, info_level, do_login, op)) {
+ rc = -1;
+ goto done;
+ }
+ goto done;
+ case DISCOVERY_TYPE_FW:
+ if (!do_discover) {
+ log_error("Invalid command. Possibly missing "
+ "--discover argument.");
+ rc = -1;
+ goto done;
+ }
+
+ drec.type = DISCOVERY_TYPE_FW;
+ if (exec_fw_op(&drec, ifaces, info_level, do_login, op))
+ rc = -1;
+ goto done;
+ default:
+ rc = -1;
+
+ if (!ip) {
+ if (op == OP_NOOP || op == OP_SHOW) {
+ if (idbm_print_all_discovery(info_level))
+ /* successfully found some recs */
+ rc = 0;
+ } else
+ log_error("Invalid operation. Operation not "
+ "supported.");
+ } else if (op)
+ log_error("Invalid command. Possibly missing discovery "
+ "--type.");
+ else
+ log_error("Invalid command. Portal not needed or "
+ "Possibly missing discovery --type.");
+ goto done;
+ }
+
+do_db_op:
+ if (op == OP_NOOP || op == OP_SHOW) {
+ if (!idbm_print_discovery_info(&drec, do_show)) {
+ log_error("No records found!");
+ rc = -1;
+ }
+ } else if (op == OP_DELETE) {
+ if (idbm_delete_discovery(&drec)) {
+ log_error("Unable to delete record!");
+ rc = -1;
+ }
+ } else if (op == OP_UPDATE) {
+ struct db_set_param set_param;
+
+ if (!name || !value) {
+ log_error("Update requires name and value.");
+ rc = -1;
+ goto done;
+ }
+ set_param.name = name;
+ set_param.value = value;
+ if (idbm_discovery_set_param(&set_param, &drec))
+ rc = -1;
+ } else {
+ log_error("Operation is not supported.");
+ rc = -1;
+ goto done;
+ }
+done:
+ return rc;
+}
+
static int exec_disc_op(int disc_type, char *ip, int port,
struct list_head *ifaces, int info_level, int do_login,
int do_discover, int op, char *name, char *value,
@@ -1795,7 +1956,8 @@ main(int argc, char **argv)
goto free_ifaces;
}
- if (mode != MODE_DISCOVERY && ip && port == -1)
+ if (mode != MODE_DISCOVERY && mode != MODE_DISCOVERY2 && ip &&
+ port == -1)
port = ISCSI_LISTEN_PORT;
switch (mode) {
@@ -1830,6 +1992,18 @@ main(int argc, char **argv)
rc = exec_iface_op(op, do_show, info_level, iface,
name, value);
break;
+ case MODE_DISCOVERY2:
+ if ((rc = verify_mode_params(argc, argv, "DSIPdmntplov", 0))) {
+ log_error("discovery mode: option '-%c' is not "
+ "allowed/supported", rc);
+ rc = -1;
+ goto out;
+ }
+
+ rc = exec_disc2_op(type, ip, port, &ifaces, info_level,
+ do_login, do_discover, op, name, value,
+ do_show);
+ break;
case MODE_DISCOVERY:
if ((rc = verify_mode_params(argc, argv, "DSIPdmntplov", 0))) {
log_error("discovery mode: option '-%c' is not "