1*5e01dafbSagc /* $NetBSD: storage.h,v 1.3 2009/06/30 02:44:52 agc Exp $ */ 22f245829Sagc 32f245829Sagc /* 42f245829Sagc * Copyright � 2006 Alistair Crooks. All rights reserved. 52f245829Sagc * 62f245829Sagc * Redistribution and use in source and binary forms, with or without 72f245829Sagc * modification, are permitted provided that the following conditions 82f245829Sagc * are met: 92f245829Sagc * 1. Redistributions of source code must retain the above copyright 102f245829Sagc * notice, this list of conditions and the following disclaimer. 112f245829Sagc * 2. Redistributions in binary form must reproduce the above copyright 122f245829Sagc * notice, this list of conditions and the following disclaimer in the 132f245829Sagc * documentation and/or other materials provided with the distribution. 142f245829Sagc * 3. The name of the author may not be used to endorse or promote 152f245829Sagc * products derived from this software without specific prior written 162f245829Sagc * permission. 172f245829Sagc * 182f245829Sagc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 192f245829Sagc * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 202f245829Sagc * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212f245829Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 222f245829Sagc * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 232f245829Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 242f245829Sagc * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 252f245829Sagc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 262f245829Sagc * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 272f245829Sagc * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 282f245829Sagc * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292f245829Sagc */ 302f245829Sagc #ifndef STORAGE_H_ 312f245829Sagc #define STORAGE_H_ 322f245829Sagc 332f245829Sagc #include "defs.h" 342f245829Sagc 35b6364952Sagc /* Length of a node address (an IEEE 802 address). */ 36b6364952Sagc #define NB_UUID_NODE_LEN 6 37b6364952Sagc 38b6364952Sagc /* 39b6364952Sagc * See also: 40b6364952Sagc * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt 41b6364952Sagc * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm 42b6364952Sagc * 43b6364952Sagc * A DCE 1.1 compatible source representation of UUIDs. 44b6364952Sagc */ 45b6364952Sagc typedef struct nbuuid_t { 46b6364952Sagc uint32_t time_low; 47b6364952Sagc uint16_t time_mid; 48b6364952Sagc uint16_t time_hi_and_version; 49b6364952Sagc uint8_t clock_seq_hi_and_reserved; 50b6364952Sagc uint8_t clock_seq_low; 51b6364952Sagc uint8_t node[NB_UUID_NODE_LEN]; 52b6364952Sagc } nbuuid_t; 53b6364952Sagc 54b6364952Sagc void nbuuid_create(nbuuid_t *, uint32_t *); 55b6364952Sagc void nbuuid_to_string(nbuuid_t *, char **, uint32_t *); 56b6364952Sagc 572f245829Sagc enum { 582f245829Sagc DE_EXTENT, 592f245829Sagc DE_DEVICE 602f245829Sagc }; 612f245829Sagc 622f245829Sagc /* a device can be made up of an extent or another device */ 632f245829Sagc typedef struct disc_de_t { 642f245829Sagc int32_t type; /* device or extent */ 652f245829Sagc uint64_t size; /* size of underlying extent or device */ 662f245829Sagc union { 672f245829Sagc struct disc_extent_t *xp; /* pointer to extent */ 682f245829Sagc struct disc_device_t *dp; /* pointer to device */ 692f245829Sagc } u; 702f245829Sagc } disc_de_t; 712f245829Sagc 722f245829Sagc /* this struct describes an extent of storage */ 732f245829Sagc typedef struct disc_extent_t { 742f245829Sagc char *extent; /* extent name */ 752f245829Sagc char *dev; /* device associated with it */ 76b6364952Sagc uint64_t sacred; /* offset of extent from start of dev */ 772f245829Sagc uint64_t len; /* size of extent */ 782f245829Sagc int fd; /* in-core file descriptor */ 792f245829Sagc int used; /* extent has been used in a device */ 802f245829Sagc } disc_extent_t; 812f245829Sagc 822f245829Sagc DEFINE_ARRAY(extv_t, disc_extent_t); 832f245829Sagc 842f245829Sagc /* this struct describes a device */ 852f245829Sagc typedef struct disc_device_t { 862f245829Sagc char *dev; /* device name */ 872f245829Sagc int raid; /* RAID level */ 882f245829Sagc uint64_t off; /* current offset in device */ 892f245829Sagc uint64_t len; /* size of device */ 902f245829Sagc uint32_t size; /* size of device/extent array */ 912f245829Sagc uint32_t c; /* # of entries in device/extents */ 922f245829Sagc disc_de_t *xv; /* device/extent array */ 932f245829Sagc int used; /* device has been used in a device/target */ 942f245829Sagc } disc_device_t; 952f245829Sagc 962f245829Sagc DEFINE_ARRAY(devv_t, disc_device_t); 972f245829Sagc 982f245829Sagc enum { 992f245829Sagc TARGET_READONLY = 0x01 1002f245829Sagc }; 1012f245829Sagc 1022f245829Sagc /* this struct describes an iscsi target's associated features */ 1032f245829Sagc typedef struct disc_target_t { 1042f245829Sagc char *target; /* target name */ 1052f245829Sagc disc_de_t de; /* pointer to its device */ 1062f245829Sagc uint16_t port; /* port to listen on */ 1072f245829Sagc char *mask; /* mask to export it to */ 1082f245829Sagc uint32_t flags; /* any flags */ 1092f245829Sagc uint16_t tsih; /* target session identifying handle */ 1102f245829Sagc char *iqn; /* assigned iqn - can be NULL */ 1112f245829Sagc } disc_target_t; 1122f245829Sagc 1132f245829Sagc DEFINE_ARRAY(targv_t, disc_target_t); 1142f245829Sagc 1152f245829Sagc int read_conf_file(const char *, targv_t *, devv_t *, extv_t *); 1162f245829Sagc 1172f245829Sagc #endif /* !STORAGE_H_ */ 118