Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/iscsi/dist/src/lib scsi_command_t: rather than ...
details: https://anonhg.NetBSD.org/src/rev/94b2809810b4
branches: trunk
changeset: 751123:94b2809810b4
user: yamt <yamt%NetBSD.org@localhost>
date: Mon Jan 25 13:45:16 2010 +0000
description:
scsi_command_t: rather than putting cleanup code before every
return statememts, use goto to a single copy of the cleanup code.
no functional changes.
diffstat:
external/bsd/iscsi/dist/src/lib/target.c | 117 +++++++++++++-----------------
1 files changed, 52 insertions(+), 65 deletions(-)
diffs (274 lines):
diff -r a719e0b950fb -r 94b2809810b4 external/bsd/iscsi/dist/src/lib/target.c
--- a/external/bsd/iscsi/dist/src/lib/target.c Mon Jan 25 11:41:10 2010 +0000
+++ b/external/bsd/iscsi/dist/src/lib/target.c Mon Jan 25 13:45:16 2010 +0000
@@ -173,12 +173,16 @@
target_cmd_t cmd;
uint32_t DataSN = 0;
uint8_t rsp_header[ISCSI_HEADER_LEN];
+ struct iovec *sg_new = NULL;
+ int result;
(void) memset(&scsi_cmd, 0x0, sizeof(scsi_cmd));
+ scsi_cmd.ahs = NULL;
if (iscsi_scsi_cmd_decap(header, &scsi_cmd) != 0) {
iscsi_err(__FILE__, __LINE__,
"iscsi_scsi_cmd_decap() failed\n");
- return -1;
+ result = -1;
+ goto out;
}
iscsi_trace(TRACE_ISCSI_DEBUG,
"session %d: SCSI Command (CmdSN %u, op %#x)\n",
@@ -193,7 +197,8 @@
"CmdSN(%d) of SCSI Command not valid, "
"ExpCmdSN(%d) MaxCmdSN(%d). Ignoring the command\n",
scsi_cmd.CmdSN, sess->ExpCmdSN, sess->MaxCmdSN);
- return 0;
+ result = 0;
+ goto out;
}
/* Arg check. */
scsi_cmd.attr = 0; /* Temp fix FIXME */
@@ -227,7 +232,8 @@
"scsi_cmd.length (%u) > MaxRecvDataSegmentLength "
"(%u)\n",
scsi_cmd.length, sess->sess_params.max_dataseg_len);
- return -1;
+ result = -1;
+ goto out;
}
#if 0
@@ -247,26 +253,21 @@
uint8_t *ahs_ptr;
uint8_t ahs_type;
- scsi_cmd.ahs = NULL;
iscsi_trace(TRACE_ISCSI_DEBUG,
"reading %u bytes AHS\n", scsi_cmd.ahs_len);
scsi_cmd.ahs = iscsi_malloc_atomic((unsigned)scsi_cmd.ahs_len);
if (scsi_cmd.ahs == NULL) {
iscsi_err(__FILE__, __LINE__,
"iscsi_malloc_atomic() failed\n");
- return -1;
+ result = -1;
+ goto out;
}
-#define AHS_CLEANUP do { \
- if (scsi_cmd.ahs != NULL) { \
- iscsi_free_atomic(scsi_cmd.ahs); \
- } \
-} while (/* CONSTCOND */ 0)
if (iscsi_sock_msg(sess->sock, 0, (unsigned)scsi_cmd.ahs_len,
scsi_cmd.ahs, 0) != scsi_cmd.ahs_len) {
iscsi_err(__FILE__, __LINE__,
"iscsi_sock_msg() failed\n");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
iscsi_trace(TRACE_ISCSI_DEBUG,
"read %u bytes AHS\n", scsi_cmd.ahs_len);
@@ -277,8 +278,8 @@
if (ahs_len == 0) {
iscsi_err(__FILE__, __LINE__,
"Zero ahs_len\n");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
switch (ahs_type = *(ahs_ptr + 2)) {
case ISCSI_AHS_EXTENDED_CDB:
@@ -301,8 +302,8 @@
default:
iscsi_err(__FILE__, __LINE__,
"unknown AHS type %x\n", ahs_type);
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
}
iscsi_trace(TRACE_ISCSI_DEBUG,
@@ -328,24 +329,20 @@
if (device_command(sess, &cmd) != 0) {
iscsi_err(__FILE__, __LINE__,
"device_command() failed\n");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
/* Send any input data */
scsi_cmd.bytes_sent = 0;
if (!scsi_cmd.status && scsi_cmd.input) {
struct iovec sg_singleton;
- struct iovec *sg, *sg_orig, *sg_new = NULL;
+ struct iovec *sg, *sg_orig;
int sg_len_orig, sg_len;
uint32_t offset, trans_len;
int fragment_flag = 0;
int offset_inc;
-#define SG_CLEANUP do { \
- if (fragment_flag) { \
- iscsi_free_atomic(sg_new); \
- } \
-} while (/* CONSTCOND */ 0)
+
if (scsi_cmd.output) {
iscsi_trace(TRACE_ISCSI_DEBUG,
"sending %u bytes bi-directional input data\n",
@@ -384,8 +381,8 @@
sg_new = iscsi_malloc_atomic(sizeof(struct iovec) * sg_len_orig);
if (sg_new == NULL) {
iscsi_err(__FILE__, __LINE__, "iscsi_malloc_atomic() failed\n");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
fragment_flag++;
}
@@ -394,9 +391,8 @@
(void) memcpy(sg, sg_orig, sizeof(struct iovec) * sg_len_orig);
if (modify_iov(&sg, &sg_len, offset, data.length) != 0) {
iscsi_err(__FILE__, __LINE__, "modify_iov() failed\n");
- SG_CLEANUP;
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
}
iscsi_trace(TRACE_ISCSI_DEBUG, "sending read data PDU (offset %u, len %u)\n", offset, data.length);
@@ -413,9 +409,8 @@
}
} else if (offset + data.length > trans_len) {
iscsi_err(__FILE__, __LINE__, "offset+data.length > trans_len??\n");
- SG_CLEANUP;
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
data.task_tag = scsi_cmd.tag;
data.ExpCmdSN = sess->ExpCmdSN;
@@ -424,21 +419,18 @@
data.offset = offset;
if (iscsi_read_data_encap(rsp_header, &data) != 0) {
iscsi_err(__FILE__, __LINE__, "iscsi_read_data_encap() failed\n");
- SG_CLEANUP;
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
if ((uint32_t)iscsi_sock_send_header_and_data(sess->sock, rsp_header, ISCSI_HEADER_LEN, sg, data.length, sg_len)
!= ISCSI_HEADER_LEN + data.length) {
iscsi_err(__FILE__, __LINE__, "iscsi_sock_send_header_and_data() failed\n");
- SG_CLEANUP;
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
scsi_cmd.bytes_sent += data.length;
iscsi_trace(TRACE_ISCSI_DEBUG, "sent read data PDU ok (offset %u, len %u)\n", data.offset, data.length);
}
- SG_CLEANUP;
iscsi_trace(TRACE_ISCSI_DEBUG, "successfully sent %u bytes read data\n", trans_len);
}
/*
@@ -466,55 +458,43 @@
scsi_rsp.status = scsi_cmd.status; /* SCSI status */
if (iscsi_scsi_rsp_encap(rsp_header, &scsi_rsp) != 0) {
iscsi_err(__FILE__, __LINE__, "iscsi_scsi_rsp_encap() failed\n");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
if ((uint32_t)iscsi_sock_send_header_and_data(sess->sock, rsp_header, ISCSI_HEADER_LEN,
scsi_cmd.send_data, scsi_rsp.length, scsi_cmd.send_sg_len)
!= ISCSI_HEADER_LEN + scsi_rsp.length) {
iscsi_err(__FILE__, __LINE__,
"iscsi_sock_send_header_and_data() failed\n");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
/* Make sure all data was transferred */
if (scsi_cmd.output) {
-#if 0
- RETURN_NOT_EQUAL("scsi_cmd.bytes_recv", scsi_cmd.bytes_recv, scsi_cmd.trans_len, AHS_CLEANUP, -1);
-#else
if (scsi_cmd.bytes_recv != scsi_cmd.trans_len) {
iscsi_err(__FILE__, __LINE__,
"scsi_cmd.bytes_recv");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
-#endif
if (scsi_cmd.input) {
-#if 0
- RETURN_NOT_EQUAL("scsi_cmd.bytes_sent", scsi_cmd.bytes_sent, scsi_cmd.bidi_trans_len, AHS_CLEANUP, -1);
-#else
if (scsi_cmd.bytes_sent !=
scsi_cmd.bidi_trans_len) {
iscsi_err(__FILE__, __LINE__,
"scsi_cmd.bytes_sent");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
-#endif
}
} else {
if (scsi_cmd.input) {
-#if 0
- RETURN_NOT_EQUAL("scsi_cmd.bytes_sent", scsi_cmd.bytes_sent, scsi_cmd.trans_len, AHS_CLEANUP, -1);
-#else
if (scsi_cmd.bytes_sent != scsi_cmd.trans_len) {
iscsi_err(__FILE__, __LINE__,
"scsi_cmd.bytes_sent");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
-#endif
}
}
}
@@ -525,12 +505,19 @@
if ((*cmd.callback)(cmd.callback_arg) != 0) {
iscsi_err(__FILE__, __LINE__,
"device callback failed\n");
- AHS_CLEANUP;
- return -1;
+ result = -1;
+ goto out;
}
}
- AHS_CLEANUP;
- return 0;
+ result = 0;
+out:
+ if (scsi_cmd.ahs != NULL) { \
+ iscsi_free_atomic(scsi_cmd.ahs); \
+ } \
+ if (sg_new != NULL) {
+ iscsi_free_atomic(sg_new);
+ }
+ return result;
}
static int
Home |
Main Index |
Thread Index |
Old Index