2 * iSCSI Discovery Database Library
4 * Copyright (C) 2004 Dmitry Yusupov, Alex Aizman
5 * Copyright (C) 2006 Mike Christie
6 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
7 * maintained by open-iscsi@@googlegroups.com
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * See the file COPYING included with this distribution for more details.
26 #include <sys/types.h>
27 #include "initiator.h"
30 #define NODE_CONFIG_DIR ISCSI_CONFIG_ROOT"nodes"
31 #define SLP_CONFIG_DIR ISCSI_CONFIG_ROOT"slp"
32 #define ISNS_CONFIG_DIR ISCSI_CONFIG_ROOT"isns"
33 #define STATIC_CONFIG_DIR ISCSI_CONFIG_ROOT"static"
34 #define FW_CONFIG_DIR ISCSI_CONFIG_ROOT"fw"
35 #define ST_CONFIG_DIR ISCSI_CONFIG_ROOT"send_targets"
36 #define ST_CONFIG_NAME "st_config"
41 #define MAX_KEYS 256 /* number of keys total(including CNX_MAX) */
42 #define NAME_MAXVAL 128 /* the maximum length of key name */
43 #define VALUE_MAXVAL 256 /* the maximum length of 223 bytes in the RFC. */
45 typedef struct recinfo
{
47 char name
[NAME_MAXVAL
];
48 char value
[VALUE_MAXVAL
];
52 char* opts
[OPTS_MAXVAL
];
55 * bool indicating if we can change it or not.
56 * TODO: make it a enum that can indicate wheter it also requires
57 * a relogin to pick up if a session is running.
62 typedef char *(idbm_get_config_file_fn
)(void);
69 idbm_get_config_file_fn
*get_config_file
;
71 recinfo_t ninfo
[MAX_KEYS
];
72 discovery_rec_t drec_st
;
73 recinfo_t dinfo_st
[MAX_KEYS
];
74 discovery_rec_t drec_slp
;
75 recinfo_t dinfo_slp
[MAX_KEYS
];
76 discovery_rec_t drec_isns
;
77 recinfo_t dinfo_isns
[MAX_KEYS
];
84 typedef int (idbm_iface_op_fn
)(void *data
, node_rec_t
*rec
);
85 typedef int (idbm_portal_op_fn
)(int *found
, void *data
,
86 char *targetname
, int tpgt
, char *ip
, int port
);
87 typedef int (idbm_node_op_fn
)(int *found
, void *data
,
92 node_rec_t
*match_rec
;
95 extern int idbm_for_each_iface(int *found
, void *data
,
97 char *targetname
, int tpgt
, char *ip
, int port
);
98 extern int idbm_for_each_portal(int *found
, void *data
,
99 idbm_portal_op_fn
*fn
, char *targetname
);
100 extern int idbm_for_each_node(int *found
, void *data
,
101 idbm_node_op_fn
*fn
);
102 extern int idbm_for_each_rec(int *found
, void *data
,
103 idbm_iface_op_fn
*fn
);
105 extern int idbm_init(idbm_get_config_file_fn
*fn
);
107 extern void idbm_node_setup_from_conf(node_rec_t
*rec
);
108 extern void idbm_terminate(void);
109 extern int idbm_print_iface_info(void *data
, struct iface_rec
*iface
);
110 extern int idbm_print_node_info(void *data
, node_rec_t
*rec
);
111 extern int idbm_print_node_flat(void *data
, node_rec_t
*rec
);
112 extern int idbm_print_node_tree(struct node_rec
*last_rec
, struct node_rec
*rec
,
114 extern int idbm_print_node_and_iface_tree(void *data
, node_rec_t
*rec
);
115 extern int idbm_print_discovery_info(discovery_rec_t
*rec
, int show
);
116 extern int idbm_print_all_discovery(int info_level
);
117 extern int idbm_print_discovered(discovery_rec_t
*drec
, int info_level
);
118 extern int idbm_delete_discovery(discovery_rec_t
*rec
);
119 extern void idbm_node_setup_defaults(node_rec_t
*rec
);
120 extern int idbm_delete_node(node_rec_t
*rec
);
121 extern int idbm_add_node(node_rec_t
*newrec
, discovery_rec_t
*drec
,
124 typedef int (idbm_disc_nodes_fn
)(void *data
, struct iface_rec
*iface
,
125 struct list_head
*recs
);
126 extern int idbm_bind_ifaces_to_nodes(idbm_disc_nodes_fn
*disc_node_fn
,
127 void *data
, struct list_head
*ifaces
,
128 struct list_head
*bound_recs
);
129 extern int idbm_add_discovery(discovery_rec_t
*newrec
);
130 extern void idbm_sendtargets_defaults(struct iscsi_sendtargets_config
*cfg
);
131 extern void idbm_slp_defaults(struct iscsi_slp_config
*cfg
);
132 extern int idbm_discovery_read(discovery_rec_t
*rec
, char *addr
,
134 extern int idbm_rec_read(node_rec_t
*out_rec
, char *target_name
,
135 int tpgt
, char *addr
, int port
,
136 struct iface_rec
*iface
);
137 extern int idbm_node_set_param(void *data
, node_rec_t
*rec
);
138 extern int idbm_discovery_set_param(void *data
, discovery_rec_t
*rec
);
139 extern void idbm_node_setup_defaults(node_rec_t
*rec
);
140 extern struct node_rec
*idbm_find_rec_in_list(struct list_head
*rec_list
,
141 char *targetname
, char *addr
,
142 int port
, struct iface_rec
*iface
);
144 /* lower level idbm functions for use by iface.c */
145 extern void idbm_recinfo_config(recinfo_t
*info
, FILE *f
);
146 extern void idbm_recinfo_iface(struct iface_rec
*r
, recinfo_t
*ri
);
147 extern int idbm_lock(void);
148 extern void idbm_unlock(void);
149 extern recinfo_t
*idbm_recinfo_alloc(int max_keys
);
150 extern int idbm_verify_param(recinfo_t
*info
, char *name
);
151 extern int idbm_rec_update_param(recinfo_t
*info
, char *name
, char *value
,
153 extern void idbm_recinfo_node(node_rec_t
*r
, recinfo_t
*ri
);
156 IDBM_PRINT_TYPE_DISCOVERY
,
157 IDBM_PRINT_TYPE_NODE
,
158 IDBM_PRINT_TYPE_IFACE
,
161 extern void idbm_print(int type
, void *rec
, int show
, FILE *f
);
164 extern struct node_rec
*idbm_create_rec(char *targetname
, int tpgt
,
166 struct iface_rec
*iface
,
168 extern struct node_rec
*
169 idbm_create_rec_from_boot_context(struct boot_context
*context
);