diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/usr/initiator.c open-iscsi-2.0-871.1.1-bnx2i.work/usr/initiator.c --- open-iscsi-2.0-871.1.1-bnx2i/usr/initiator.c 2010-01-15 02:24:02.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/usr/initiator.c 2010-01-15 03:46:45.000000000 -0600 @@ -45,6 +45,7 @@ #include "iscsi_sysfs.h" #include "iscsi_settings.h" #include "iface.h" +#include "host.h" #include "sysdeps.h" #define ISCSI_CONN_ERR_REOPEN_DELAY 3 @@ -725,6 +726,38 @@ static int iscsi_conn_connect(struct isc return 0; } +static int __set_net_config(struct iscsi_transport *t, + iscsi_session_t *session, + struct iface_rec *iface) +{ + if (t->template->set_net_config) { + /* uip needs the netdev name */ + struct host_info hinfo; + int hostno, rc; + + /* this assumes that the netdev or hw address is going to be + set */ + hostno = iscsi_sysfs_get_host_no_from_hwinfo(iface, &rc); + if (rc) { + log_debug(4, "Couldn't get host no.\n"); + return rc; + } + + /* uip needs the netdev name */ + if (!strlen(iface->netdev)) { + memset(&hinfo, 0, sizeof(hinfo)); + hinfo.host_no = hostno; + iscsi_sysfs_get_hostinfo_by_host_no(&hinfo); + strcpy(iface->netdev, hinfo.iface.netdev); + } + + return t->template->set_net_config(t, iface, session); + } + + return 0; +} + + static void __session_conn_reopen(iscsi_conn_t *conn, queue_task_t *qtask, int do_stop, int redirected) @@ -766,6 +799,11 @@ __session_conn_reopen(iscsi_conn_t *conn if (!redirected) session->reopen_cnt++; + /* uIP will needs to be re-triggered on the connection re-open */ + if (__set_net_config(conn->session->t, conn->session, + &conn->session->nrec.iface) != 0) + goto queue_reopen; + if (iscsi_conn_connect(conn, qtask)) { delay = ISCSI_CONN_ERR_REOPEN_DELAY; goto queue_reopen; @@ -2108,6 +2146,10 @@ static int iface_set_param(struct iscsi_ return EINVAL; } + rc = __set_net_config(t, session, iface); + if (rc != 0) + return rc; + rc = __iscsi_host_set_param(t, session->hostno, ISCSI_HOST_PARAM_IPADDRESS, iface->ipaddress, ISCSI_STRING); diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/usr/Makefile open-iscsi-2.0-871.1.1-bnx2i.work/usr/Makefile --- open-iscsi-2.0-871.1.1-bnx2i/usr/Makefile 2010-01-15 02:24:02.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/usr/Makefile 2010-01-15 04:07:30.000000000 -0600 @@ -41,7 +41,7 @@ ISCSI_LIB_SRCS = util.o io.o auth.o logi $(SYSDEPS_SRCS) # core initiator files INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o isns.o \ - transport.o cxgb3i.o be2iscsi.o + transport.o cxgb3i.o be2iscsi.o uip_mgmt_ipc.o # fw boot files FW_BOOT_SRCS = $(wildcard ../utils/fwparam_ibft/*.o) diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/usr/transport.c open-iscsi-2.0-871.1.1-bnx2i.work/usr/transport.c --- open-iscsi-2.0-871.1.1-bnx2i/usr/transport.c 2010-01-15 02:24:02.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/usr/transport.c 2010-01-15 03:46:45.000000000 -0600 @@ -25,6 +25,7 @@ #include "log.h" #include "util.h" #include "iscsi_sysfs.h" +#include "uip_mgmt_ipc.h" #include "cxgb3i.h" #include "be2iscsi.h" @@ -58,6 +59,7 @@ struct iscsi_transport_template bnx2i = .ep_connect = ktransport_ep_connect, .ep_poll = ktransport_ep_poll, .ep_disconnect = ktransport_ep_disconnect, + .set_net_config = uip_broadcast_params, }; struct iscsi_transport_template be2iscsi = { diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/usr/transport.h open-iscsi-2.0-871.1.1-bnx2i.work/usr/transport.h --- open-iscsi-2.0-871.1.1-bnx2i/usr/transport.h 2010-01-15 02:24:02.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/usr/transport.h 2010-01-15 03:46:45.000000000 -0600 @@ -35,6 +35,9 @@ struct iscsi_transport_template { int (*ep_poll) (struct iscsi_conn *conn, int timeout_ms); void (*ep_disconnect) (struct iscsi_conn *conn); void (*create_conn) (struct iscsi_conn *conn); + int (*set_net_config) (struct iscsi_transport *t, + struct iface_rec *iface, + struct iscsi_session *session); }; /* represents data path provider */ diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/usr/uip_mgmt_ipc.c open-iscsi-2.0-871.1.1-bnx2i.work/usr/uip_mgmt_ipc.c --- open-iscsi-2.0-871.1.1-bnx2i/usr/uip_mgmt_ipc.c 1969-12-31 18:00:00.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/usr/uip_mgmt_ipc.c 2010-01-15 03:46:45.000000000 -0600 @@ -0,0 +1,41 @@ +/* + * uIP iSCSI Daemon/Admin Management IPC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * See the file COPYING included with this distribution for more details. + */ + +#include + +#include "log.h" +#include "uip_mgmt_ipc.h" +#include "util.h" + +int uip_broadcast_params(struct iscsi_transport *t, + struct iface_rec *iface, + struct iscsi_session *session) +{ + struct iscsid_uip_broadcast broadcast; + + log_debug(3, "broadcasting to uip\n"); + + memset(&broadcast, 0, sizeof(broadcast)); + + broadcast.header.command = ISCSID_UIP_IPC_GET_IFACE; + broadcast.header.payload_len = sizeof(*iface); + + memcpy(&broadcast.u.iface_rec, iface, sizeof(*iface)); + + return uip_broadcast(&broadcast, + sizeof(iscsid_uip_broadcast_header_t) + + sizeof(*iface)); +} diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/usr/uip_mgmt_ipc.h open-iscsi-2.0-871.1.1-bnx2i.work/usr/uip_mgmt_ipc.h --- open-iscsi-2.0-871.1.1-bnx2i/usr/uip_mgmt_ipc.h 1969-12-31 18:00:00.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/usr/uip_mgmt_ipc.h 2010-01-15 03:46:45.000000000 -0600 @@ -0,0 +1,71 @@ +/* + * uIP iSCSI Daemon/Admin Management IPC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * See the file COPYING included with this distribution for more details. + */ +#ifndef UIP_MGMT_IPC_H +#define UIP_MGMT_IPC_H + +#include "types.h" +#include "iscsi_if.h" +#include "config.h" +#include "mgmt_ipc.h" + +#include "initiator.h" +#include "transport.h" + +#define ISCSID_UIP_NAMESPACE "ISCSID_UIP_ABSTRACT_NAMESPACE" + +typedef enum iscsid_uip_cmd { + ISCSID_UIP_IPC_UNKNOWN = 0, + ISCSID_UIP_IPC_GET_IFACE = 1, + + __ISCSID_UIP_IPC_MAX_COMMAND +} iscsid_uip_cmd_e; + +typedef struct iscsid_uip_broadcast_header { + iscsid_uip_cmd_e command; + uint32_t payload_len; +} iscsid_uip_broadcast_header_t; + +/* IPC Request */ +typedef struct iscsid_uip_broadcast { + struct iscsid_uip_broadcast_header header; + + union { + /* messages */ + struct ipc_broadcast_iface_rec { + struct iface_rec rec; + } iface_rec; + } u; +} iscsid_uip_broadcast_t; + +typedef enum iscsid_uip_mgmt_ipc_err { + ISCSID_UIP_MGMT_IPC_OK = 0, + ISCISD_UIP_MGMT_IPC_ERR = 1, + ISCISD_UIP_MGMT_IPC_ERR_NOT_FOUND = 2, + ISCISD_UIP_MGMT_IPC_ERR_NOMEM = 3, +} iscsid_uip_mgmt_ipc_err_e; + +/* IPC Response */ +typedef struct iscsid_uip_mgmt_rsp { + iscsid_uip_cmd_e command; + iscsid_uip_mgmt_ipc_err_e err; +} iscsid_uip_rsp_t; + +extern int uip_broadcast_params(struct iscsi_transport *t, + struct iface_rec *iface, + struct iscsi_session *session); + + +#endif /* UIP_MGMT_IPC_H */ diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/usr/util.c open-iscsi-2.0-871.1.1-bnx2i.work/usr/util.c --- open-iscsi-2.0-871.1.1-bnx2i/usr/util.c 2010-01-15 02:24:02.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/usr/util.c 2010-01-15 04:05:49.000000000 -0600 @@ -23,6 +23,7 @@ #include "idbm.h" #include "iface.h" #include "session_info.h" +#include "uip_mgmt_ipc.h" void daemon_init(void) { @@ -201,7 +202,8 @@ static void iscsid_startup(void) #define MAXSLEEP 128 -static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid) +static mgmt_ipc_err_e ipc_connect(int *fd, char *unix_sock_name, + int start_iscsid) { int nsec; struct sockaddr_un addr; @@ -214,8 +216,8 @@ static mgmt_ipc_err_e iscsid_connect(int memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_LOCAL; - memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE, - strlen(ISCSIADM_NAMESPACE)); + memcpy((char *) &addr.sun_path + 1, unix_sock_name, + strlen(unix_sock_name)); /* * Trying to connect with exponential backoff */ @@ -243,6 +245,11 @@ static mgmt_ipc_err_e iscsid_connect(int return MGMT_IPC_ERR_ISCSID_NOTCONN; } +static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid) +{ + return ipc_connect(fd, ISCSIADM_NAMESPACE, start_iscsid); +} + mgmt_ipc_err_e iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid) { int err; @@ -340,6 +347,72 @@ int iscsid_req_by_sid(iscsiadm_cmd_e cmd return iscsid_req_wait(cmd, fd); } +static mgmt_ipc_err_e uip_connect(int *fd) +{ + return ipc_connect(fd, ISCSID_UIP_NAMESPACE, 0); +} + +int uip_broadcast(void *buf, size_t buf_len) +{ + int err; + int fd; + iscsid_uip_rsp_t rsp; + int flags; + int count; + + err = uip_connect(&fd); + if (err) { + log_warning("uIP daemon is not up"); + return err; + } + + /* Send the data to uIP */ + if ((err = write(fd, buf, buf_len)) != buf_len) { + log_error("got write error (%d/%d), daemon died?", + err, errno); + close(fd); + return -EIO; + } + + /* Set the socket to a non-blocking read, this way if there are + * problems waiting for uIP, iscsid can bailout early */ + flags = fcntl(fd, F_GETFL, 0); + if (flags == -1) + flags = 0; + err = fcntl(fd, F_SETFL, flags | O_NONBLOCK); + if(err != 0) { + log_error("could not set uip broadcast to non-blocking: %d", + errno); + close(fd); + return -EIO; + } + +#define MAX_UIP_BROADCAST_READ_TRIES 3 + for(count = 0; count < MAX_UIP_BROADCAST_READ_TRIES; count++) { + /* Wait for the response */ + err = read(fd, &rsp, sizeof(rsp)); + if (err == sizeof(rsp)) { + log_debug(3, "Broadcasted to uIP with length: %ld\n", + buf_len); + break; + } else if((err == -1) && (errno == EAGAIN)) { + usleep(250000); + continue; + } else { + log_error("Could not read response (%d/%d), daemon died?", + err, errno); + break; + } + } + + if(count == MAX_UIP_BROADCAST_READ_TRIES) + log_error("Could not broadcast to uIP"); + + close(fd); + + return 0; +} + void idbm_node_setup_defaults(node_rec_t *rec) { int i; diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/usr/util.h open-iscsi-2.0-871.1.1-bnx2i.work/usr/util.h --- open-iscsi-2.0-871.1.1-bnx2i/usr/util.h 2010-01-15 02:24:02.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/usr/util.h 2010-01-15 03:46:45.000000000 -0600 @@ -36,4 +36,7 @@ extern int __iscsi_match_session(struct extern char *strstrip(char *s); extern char *get_global_string_param(char *pathname, const char *key); +extern int uip_broadcast(void *buf, size_t buf_len); + + #endif diff -Naurp open-iscsi-2.0-871.1.1-bnx2i/utils/iscsi-iname.c open-iscsi-2.0-871.1.1-bnx2i.work/utils/iscsi-iname.c --- open-iscsi-2.0-871.1.1-bnx2i/utils/iscsi-iname.c 2010-01-15 03:50:49.000000000 -0600 +++ open-iscsi-2.0-871.1.1-bnx2i.work/utils/iscsi-iname.c 2010-01-15 03:44:23.000000000 -0600 @@ -73,7 +73,7 @@ main(int argc, char *argv[]) exit(0); } } else { - prefix = "iqn.1994-05.com.redhat"; + prefix = "iqn.1994-05.com.fedora"; } /* try to feed some entropy from the pool to MD5 in order to get