diff options
author | Mike Christie <michaelc@cs.wisc.edu> | 2011-01-29 22:50:43 -0600 |
---|---|---|
committer | Mike Christie <michaelc@cs.wisc.edu> | 2011-01-31 21:52:18 -0600 |
commit | 9dca10af955255f9806942cb3370d4a86660a655 (patch) | |
tree | 5fb8e7f4ada8989fec2c815de7044ea2b75a281a /usr/iscsi_timer.c | |
parent | 44cc856b2115e6cd1221fe061b08b23d3cf188c8 (diff) | |
download | open-iscsi-9dca10af955255f9806942cb3370d4a86660a655.tar.gz |
Use pass through interface for sendtargets (take4) Currenly offload cards like bnx2i, be2iscsi, cxgb3i must use a normal eth for discovery. This patch allows us to do discovery using the iscsi class passthrough interface.
Note1 that the dirver must set the CAP_TEXT_NEGO setting, which
might requires scsi-misc.
Limitations of patch:
- MaxRecvDataSegmentLength is limited to 8K for discovery sessions
when offload is used.
V3:
- bug fixes from Eddie Wai to call start conn after we have logged in.
Fixed set param not setting all settings.
Misc cleanups.
V4:
- fix iscsistart segfault due to missing initialization.
Diffstat (limited to 'usr/iscsi_timer.c')
-rw-r--r-- | usr/iscsi_timer.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/usr/iscsi_timer.c b/usr/iscsi_timer.c new file mode 100644 index 0000000..de38286 --- /dev/null +++ b/usr/iscsi_timer.c @@ -0,0 +1,86 @@ +/* + * iSCSI timer + * + * Copyright (C) 2002 Cisco Systems, Inc. + * + * 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 <string.h> +#include <sys/time.h> + +void iscsi_timer_clear(struct timeval *timer) +{ + memset(timer, 0, sizeof (*timer)); +} + +/* set timer to now + seconds */ +void iscsi_timer_set(struct timeval *timer, int seconds) +{ + if (timer) { + memset(timer, 0, sizeof (*timer)); + gettimeofday(timer, NULL); + + timer->tv_sec += seconds; + } +} + +int iscsi_timer_expired(struct timeval *timer) +{ + struct timeval now; + + /* no timer, can't have expired */ + if ((timer == NULL) || ((timer->tv_sec == 0) && (timer->tv_usec == 0))) + return 0; + + memset(&now, 0, sizeof (now)); + gettimeofday(&now, NULL); + + if (now.tv_sec > timer->tv_sec) + return 1; + if ((now.tv_sec == timer->tv_sec) && (now.tv_usec >= timer->tv_usec)) + return 1; + return 0; +} + +int iscsi_timer_msecs_until(struct timeval *timer) +{ + struct timeval now; + int msecs; + long partial; + + /* no timer, can't have expired, infinite time til it expires */ + if ((timer == NULL) || ((timer->tv_sec == 0) && (timer->tv_usec == 0))) + return -1; + + memset(&now, 0, sizeof (now)); + gettimeofday(&now, NULL); + + /* already expired? */ + if (now.tv_sec > timer->tv_sec) + return 0; + if ((now.tv_sec == timer->tv_sec) && (now.tv_usec >= timer->tv_usec)) + return 0; + + /* not expired yet, do the math */ + partial = timer->tv_usec - now.tv_usec; + if (partial < 0) { + partial += 1000 * 1000; + msecs = (partial + 500) / 1000; + msecs += (timer->tv_sec - now.tv_sec - 1) * 1000; + } else { + msecs = (partial + 500) / 1000; + msecs += (timer->tv_sec - now.tv_sec) * 1000; + } + + return msecs; +} |