The patch addresses 3 issues:
1. Fixes bug in srp_daemon for the case where if it is invoked with the
'-e' option, it fails to connect to the SRP targets because of a newline
character in the parameter string.
2. Changes the name of the constant 'MAX_TRAGET_CONFIG_STR_STRING' to
'MAX_TARGET_CONFIG_STR_STRING'.
3. Changes the behavior of the '-n' option to srp_daemon. The earlier
behavior printed the initiator extension. The new behavior allows the
user to specify an initiator extension as an argument to the '-n'
option.

Signed-off-by: Madhu Lakshmanan <[EMAIL PROTECTED]>
---
--- 1.1-orig/src/userspace/srptools/srp_daemon/srp_daemon.c
2006-10-17 06:32:14.000000000 -0400
+++ 1.1/src/userspace/srptools/srp_daemon/srp_daemon.c  2006-10-17
06:10:12.000000000 -0400
@@ -78,7 +78,7 @@ static char *sysfs_path = "/sys";
 
 static void usage(const char *argv0)
 {
-       fprintf(stderr, "Usage: %s [-vVceo] [-d <umad device> | -i
<infiniband device> [-p <port_num>]] [-t <timoeout (ms)>] [-r <retries>]
[-R <Rescan time>]\n", argv0);
+       fprintf(stderr, "Usage: %s [-vVceo] [-d <umad device> | -i
<infiniband device> [-p <port_num>]] [-n <initiator_ext>] [-t <timoeout
(ms)>] [-r <retries>] [-R <Rescan time>]\n", argv0);
        fprintf(stderr, "-v                     Verbose\n");
        fprintf(stderr, "-V                     debug Verbose\n");
        fprintf(stderr, "-c                     prints connection
Commands\n");
@@ -91,7 +91,7 @@ static void usage(const char *argv0)
        fprintf(stderr, "-R <Rescan time>       perform complete Rescan
every <Rescan time> seconds\n");
        fprintf(stderr, "-t <timoeout>          Timeout for mad response
in milisec \n");
        fprintf(stderr, "-r <retries>           number of send Retries
for each mad\n");
-       fprintf(stderr, "-n                     New print - prints also
initiator extention\n");
+       fprintf(stderr, "-n <initiator_ext>     New: use initiator
extension\n");
        fprintf(stderr, "\nExample: srp_daemon -e -i mthca0 -p 1 -R
60\n");
 }
 
@@ -114,7 +114,7 @@ void pr_cmd(char *target_str, int not_co
        int ret;
 
        if (config->cmd)
-               printf("%s", target_str);
+               printf("%s\n", target_str);
 
        if (config->execute && not_connected) {
                int fd = open(config->add_target_file, O_WRONLY);
@@ -122,6 +122,7 @@ void pr_cmd(char *target_str, int not_co
                        pr_err("unable to open %s, maybe ib_srp is not
loaded\n", config->add_target_file);
                        return;
                }
+               pr_debug("Add target str: %s\n", target_str);
                ret = write(fd, target_str, strlen(target_str));
                pr_debug("Adding target returned %d\n", ret);
                close(fd);
@@ -174,8 +175,8 @@ static void add_non_exist_traget(char *i
        char *subdir_name_ptr;
        int prefix_len;
        uint8_t dgid_val[16];
-       const int MAX_TRAGET_CONFIG_STR_STRING = 255;
-       char target_config_str[MAX_TRAGET_CONFIG_STR_STRING];
+       const int MAX_TARGET_CONFIG_STR_STRING = 255;
+       char target_config_str[MAX_TARGET_CONFIG_STR_STRING];
        int len, len_left;
        int not_connected = 1;
 
@@ -190,8 +191,7 @@ static void add_non_exist_traget(char *i
        prefix_len = strlen(scsi_host_dir);
        subdir_name_ptr = scsi_host_dir + prefix_len;
 
-       subdir = (void *) 1; /* Dummy value to enter the loop */
-       while (subdir) {
+       do {
                subdir = readdir(dir);
                
                if (!subdir)
@@ -237,9 +237,9 @@ static void add_non_exist_traget(char *i
 
                return;
 
-       }
+       } while (subdir);
 
-       len = snprintf(target_config_str, MAX_TRAGET_CONFIG_STR_STRING,
"id_ext=%s,"
+       len = snprintf(target_config_str, MAX_TARGET_CONFIG_STR_STRING,
"id_ext=%s,"
                "ioc_guid=%016llx,"
                "dgid=%016llx%016llx,"
                "pkey=ffff,"
@@ -249,41 +249,40 @@ static void add_non_exist_traget(char *i
                (unsigned long long) subnet_prefix,
                (unsigned long long) h_guid,
                (unsigned long long) h_service_id);
-       if (len >= MAX_TRAGET_CONFIG_STR_STRING) {
+       if (len >= MAX_TARGET_CONFIG_STR_STRING) {
                pr_err("Target conifg string is too long, ignoring
target\n");
                closedir(dir);
                return;
        }
 
        if (ioc_prof.io_class != htons(SRP_REV16A_IB_IO_CLASS)) {
-               len_left = MAX_TRAGET_CONFIG_STR_STRING - len;
+               len_left = MAX_TARGET_CONFIG_STR_STRING - len;
                len += snprintf(target_config_str+len, 
-                               MAX_TRAGET_CONFIG_STR_STRING - len,
+                               MAX_TARGET_CONFIG_STR_STRING - len,
                                ",io_class=%04hx",
ntohs(ioc_prof.io_class));
 
-               if (len >= MAX_TRAGET_CONFIG_STR_STRING) {
+               if (len >= MAX_TARGET_CONFIG_STR_STRING) {
                        pr_err("Target conifg string is too long,
ignoring target\n");
                        closedir(dir);
                        return;
                }
        }
 
-       if (config->print_initiator_ext) {
-               len_left = MAX_TRAGET_CONFIG_STR_STRING - len;
+       if (config->initiator_ext) {
+               len_left = MAX_TARGET_CONFIG_STR_STRING - len;
                len += snprintf(target_config_str+len, 
-                               MAX_TRAGET_CONFIG_STR_STRING - len,
+                               MAX_TARGET_CONFIG_STR_STRING - len,
                                ",initiator_ext=%016llx",
-                               (unsigned long long) ntohll(h_guid));
+                               (unsigned long long)
config->initiator_ext);
 
-               if (len >= MAX_TRAGET_CONFIG_STR_STRING) {
+               if (len >= MAX_TARGET_CONFIG_STR_STRING) {
                        pr_err("Target conifg string is too long,
ignoring target\n");
                        closedir(dir);
                        return;
                }
        }
 
-       target_config_str[len] = '\n';
-       target_config_str[len+1] = '\0';
+       target_config_str[len] = '\0';
 
        pr_cmd(target_config_str, not_connected);
 
@@ -860,10 +859,6 @@ static void print_config(struct config_t
        printf(" Executes add target command            : %d\n",
conf->execute);
        printf(" Print also connected targets           : %d\n",
conf->all);
        printf(" Report current tragets and stop        : %d\n",
conf->once);
-       if (conf->print_initiator_ext)
-               printf(" Print initiator_ext\n");
-       else
-               printf(" Do not print initiator_ext\n");
        if (conf->recalc_time)
                printf(" Performs full target rescan every %d
seconds\n", conf->recalc_time);
        else
@@ -892,12 +887,12 @@ static int get_config(struct config_t *c
        conf->mad_retries               = 3;
        conf->recalc_time               = 0;
        conf->add_target_file           = NULL;
-       conf->print_initiator_ext       = 0;
+       conf->initiator_ext             = 0;
 
        while (1) {
                int c;
 
-               c = getopt(argc, argv, "caveod:i:p:t:r:R:Vhn");
+               c = getopt(argc, argv, "caveod:i:n:p:t:r:R:Vh");
                if (c == -1)
                        break;
 
@@ -940,7 +935,8 @@ static int get_config(struct config_t *c
                        ++conf->debug_verbose;
                        break;
                case 'n':
-                       ++conf->print_initiator_ext;
+                       conf->initiator_ext = (uint64_t) 
+                                                 strtoull(optarg, NULL,
16);
                        break;
                case 't':
                        conf->timeout = atoi(optarg);
--- 1.1-orig/src/userspace/srptools/srp_daemon/srp_daemon.h
2006-10-17 06:32:14.000000000 -0400
+++ 1.1/src/userspace/srptools/srp_daemon/srp_daemon.h  2006-10-13
01:39:50.000000000 -0400
@@ -288,7 +288,7 @@ struct config_t {
        int     debug_verbose;
        int     timeout;
        int     recalc_time;
-       int     print_initiator_ext;
+       uint64_t        initiator_ext;
 };
 
 extern struct config_t *config;

_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to