Deleted Added
full compact
isc_subr.c (188605) isc_subr.c (211095)
1/*-
1/*-
2 * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
2 * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 10 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27/*
28 | iSCSI
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 10 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27/*
28 | iSCSI
29 | $Id: isc_subr.c,v 1.20 2006/12/01 09:10:17 danny Exp danny $
29 | $Id: isc_subr.c 560 2009-05-07 07:37:49Z danny $
30 */
31
32#include <sys/cdefs.h>
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/dev/iscsi/initiator/isc_subr.c 188605 2009-02-14 11:34:57Z rrs $");
33__FBSDID("$FreeBSD: head/sys/dev/iscsi/initiator/isc_subr.c 211095 2010-08-09 12:36:36Z des $");
34
35#include "opt_iscsi_initiator.h"
36
37#include <sys/param.h>
38#include <sys/kernel.h>
39#include <sys/conf.h>
40#include <sys/systm.h>
41#include <sys/malloc.h>

--- 11 unchanged lines hidden (view full) ---

53#include <sys/kthread.h>
54#include <sys/syslog.h>
55#include <sys/mbuf.h>
56#include <sys/libkern.h>
57
58#include <dev/iscsi/initiator/iscsi.h>
59#include <dev/iscsi/initiator/iscsivar.h>
60
34
35#include "opt_iscsi_initiator.h"
36
37#include <sys/param.h>
38#include <sys/kernel.h>
39#include <sys/conf.h>
40#include <sys/systm.h>
41#include <sys/malloc.h>

--- 11 unchanged lines hidden (view full) ---

