Tue Jun 23 05:11:47 2009 UTC ()
Apply some fixes from HEO SeonMeyong to allow the iSCSI target to build
and operate on Mac OS X - with apologies for taking so long to apply them.


(agc)
diff -r1.9 -r1.10 src/dist/iscsi/include/compat.h
diff -r1.5 -r1.6 src/dist/iscsi/include/storage.h
diff -r1.39 -r1.40 src/dist/iscsi/src/disk.c
diff -r1.3 -r1.4 src/dist/iscsi/src/uuid.c

cvs diff -r1.9 -r1.10 src/dist/iscsi/include/Attic/compat.h (expand / switch to unified diff)

--- src/dist/iscsi/include/Attic/compat.h 2007/12/06 00:08:05 1.9
+++ src/dist/iscsi/include/Attic/compat.h 2009/06/23 05:11:46 1.10
@@ -64,38 +64,14 @@ size_t strlcpy(char *, const char *, siz @@ -64,38 +64,14 @@ size_t strlcpy(char *, const char *, siz
64 64
65#ifndef _DIAGASSERT 65#ifndef _DIAGASSERT
66# ifndef __static_cast 66# ifndef __static_cast
67# define __static_cast(x,y) (x)y 67# define __static_cast(x,y) (x)y
68# endif 68# endif
69#define _DIAGASSERT(e) (__static_cast(void,0)) 69#define _DIAGASSERT(e) (__static_cast(void,0))
70#endif 70#endif
71 71
72/* Added for busybox, which doesn't define INFTIM */ 72/* Added for busybox, which doesn't define INFTIM */
73#ifndef INFTIM 73#ifndef INFTIM
74#define INFTIM -1 74#define INFTIM -1
75#endif 75#endif
76 76
77#ifndef HAVE_UUID_H 
78/* Length of a node address (an IEEE 802 address). */ 
79#define _UUID_NODE_LEN 6 
80 
81/* 
82 * See also: 
83 * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt 
84 * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm 
85 * 
86 * A DCE 1.1 compatible source representation of UUIDs. 
87 */ 
88typedef struct uuid_t { 
89 uint32_t time_low; 
90 uint16_t time_mid; 
91 uint16_t time_hi_and_version; 
92 uint8_t clock_seq_hi_and_reserved; 
93 uint8_t clock_seq_low; 
94 uint8_t node[_UUID_NODE_LEN]; 
95} uuid_t; 
96 
97void uuid_create(uuid_t *, uint32_t *); 
98void uuid_to_string(uuid_t *, char **, uint32_t *); 
99#endif 
100 
101#endif /* COMPAT_H_ */ 77#endif /* COMPAT_H_ */

cvs diff -r1.5 -r1.6 src/dist/iscsi/include/Attic/storage.h (expand / switch to unified diff)

--- src/dist/iscsi/include/Attic/storage.h 2007/12/09 09:16:42 1.5
+++ src/dist/iscsi/include/Attic/storage.h 2009/06/23 05:11:46 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: storage.h,v 1.5 2007/12/09 09:16:42 agc Exp $ */ 1/* $NetBSD: storage.h,v 1.6 2009/06/23 05:11:46 agc Exp $ */
2 2
3/* 3/*
4 * Copyright © 2006 Alistair Crooks. All rights reserved. 4 * Copyright © 2006 Alistair Crooks. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote 14 * 3. The name of the author may not be used to endorse or promote
@@ -22,46 +22,68 @@ @@ -22,46 +22,68 @@
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30#ifndef STORAGE_H_ 30#ifndef STORAGE_H_
31#define STORAGE_H_ 31#define STORAGE_H_
32 32
33#include "defs.h" 33#include "defs.h"
34 34
 35/* Length of a node address (an IEEE 802 address). */
 36#define NB_UUID_NODE_LEN 6
 37
 38/*
 39 * See also:
 40 * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
 41 * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm
 42 *
 43 * A DCE 1.1 compatible source representation of UUIDs.
 44 */
 45typedef struct nbuuid_t {
 46 uint32_t time_low;
 47 uint16_t time_mid;
 48 uint16_t time_hi_and_version;
 49 uint8_t clock_seq_hi_and_reserved;
 50 uint8_t clock_seq_low;
 51 uint8_t node[NB_UUID_NODE_LEN];
 52} nbuuid_t;
 53
 54void nbuuid_create(nbuuid_t *, uint32_t *);
 55void nbuuid_to_string(nbuuid_t *, char **, uint32_t *);
 56
35enum { 57enum {
36 DE_EXTENT, 58 DE_EXTENT,
37 DE_DEVICE 59 DE_DEVICE
38}; 60};
39 61
40/* a device can be made up of an extent or another device */ 62/* a device can be made up of an extent or another device */
41typedef struct disc_de_t { 63typedef struct disc_de_t {
42 int32_t type; /* device or extent */ 64 int32_t type; /* device or extent */
43 uint64_t size; /* size of underlying extent or device */ 65 uint64_t size; /* size of underlying extent or device */
44 union { 66 union {
45 struct disc_extent_t *xp; /* pointer to extent */ 67 struct disc_extent_t *xp; /* pointer to extent */
46 struct disc_device_t *dp; /* pointer to device */ 68 struct disc_device_t *dp; /* pointer to device */
47 } u; 69 } u;
48} disc_de_t; 70} disc_de_t;
49 71
50/* this struct describes an extent of storage */ 72/* this struct describes an extent of storage */
51typedef struct disc_extent_t { 73typedef struct disc_extent_t {
52 char *extent; /* extent name */ 74 char *extent; /* extent name */
53 char *dev; /* device associated with it */ 75 char *dev; /* device associated with it */
54 uint64_t sacred; /* offset of extent from start of device */ 76 uint64_t sacred; /* offset of extent from start of dev */
55 uint64_t len; /* size of extent */ 77 uint64_t len; /* size of extent */
56 int fd; /* in-core file descriptor */ 78 int fd; /* in-core file descriptor */
57 int used; /* extent has been used in a device */ 79 int used; /* extent has been used in a device */
58} disc_extent_t; 80} disc_extent_t;
59 81
60DEFINE_ARRAY(extv_t, disc_extent_t); 82DEFINE_ARRAY(extv_t, disc_extent_t);
61 83
62/* this struct describes a device */ 84/* this struct describes a device */
63typedef struct disc_device_t { 85typedef struct disc_device_t {
64 char *dev; /* device name */ 86 char *dev; /* device name */
65 int raid; /* RAID level */ 87 int raid; /* RAID level */
66 uint64_t off; /* current offset in device */ 88 uint64_t off; /* current offset in device */
67 uint64_t len; /* size of device */ 89 uint64_t len; /* size of device */

cvs diff -r1.39 -r1.40 src/dist/iscsi/src/Attic/disk.c (expand / switch to unified diff)

--- src/dist/iscsi/src/Attic/disk.c 2009/01/25 14:25:27 1.39
+++ src/dist/iscsi/src/Attic/disk.c 2009/06/23 05:11:47 1.40
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: disk.c,v 1.39 2009/01/25 14:25:27 lukem Exp $ */ 1/* $NetBSD: disk.c,v 1.40 2009/06/23 05:11:47 agc Exp $ */
2 2
3/* 3/*
4 * Copyright © 2006 Alistair Crooks. All rights reserved. 4 * Copyright © 2006 Alistair Crooks. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote 14 * 3. The name of the author may not be used to endorse or promote
@@ -98,30 +98,26 @@ @@ -98,30 +98,26 @@
98#include <fcntl.h> 98#include <fcntl.h>
99#endif 99#endif
100 100
101#include <ctype.h> 101#include <ctype.h>
102#include <stdio.h> 102#include <stdio.h>
103#include <stdlib.h> 103#include <stdlib.h>
104 104
105#ifdef HAVE_STRING_H 105#ifdef HAVE_STRING_H
106#include <string.h> 106#include <string.h>
107#endif 107#endif
108 108
109#include <unistd.h> 109#include <unistd.h>
110 110
111#ifdef HAVE_UUID_H 
112#include <uuid.h> 
113#endif 
114 
115#include "scsi_cmd_codes.h" 111#include "scsi_cmd_codes.h"
116 112
117#include "iscsi.h" 113#include "iscsi.h"
118#include "compat.h" 114#include "compat.h"
119#include "iscsiutil.h" 115#include "iscsiutil.h"
120#include "device.h" 116#include "device.h"
121#include "target.h" 117#include "target.h"
122#include "defs.h" 118#include "defs.h"
123#include "storage.h" 119#include "storage.h"
124 120
125#define CONFIG_DISK_NUM_LUNS_DFLT 1 121#define CONFIG_DISK_NUM_LUNS_DFLT 1
126#define CONFIG_DISK_BLOCK_LEN_DFLT 512 122#define CONFIG_DISK_BLOCK_LEN_DFLT 512
127#define CONFIG_DISK_NUM_BLOCKS_DFLT 204800 123#define CONFIG_DISK_NUM_BLOCKS_DFLT 204800
@@ -141,27 +137,27 @@ enum { @@ -141,27 +137,27 @@ enum {
141}; 137};
142 138
143#define MB(x) ((x) * 1024 * 1024) 139#define MB(x) ((x) * 1024 * 1024)
144 140
145/* this struct describes an iscsi LUN */ 141/* this struct describes an iscsi LUN */
146typedef struct iscsi_disk_t { 142typedef struct iscsi_disk_t {
147 int type; /* type of disk - fs/mmap and fs */ 143 int type; /* type of disk - fs/mmap and fs */
148 char filename[MAXPATHLEN]; /* filename for the disk itself */ 144 char filename[MAXPATHLEN]; /* filename for the disk itself */
149 uint8_t *buffer; /* buffer for disk read/write ops */ 145 uint8_t *buffer; /* buffer for disk read/write ops */
150 uint64_t blockc; /* # of blocks */ 146 uint64_t blockc; /* # of blocks */
151 uint64_t blocklen; /* block size */ 147 uint64_t blocklen; /* block size */
152 uint64_t luns; /* # of luns */ 148 uint64_t luns; /* # of luns */
153 uint64_t size; /* size of complete disk */ 149 uint64_t size; /* size of complete disk */
154 uuid_t uuid; /* disk's uuid */ 150 nbuuid_t uuid; /* disk's uuid */
155 char *uuid_string; /* uuid string */ 151 char *uuid_string; /* uuid string */
156 targv_t *tv; /* the component devices and extents */ 152 targv_t *tv; /* the component devices and extents */
157 uint32_t resc; /* # of reservation keys */ 153 uint32_t resc; /* # of reservation keys */
158 uint64_t reskeys[MAX_RESERVATIONS]; /* the reservation keys */ 154 uint64_t reskeys[MAX_RESERVATIONS]; /* the reservation keys */
159} iscsi_disk_t; 155} iscsi_disk_t;
160 156
161DEFINE_ARRAY(disks_t, iscsi_disk_t); 157DEFINE_ARRAY(disks_t, iscsi_disk_t);
162 158
163static disks_t disks; 159static disks_t disks;
164static iscsi_disk_t defaults; 160static iscsi_disk_t defaults;
165 161
166#ifndef FDATASYNC 162#ifndef FDATASYNC
167/* 163/*
@@ -966,28 +962,28 @@ device_command(target_session_t * sess,  @@ -966,28 +962,28 @@ device_command(target_session_t * sess,
966 cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_TARGET_PORT << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME; 962 cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_TARGET_PORT << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME;
967 len = (uint8_t) snprintf((char *)&cp[4], 963 len = (uint8_t) snprintf((char *)&cp[4],
968 (unsigned)(*totsize - (int)(cp - &data[4])), 964 (unsigned)(*totsize - (int)(cp - &data[4])),
969 "%s,t,%#x", 965 "%s,t,%#x",
970 sess->globals->targetname, 966 sess->globals->targetname,
971 lun); 967 lun);
972 cp[3] = len; 968 cp[3] = len;
973 *totlen += len + 4; 969 *totlen += len + 4;
974 cp += len + 4; 970 cp += len + 4;
975 /* add target port's IQN + LUN extension */ 971 /* add target port's IQN + LUN extension */
976 cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8; 972 cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8;
977 cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_LOGICAL_UNIT << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME; 973 cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_LOGICAL_UNIT << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME;
978 if (disks.v[sess->d].uuid_string == NULL) { 974 if (disks.v[sess->d].uuid_string == NULL) {
979 uuid_create(&disks.v[sess->d].uuid, &status); 975 nbuuid_create(&disks.v[sess->d].uuid, &status);
980 uuid_to_string(&disks.v[sess->d].uuid, &disks.v[sess->d].uuid_string, &status); 976 nbuuid_to_string(&disks.v[sess->d].uuid, &disks.v[sess->d].uuid_string, &status);
981 } 977 }
982 len = (uint8_t) snprintf((char *)&cp[4], 978 len = (uint8_t) snprintf((char *)&cp[4],
983 (unsigned)(*totsize - (int)(cp - &data[4])), 979 (unsigned)(*totsize - (int)(cp - &data[4])),
984 "%s,L,0x%8.8s%4.4s%4.4s", 980 "%s,L,0x%8.8s%4.4s%4.4s",
985 sess->globals->targetname, 981 sess->globals->targetname,
986 disks.v[sess->d].uuid_string, 982 disks.v[sess->d].uuid_string,
987 &disks.v[sess->d].uuid_string[9], 983 &disks.v[sess->d].uuid_string[9],
988 &disks.v[sess->d].uuid_string[14]); 984 &disks.v[sess->d].uuid_string[14]);
989 cp[3] = len; 985 cp[3] = len;
990 *totlen += len + 4; 986 *totlen += len + 4;
991 cp += len + 4; 987 cp += len + 4;
992 /* add target's uuid as a T10 identifier */ 988 /* add target's uuid as a T10 identifier */
993 cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8; 989 cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8;

cvs diff -r1.3 -r1.4 src/dist/iscsi/src/Attic/uuid.c (expand / switch to unified diff)

--- src/dist/iscsi/src/Attic/uuid.c 2007/06/16 23:13:26 1.3
+++ src/dist/iscsi/src/Attic/uuid.c 2009/06/23 05:11:47 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uuid.c,v 1.3 2007/06/16 23:13:26 agc Exp $ */ 1/* $NetBSD: uuid.c,v 1.4 2009/06/23 05:11:47 agc Exp $ */
2 2
3/* 3/*
4 * Copyright © 2006 Alistair Crooks. All rights reserved. 4 * Copyright © 2006 Alistair Crooks. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote 14 * 3. The name of the author may not be used to endorse or promote
@@ -38,63 +38,56 @@ @@ -38,63 +38,56 @@
38#ifdef HAVE_SYS_PARAM_H 38#ifdef HAVE_SYS_PARAM_H
39#include <sys/param.h> 39#include <sys/param.h>
40#endif 40#endif
41  41
42#ifdef HAVE_SYS_TIME_H 42#ifdef HAVE_SYS_TIME_H
43#include <sys/time.h> 43#include <sys/time.h>
44#endif 44#endif
45 45
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49#include <unistd.h> 49#include <unistd.h>
50 50
51#ifdef HAVE_UUID_H 51#include "storage.h"
52#include <uuid.h> 
53#endif 
54 
55#include "compat.h" 52#include "compat.h"
56#include "defs.h" 53#include "defs.h"
57 54
58#ifndef HAVE_UUID_CREATE 
59/* just fill the struct with random values for now */ 55/* just fill the struct with random values for now */
60void 56void
61uuid_create(uuid_t *uuid, uint32_t *status) 57nbuuid_create(nbuuid_t *uuid, uint32_t *status)
62{ 58{
63 uint64_t ether; 59 uint64_t ether;
64 time_t t; 60 time_t t;
65 61
66 (void) time(&t); 62 (void) time(&t);
67 ether = (random() << 32) | random(); 63 ether = ((uint64_t)random() << 32) | random();
68 uuid->time_low = t; 64 uuid->time_low = t;
69 uuid->time_mid = (uint16_t)(random() & 0xffff); 65 uuid->time_mid = (uint16_t)(random() & 0xffff);
70 uuid->time_hi_and_version = (uint16_t)(random() & 0xffff); 66 uuid->time_hi_and_version = (uint16_t)(random() & 0xffff);
71 uuid->clock_seq_low = random() & 0xff; 67 uuid->clock_seq_low = random() & 0xff;
72 uuid->clock_seq_hi_and_reserved = random() & 0xff; 68 uuid->clock_seq_hi_and_reserved = random() & 0xff;
73 (void) memcpy(&uuid->node, &ether, sizeof(uuid->node)); 69 (void) memcpy(&uuid->node, &ether, sizeof(uuid->node));
74 *status = 0; 70 *status = 0;
75} 71}
76#endif 
77 72
78#ifndef HAVE_UUID_TO_STRING 
79/* convert the struct to a printable string */ 73/* convert the struct to a printable string */
80void 74void
81uuid_to_string(uuid_t *uuid, char **str, uint32_t *status) 75nbuuid_to_string(nbuuid_t *uuid, char **str, uint32_t *status)
82{ 76{
83 char s[64]; 77 char s[64];
84 78
85 (void) snprintf(s, sizeof(s), "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", 79 (void) snprintf(s, sizeof(s), "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
86 uuid->time_low, 80 uuid->time_low,
87 uuid->time_mid, 81 uuid->time_mid,
88 uuid->time_hi_and_version, 82 uuid->time_hi_and_version,
89 uuid->clock_seq_hi_and_reserved, 83 uuid->clock_seq_hi_and_reserved,
90 uuid->clock_seq_low, 84 uuid->clock_seq_low,
91 uuid->node[0], 85 uuid->node[0],
92 uuid->node[1], 86 uuid->node[1],
93 uuid->node[2], 87 uuid->node[2],
94 uuid->node[3], 88 uuid->node[3],
95 uuid->node[4], 89 uuid->node[4],
96 uuid->node[5]); 90 uuid->node[5]);
97 *str = strdup(s); 91 *str = strdup(s);
98 *status = 0; 92 *status = 0;
99} 93}
100#endif