iscsid: fix discoveryd shutdown
[open-iscsi.git] / usr / idbm.h
blob57b9295bea44dbfe7f87641cdca7d14d091ca752
1 /*
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.
22 #ifndef IDBM_H
23 #define IDBM_H
25 #include <stdio.h>
26 #include <sys/types.h>
27 #include "initiator.h"
28 #include "config.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"
38 #define TYPE_INT 0
39 #define TYPE_INT_O 1
40 #define TYPE_STR 2
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. */
44 #define OPTS_MAXVAL 8
45 typedef struct recinfo {
46 int type;
47 char name[NAME_MAXVAL];
48 char value[VALUE_MAXVAL];
49 void *data;
50 int data_len;
51 int visible;
52 char* opts[OPTS_MAXVAL];
53 int numopts;
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.
59 int can_modify;
60 } recinfo_t;
62 typedef char *(idbm_get_config_file_fn)(void);
64 typedef struct idbm {
65 void *discdb;
66 void *nodedb;
67 char *configfile;
68 int refs;
69 idbm_get_config_file_fn *get_config_file;
70 node_rec_t nrec;
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];
78 } idbm_t;
79 struct db_set_param {
80 char *name;
81 char *value;
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,
88 char *targetname);
90 struct rec_op_data {
91 void *data;
92 node_rec_t *match_rec;
93 idbm_iface_op_fn *fn;
95 extern int idbm_for_each_iface(int *found, void *data,
96 idbm_iface_op_fn *fn,
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,
113 char *prefix);
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,
122 int overwrite);
123 struct list_head;
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,
133 int port);
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,
152 int line_number);
153 extern void idbm_recinfo_node(node_rec_t *r, recinfo_t *ri);
155 enum {
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);
163 struct boot_context;
164 extern struct node_rec *idbm_create_rec(char *targetname, int tpgt,
165 char *ip, int port,
166 struct iface_rec *iface,
167 int verbose);
168 extern struct node_rec *
169 idbm_create_rec_from_boot_context(struct boot_context *context);
171 #endif /* IDBM_H */