Home | History | Annotate | Line # | Download | only in include
      1 /* $NetBSD: storage.h,v 1.3 2009/06/30 02:44:52 agc Exp $ */
      2 
      3 /*
      4  * Copyright  2006 Alistair Crooks.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     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
     15  *    products derived from this software without specific prior written
     16  *    permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     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.
     29  */
     30 #ifndef STORAGE_H_
     31 #define STORAGE_H_
     32 
     33 #include "defs.h"
     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  */
     45 typedef 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 
     54 void    nbuuid_create(nbuuid_t *, uint32_t *);
     55 void    nbuuid_to_string(nbuuid_t *, char **, uint32_t *);
     56 
     57 enum {
     58 	DE_EXTENT,
     59 	DE_DEVICE
     60 };
     61 
     62 /* a device can be made up of an extent or another device */
     63 typedef struct disc_de_t {
     64 	int32_t		type;		/* device or extent */
     65 	uint64_t	size;		/* size of underlying extent or device */
     66 	union {
     67 		struct disc_extent_t	*xp;	/* pointer to extent */
     68 		struct disc_device_t	*dp;	/* pointer to device */
     69 	} u;
     70 } disc_de_t;
     71 
     72 /* this struct describes an extent of storage */
     73 typedef struct disc_extent_t {
     74 	char		*extent;	/* extent name */
     75 	char		*dev;		/* device associated with it */
     76 	uint64_t	sacred;		/* offset of extent from start of dev */
     77 	uint64_t	len;		/* size of extent */
     78 	int		fd;		/* in-core file descriptor */
     79 	int		used;		/* extent has been used in a device */
     80 } disc_extent_t;
     81 
     82 DEFINE_ARRAY(extv_t, disc_extent_t);
     83 
     84 /* this struct describes a device */
     85 typedef struct disc_device_t {
     86 	char		*dev;		/* device name */
     87 	int		raid;		/* RAID level */
     88 	uint64_t	off;		/* current offset in device */
     89 	uint64_t	len;		/* size of device */
     90 	uint32_t	size;		/* size of device/extent array */
     91 	uint32_t	c;		/* # of entries in device/extents */
     92 	disc_de_t	*xv;		/* device/extent array */
     93 	int		used;		/* device has been used in a device/target */
     94 } disc_device_t;
     95 
     96 DEFINE_ARRAY(devv_t, disc_device_t);
     97 
     98 enum {
     99 	TARGET_READONLY = 0x01
    100 };
    101 
    102 /* this struct describes an iscsi target's associated features */
    103 typedef struct disc_target_t {
    104 	char		*target;	/* target name */
    105 	disc_de_t	 de;		/* pointer to its device */
    106 	uint16_t	 port;		/* port to listen on */
    107 	char		*mask;		/* mask to export it to */
    108 	uint32_t	 flags;		/* any flags */
    109 	uint16_t	 tsih;		/* target session identifying handle */
    110 	char		*iqn;		/* assigned iqn - can be NULL */
    111 } disc_target_t;
    112 
    113 DEFINE_ARRAY(targv_t, disc_target_t);
    114 
    115 int read_conf_file(const char *, targv_t *, devv_t *, extv_t *);
    116 
    117 #endif /* !STORAGE_H_ */
    118