53#include <sys/kthread.h>
54#include <sys/syslog.h>
55#include <sys/mbuf.h>
56#include <sys/libkern.h>
57
58#include <dev/iscsi/initiator/iscsi.h>
59#include <dev/iscsi/initiator/iscsivar.h>
60
61MALLOC_DEFINE(M_ISC, "iSC", "iSCSI driver options");
62
61static char *
62i_strdupin(char *s, size_t maxlen)
63{
64 size_t len;
65 char *p, *q;
66
63static char *
64i_strdupin(char *s, size_t maxlen)
65{
66 size_t len;
67 char *p, *q;
68
67 p = malloc(maxlen, M_ISCSI, M_WAITOK);
69 p = malloc(maxlen, M_ISC, M_WAITOK);
68 if(copyinstr(s, p, maxlen, &len)) {
70 if(copyinstr(s, p, maxlen, &len)) {
69 free(p, M_ISCSI);
71 free(p, M_ISC);
70 return NULL;
71 }
72 return NULL;
73 }
72 q = malloc(len, M_ISCSI, M_WAITOK);
74 q = malloc(len, M_ISC, M_WAITOK);
73 bcopy(p, q, len);
75 bcopy(p, q, len);
74 free(p, M_ISCSI);
76 free(p, M_ISC);
75
76 return q;
77}
78
79static uint32_t
80i_crc32c(const void *buf, size_t size, uint32_t crc)
81{
82 crc = crc ^ 0xffffffff;

--- 10 unchanged lines hidden (view full) ---

93{
94 if(opt->maxRecvDataSegmentLength > 0) {
95 sp->opt.maxRecvDataSegmentLength = opt->maxRecvDataSegmentLength;
96 sdebug(2, "maxRecvDataSegmentLength=%d", sp->opt.maxRecvDataSegmentLength);
97 }
98 if(opt->maxXmitDataSegmentLength > 0) {
99 // danny's RFC
100 sp->opt.maxXmitDataSegmentLength = opt->maxXmitDataSegmentLength;
77
78 return q;
79}
80
81static uint32_t
82i_crc32c(const void *buf, size_t size, uint32_t crc)
83{
84 crc = crc ^ 0xffffffff;

--- 10 unchanged lines hidden (view full) ---

95{
96 if(opt->maxRecvDataSegmentLength > 0) {
97 sp->opt.maxRecvDataSegmentLength = opt->maxRecvDataSegmentLength;
98 sdebug(2, "maxRecvDataSegmentLength=%d", sp->opt.maxRecvDataSegmentLength);
99 }
100 if(opt->maxXmitDataSegmentLength > 0) {
101 // danny's RFC
102 sp->opt.maxXmitDataSegmentLength = opt->maxXmitDataSegmentLength;
101 sdebug(2, "maXmitDataSegmentLength=%d", sp->opt.maxXmitDataSegmentLength);
103 sdebug(2, "opt.maXmitDataSegmentLength=%d", sp->opt.maxXmitDataSegmentLength);
102 }
103 if(opt->maxBurstLength != 0) {
104 sp->opt.maxBurstLength = opt->maxBurstLength;
104 }
105 if(opt->maxBurstLength != 0) {
106 sp->opt.maxBurstLength = opt->maxBurstLength;
105 sdebug(2, "maxBurstLength=%d", sp->opt.maxBurstLength);
107 sdebug(2, "opt.maxBurstLength=%d", sp->opt.maxBurstLength);
106 }
107
108 if(opt->targetAddress != NULL) {
109 if(sp->opt.targetAddress != NULL)
108 }
109
110 if(opt->targetAddress != NULL) {
111 if(sp->opt.targetAddress != NULL)
110 free(sp->opt.targetAddress, M_ISCSI);
112 free(sp->opt.targetAddress, M_ISC);
111 sp->opt.targetAddress = i_strdupin(opt->targetAddress, 128);
113 sp->opt.targetAddress = i_strdupin(opt->targetAddress, 128);
112 sdebug(4, "opt.targetAddress='%s'", sp->opt.targetAddress);
114 sdebug(2, "opt.targetAddress='%s'", sp->opt.targetAddress);
113 }
114 if(opt->targetName != NULL) {
115 if(sp->opt.targetName != NULL)
115 }
116 if(opt->targetName != NULL) {
117 if(sp->opt.targetName != NULL)
116 free(sp->opt.targetName, M_ISCSI);
118 free(sp->opt.targetName, M_ISC);
117 sp->opt.targetName = i_strdupin(opt->targetName, 128);
119 sp->opt.targetName = i_strdupin(opt->targetName, 128);
118 sdebug(4, "opt.targetName='%s'", sp->opt.targetName);
120 sdebug(2, "opt.targetName='%s'", sp->opt.targetName);
119 }
120 if(opt->initiatorName != NULL) {
121 if(sp->opt.initiatorName != NULL)
121 }
122 if(opt->initiatorName != NULL) {
123 if(sp->opt.initiatorName != NULL)
122 free(sp->opt.initiatorName, M_ISCSI);
124 free(sp->opt.initiatorName, M_ISC);
123 sp->opt.initiatorName = i_strdupin(opt->initiatorName, 128);
125 sp->opt.initiatorName = i_strdupin(opt->initiatorName, 128);
124 sdebug(4, "opt.initiatorName='%s'", sp->opt.initiatorName);
126 sdebug(2, "opt.initiatorName='%s'", sp->opt.initiatorName);
125 }
126
127 if(opt->maxluns > 0) {
128 if(opt->maxluns > ISCSI_MAX_LUNS)
129 sp->opt.maxluns = ISCSI_MAX_LUNS; // silently chop it down ...
130 sp->opt.maxluns = opt->maxluns;
127 }
128
129 if(opt->maxluns > 0) {
130 if(opt->maxluns > ISCSI_MAX_LUNS)
131 sp->opt.maxluns = ISCSI_MAX_LUNS; // silently chop it down ...
132 sp->opt.maxluns = opt->maxluns;
131 sdebug(4, "opt.maxluns=%d", sp->opt.maxluns);
133 sdebug(2, "opt.maxluns=%d", sp->opt.maxluns);
132 }
133
134 if(opt->headerDigest != NULL) {
135 sdebug(2, "opt.headerDigest='%s'", opt->headerDigest);
136 if(strcmp(opt->headerDigest, "CRC32C") == 0) {
137 sp->hdrDigest = (digest_t *)i_crc32c;
134 }
135
136 if(opt->headerDigest != NULL) {
137 sdebug(2, "opt.headerDigest='%s'", opt->headerDigest);
138 if(strcmp(opt->headerDigest, "CRC32C") == 0) {
139 sp->hdrDigest = (digest_t *)i_crc32c;
138 sdebug(2, "headerDigest set");
140 sdebug(2, "opt.headerDigest set");
139 }
140 }
141 if(opt->dataDigest != NULL) {
141 }
142 }
143 if(opt->dataDigest != NULL) {
144 sdebug(2, "opt.dataDigest='%s'", opt->headerDigest);
142 if(strcmp(opt->dataDigest, "CRC32C") == 0) {
143 sp->dataDigest = (digest_t *)i_crc32c;
145 if(strcmp(opt->dataDigest, "CRC32C") == 0) {
146 sp->dataDigest = (digest_t *)i_crc32c;
144 sdebug(2, "dataDigest set");
147 sdebug(2, "opt.dataDigest set");
145 }
146 }
147
148 return 0;
149}
150
151void
152i_freeopt(isc_opt_t *opt)
153{
148 }
149 }
150
151 return 0;
152}
153
154void
155i_freeopt(isc_opt_t *opt)
156{
157 debug_called(8);
158
154 if(opt->targetAddress != NULL) {
159 if(opt->targetAddress != NULL) {
155 free(opt->targetAddress, M_ISCSI);
160 free(opt->targetAddress, M_ISC);
156 opt->targetAddress = NULL;
157 }
158 if(opt->targetName != NULL) {
161 opt->targetAddress = NULL;
162 }
163 if(opt->targetName != NULL) {
159 free(opt->targetName, M_ISCSI);
164 free(opt->targetName, M_ISC);
160 opt->targetName = NULL;
161 }
162 if(opt->initiatorName != NULL) {
165 opt->targetName = NULL;
166 }
167 if(opt->initiatorName != NULL) {
163 free(opt->initiatorName, M_ISCSI);
168 free(opt->initiatorName, M_ISC);
164 opt->initiatorName = NULL;
165 }
166}
169 opt->initiatorName = NULL;
170 }
171}