Module Name: src Committed By: yamt Date: Wed Mar 3 00:44:52 UTC 2010
Modified Files: src/external/bsd/iscsi/dist/include: iscsiprotocol.h src/external/bsd/iscsi/dist/src/lib: disk.c target.c Log Message: fix multi-thread problems wrt read/write buffer. PR/42651. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/external/bsd/iscsi/dist/include/iscsiprotocol.h cvs rdiff -u -r1.5 -r1.6 src/external/bsd/iscsi/dist/src/lib/disk.c cvs rdiff -u -r1.6 -r1.7 src/external/bsd/iscsi/dist/src/lib/target.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/iscsi/dist/include/iscsiprotocol.h diff -u src/external/bsd/iscsi/dist/include/iscsiprotocol.h:1.1 src/external/bsd/iscsi/dist/include/iscsiprotocol.h:1.2 --- src/external/bsd/iscsi/dist/include/iscsiprotocol.h:1.1 Thu Jun 25 13:47:09 2009 +++ src/external/bsd/iscsi/dist/include/iscsiprotocol.h Wed Mar 3 00:44:51 2010 @@ -391,6 +391,7 @@ uint8_t *ahs; uint8_t ahs_len; uint8_t *send_data; + uint8_t *send_buffer; /* malloc'ed buffer for READ */ int32_t send_sg_len; uint8_t *recv_data; int32_t recv_sg_len; Index: src/external/bsd/iscsi/dist/src/lib/disk.c diff -u src/external/bsd/iscsi/dist/src/lib/disk.c:1.5 src/external/bsd/iscsi/dist/src/lib/disk.c:1.6 --- src/external/bsd/iscsi/dist/src/lib/disk.c:1.5 Wed Jan 20 10:33:08 2010 +++ src/external/bsd/iscsi/dist/src/lib/disk.c Wed Mar 3 00:44:51 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: disk.c,v 1.5 2010/01/20 10:33:08 yamt Exp $ */ +/* $NetBSD: disk.c,v 1.6 2010/03/03 00:44:51 yamt Exp $ */ /*- * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -100,6 +100,8 @@ #include <netinet/in.h> #endif +#include <assert.h> + #ifdef HAVE_ERRNO_H #include <errno.h> #endif @@ -149,7 +151,6 @@ typedef struct iscsi_disk_t { int type; /* type of disk - fs/mmap and fs */ char filename[MAXPATHLEN]; /* filename for the disk */ - uint8_t *buffer; /* buffer for disk read/write ops */ uint64_t blockc; /* # of blocks */ uint64_t blocklen; /* block size */ uint64_t luns; /* # of luns */ @@ -859,7 +860,6 @@ } idisk->size = de_getsize(&tp->de); idisk->blockc = idisk->size / idisk->blocklen; - NEWARRAY(uint8_t, idisk->buffer, MB(1), "buffer1", ;); idisk->type = ISCSI_FS; printf("DISK: %" PRIu64 " logical unit%s (%" PRIu64 " blocks, %" PRIu64 " bytes/block), type %s\n", @@ -1386,6 +1386,7 @@ uint64_t byte_offset; uint64_t bytec; uint8_t *ptr; + int result; byte_offset = lba * disks.v[sess->d].blocklen; bytec = len * disks.v[sess->d].blocklen; @@ -1402,7 +1403,7 @@ } /* Assign ptr for write data */ - ptr = disks.v[sess->d].buffer; + ptr = malloc(MB(1)); /* Have target do data transfer */ sg.iov_base = ptr; @@ -1410,7 +1411,8 @@ if (target_transfer_data(sess, args, &sg, 1) != 0) { iscsi_err(__FILE__, __LINE__, "target_transfer_data() failed\n"); - return -1; + result = -1; + goto out; } /* Finish up write */ if (de_lseek(&disks.v[sess->d].lunv->v[lun].de, (off_t)byte_offset, @@ -1418,7 +1420,8 @@ iscsi_err(__FILE__, __LINE__, "lseek() to offset %" PRIu64 " failed\n", byte_offset); - return -1; + result = -1; + goto out; } if (!target_writable(&disks.v[sess->d].lunv->v[lun])) { iscsi_err(__FILE__, __LINE__, @@ -1426,7 +1429,8 @@ PRIu64 ", size %" PRIu64 "[READONLY TARGET]\n", bytec, byte_offset, de_getsize(&disks.v[sess->d].lunv->v[lun].de)); - return -1; + result = -1; + goto out; } if ((uint64_t)de_write(&disks.v[sess->d].lunv->v[lun].de, ptr, (unsigned) bytec) != bytec) { @@ -1435,11 +1439,15 @@ PRIu64 ", size %" PRIu64 "\n", bytec, byte_offset, de_getsize(&disks.v[sess->d].lunv->v[lun].de)); - return -1; + result = -1; + goto out; } iscsi_trace(TRACE_SCSI_DATA, "wrote %" PRIu64 " bytes to device OK\n", bytec); - return 0; + result = 0; +out: + free(ptr); + return result; } static int @@ -1452,11 +1460,12 @@ uint8_t *ptr; uint32_t n; int rc; + int result; + assert(args->send_buffer == NULL); byte_offset = lba * disks.v[sess->d].blocklen; bytec = len * disks.v[sess->d].blocklen; extra = 0; - ptr = NULL; if (len == 0) { iscsi_err(__FILE__, __LINE__, "Zero \"len\"\n"); NO_CLEANUP; @@ -1475,20 +1484,22 @@ NO_CLEANUP; return -1; } - ptr = disks.v[sess->d].buffer; + ptr = malloc(MB(1)); n = 0; do { if (de_lseek(&disks.v[sess->d].lunv->v[lun].de, (off_t)(n + byte_offset), SEEK_SET) == -1) { iscsi_err(__FILE__, __LINE__, "lseek failed\n"); - return -1; + result = -1; + goto out; } rc = de_read(&disks.v[sess->d].lunv->v[lun].de, ptr + n, (size_t)(bytec - n)); if (rc <= 0) { iscsi_err(__FILE__, __LINE__, "read failed: rc %d errno %d\n", rc, errno); - return -1; + result = -1; + goto out; } n += rc; if (n < bytec) { @@ -1504,5 +1515,9 @@ args->length = (unsigned) bytec; args->send_sg_len = 1; args->status = 0; + args->send_buffer = ptr; return 0; +out: + free(ptr); + return result; } Index: src/external/bsd/iscsi/dist/src/lib/target.c diff -u src/external/bsd/iscsi/dist/src/lib/target.c:1.6 src/external/bsd/iscsi/dist/src/lib/target.c:1.7 --- src/external/bsd/iscsi/dist/src/lib/target.c:1.6 Mon Jan 25 13:45:16 2010 +++ src/external/bsd/iscsi/dist/src/lib/target.c Wed Mar 3 00:44:51 2010 @@ -178,6 +178,7 @@ (void) memset(&scsi_cmd, 0x0, sizeof(scsi_cmd)); scsi_cmd.ahs = NULL; + scsi_cmd.send_buffer = NULL; if (iscsi_scsi_cmd_decap(header, &scsi_cmd) != 0) { iscsi_err(__FILE__, __LINE__, "iscsi_scsi_cmd_decap() failed\n"); @@ -517,6 +518,7 @@ if (sg_new != NULL) { iscsi_free_atomic(sg_new); } + free(scsi_cmd.send_buffer); return result; }