nfs-ganesha 1.4
|
00001 00002 #include "ganesha_rpc.h" 00003 #include "config_parsing.h" 00004 #include "nfs_core.h" 00005 #include "nfs_exports.h" 00006 #include "config_parsing.h" 00007 #include <stdlib.h> 00008 #include <string.h> 00009 #include <arpa/inet.h> 00010 #include "../MainNFSD/nfs_init.h" 00011 #include "nfs23.h" 00012 00013 #define MOUNT_PROGRAM 100005 00014 nfs_parameter_t nfs_param; 00015 00016 char out[MAXHOSTNAMELEN]; 00017 00018 #define EQUALS(a, b, msg, args...) do { \ 00019 if (a != b) { \ 00020 printf(msg "\n", ## args); \ 00021 exit(1); \ 00022 } \ 00023 } while(0) 00024 00025 #define CMP(a, b, n, msg) do { \ 00026 if (strncmp(a, b, n) != 0) { \ 00027 printf(msg "\n"); \ 00028 exit(1); \ 00029 } \ 00030 } while(0) 00031 00032 sockaddr_t ipv4a; 00033 sockaddr_t ipv4b; 00034 sockaddr_t ipv4c; 00035 char name4a[MAXHOSTNAMELEN]; 00036 char name4c[MAXHOSTNAMELEN]; 00037 sockaddr_t ipv6a; 00038 sockaddr_t ipv6b; 00039 sockaddr_t ipv6c; 00040 char name6a[MAXHOSTNAMELEN]; 00041 char name6c[MAXHOSTNAMELEN]; 00042 00043 void *rpc_tcp_socket_manager_thread(void *Arg) 00044 { 00045 return NULL; 00046 } 00047 00048 void create_ipv4(char * ip, int port, struct sockaddr_in * addr) 00049 { 00050 memset(addr, 0, sizeof(struct sockaddr_in)); 00051 addr->sin_family = AF_INET; 00052 addr->sin_port = port; 00053 inet_pton(AF_INET, ip, &(addr->sin_addr)); 00054 } 00055 00056 void create_ipv6(char * ip, int port, struct sockaddr_in6 * addr) 00057 { 00058 memset(addr, 0, sizeof(struct sockaddr_in6)); 00059 addr->sin6_family = AF_INET6; 00060 addr->sin6_port = port; 00061 inet_pton(AF_INET6, ip, &(addr->sin6_addr.s6_addr)); 00062 } 00063 00064 void create_svc_req(struct svc_req *req, rpcvers_t ver, rpcprog_t prog, rpcproc_t proc) 00065 { 00066 memset(req, 0, sizeof(struct svc_req)); 00067 req->rq_prog = prog; 00068 req->rq_vers = ver; 00069 req->rq_proc = proc; 00070 } 00071 00072 void nfs_set_ip_name_param_default() 00073 { 00074 nfs_param.ip_name_param.hash_param.index_size = PRIME_IP_NAME; 00075 nfs_param.ip_name_param.hash_param.alphabet_length = 10; /* ipaddr is a numerical decimal value */ 00076 nfs_param.ip_name_param.hash_param.nb_node_prealloc = NB_PREALLOC_HASH_IP_NAME; 00077 nfs_param.ip_name_param.hash_param.hash_func_key = ip_name_value_hash_func; 00078 nfs_param.ip_name_param.hash_param.hash_func_rbt = ip_name_rbt_hash_func; 00079 nfs_param.ip_name_param.hash_param.compare_key = compare_ip_name; 00080 nfs_param.ip_name_param.hash_param.key_to_str = display_ip_name_key; 00081 nfs_param.ip_name_param.hash_param.val_to_str = display_ip_name_val; 00082 nfs_param.ip_name_param.hash_param.name = "IP Name"; 00083 nfs_param.ip_name_param.hash_param.flags = HASH_FLAG_NONE; 00084 nfs_param.ip_name_param.expiration_time = IP_NAME_EXPIRATION; 00085 strncpy(nfs_param.ip_name_param.mapfile, "", MAXPATHLEN); 00086 00087 nfs_param.core_param.dump_stats_per_client = 1; 00088 00089 } 00090 00091 void init() 00092 { 00093 nfs_set_ip_name_param_default(); 00094 nfs_Init_ip_name(nfs_param.ip_name_param); 00095 00096 create_ipv4("127.0.0.1", 2048, (struct sockaddr_in * ) &ipv4a); 00097 // create_ipv4("10.10.5.1", 2049, (struct sockaddr_in * ) &ipv4b); 00098 create_ipv4("127.0.0.2", 2048, (struct sockaddr_in * ) &ipv4c); 00099 00100 #ifdef _USE_TIRPC 00101 create_ipv6("::1", 2048, (struct sockaddr_in6 *) &ipv6a); 00102 // create_ipv6("2001::1", 2049, (struct sockaddr_in6 *) &ipv6b); 00103 create_ipv6("fe00::0", 2048, (struct sockaddr_in6 *) &ipv6c); 00104 #endif 00105 00106 } 00107 00108 void test_not_found() 00109 { 00110 EQUALS(nfs_ip_name_get(&ipv4a, out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv4a yet"); 00111 // EQUALS(nfs_ip_name_get(ipname, &ipv4b, &out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv4b yet"); 00112 EQUALS(nfs_ip_name_get(&ipv4c, out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv4c yet"); 00113 } 00114 00115 void test_not_found_bc() 00116 { 00117 EQUALS(nfs_ip_name_get(&ipv4a, out), IP_NAME_SUCCESS, "There should be an ipv4a"); 00118 // EQUALS(nfs_ip_name_get(ipname, &ipv4b, &out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv4b yet"); 00119 EQUALS(nfs_ip_name_get(&ipv4c, out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv4c yet"); 00120 } 00121 00122 void test_not_found_c() 00123 { 00124 EQUALS(nfs_ip_name_get(&ipv4a, out), IP_NAME_SUCCESS, "There should be an ipv4a"); 00125 // EQUALS(nfs_ip_name_get(ipname, &ipv4b, &out), IP_NAME_SUCCESS, "There should be an ipv4b"); 00126 EQUALS(nfs_ip_name_get(&ipv4c, out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv4c yet"); 00127 } 00128 00129 void test_not_found_none() 00130 { 00131 EQUALS(nfs_ip_name_get(&ipv4a, out), IP_NAME_SUCCESS, "There should be an ipv4a"); 00132 // EQUALS(nfs_ip_name_get(ipname, &ipv4b, &out), IP_NAME_SUCCESS, "There should be an ipv4b"); 00133 EQUALS(nfs_ip_name_get(&ipv4c, out), IP_NAME_SUCCESS, "There should be an ipv4c"); 00134 } 00135 00136 00137 void test_add() 00138 { 00139 int rc = nfs_ip_name_add(&ipv4a, name4a); 00140 EQUALS(rc, IP_NAME_SUCCESS, "Can't add ipv4a, rc = %d", rc); 00141 test_not_found_bc(); 00142 00143 /* rc = nfs_ip_name_add(ipname, &ipv4b, &ip_name_pool); */ 00144 /* EQUALS(rc, IP_NAME_SUCCESS, "Can't add ipv4b"); */ 00145 /* test_not_found_c(); */ 00146 00147 rc = nfs_ip_name_add(&ipv4c, name4c); 00148 EQUALS(rc, IP_NAME_SUCCESS, "Can't add ipv4c"); 00149 test_not_found_none(); 00150 } 00151 00152 00153 // check that counts look right, including a check on something we didn't set so that it's actually removed correctly 00154 void test_get() 00155 { 00156 00157 } 00158 00159 // remove then re-add ipv4c to test the removal path 00160 void test_remove() 00161 { 00162 int rc; 00163 rc = nfs_ip_name_remove(&ipv4c); 00164 test_not_found_c(); 00165 EQUALS(rc, IP_NAME_SUCCESS, "Can't remove ipv4c"); 00166 00167 rc = nfs_ip_name_remove(&ipv4c); 00168 test_not_found_c(); 00169 EQUALS(rc, IP_NAME_NOT_FOUND, "Can't remove ipv4c"); 00170 00171 rc = nfs_ip_name_add(&ipv4c, name4c); 00172 EQUALS(rc, IP_NAME_SUCCESS, "Can't add ipv4c"); 00173 test_not_found_none(); 00174 } 00175 00176 // The IPv6 versions of all of the tests 00177 // 00178 // 00179 00180 void test_not_found_6() 00181 { 00182 EQUALS(nfs_ip_name_get(&ipv6a, out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv6a yet"); 00183 // EQUALS(nfs_ip_name_get(ipname, &ipv6b, &out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv6b yet"); 00184 EQUALS(nfs_ip_name_get(&ipv6c, out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv6c yet"); 00185 } 00186 00187 void test_not_found_bc_6() 00188 { 00189 EQUALS(nfs_ip_name_get(&ipv6a, out), IP_NAME_SUCCESS, "There should be an ipv6a"); 00190 // EQUALS(nfs_ip_name_get(ipname, &ipv6b, &out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv6b yet"); 00191 EQUALS(nfs_ip_name_get(&ipv6c, out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv6c yet"); 00192 } 00193 00194 void test_not_found_c_6() 00195 { 00196 EQUALS(nfs_ip_name_get(&ipv6a, out), IP_NAME_SUCCESS, "There should be an ipv6a"); 00197 // EQUALS(nfs_ip_name_get(ipname, &ipv6b, &out), IP_NAME_SUCCESS, "There should be an ipv6b"); 00198 EQUALS(nfs_ip_name_get(&ipv6c, out), IP_NAME_NOT_FOUND, "There shouldn't be an ipv6c yet"); 00199 } 00200 00201 void test_not_found_none_6() 00202 { 00203 EQUALS(nfs_ip_name_get(&ipv6a, out), IP_NAME_SUCCESS, "There should be an ipv6a"); 00204 // EQUALS(nfs_ip_name_get(ipname, &ipv6b, &out), IP_NAME_SUCCESS, "There should be an ipv6b"); 00205 EQUALS(nfs_ip_name_get(&ipv6c, out), IP_NAME_SUCCESS, "There should be an ipv6c"); 00206 } 00207 00208 00209 void test_add_6() 00210 { 00211 int rc = nfs_ip_name_add(&ipv6a, name6a); 00212 EQUALS(rc, IP_NAME_SUCCESS, "Can't add ipv6a, rc = %d", rc); 00213 test_not_found_bc_6(); 00214 00215 /* rc = nfs_ip_name_add(ipname, &ipv6b, &ip_name_pool); */ 00216 /* EQUALS(rc, IP_NAME_SUCCESS, "Can't add ipv6b"); */ 00217 /* test_not_found_c_6(); */ 00218 00219 rc = nfs_ip_name_add(&ipv6c, name6c); 00220 EQUALS(rc, IP_NAME_SUCCESS, "Can't add ipv6c"); 00221 test_not_found_none_6(); 00222 } 00223 00224 00225 // check that counts look right, including a check on something we didn't set so that it's actually removed correctly 00226 void test_get_6() 00227 { 00228 00229 } 00230 00231 // remove then re-add ipv6c to test the removal path 00232 void test_remove_6() 00233 { 00234 int rc; 00235 rc = nfs_ip_name_remove(&ipv6c); 00236 test_not_found_c_6(); 00237 EQUALS(rc, IP_NAME_SUCCESS, "Can't remove ipv6c"); 00238 00239 rc = nfs_ip_name_remove(&ipv6c); 00240 test_not_found_c_6(); 00241 EQUALS(rc, IP_NAME_NOT_FOUND, "Can't remove ipv6c"); 00242 00243 rc = nfs_ip_name_add(&ipv6c, name6c); 00244 EQUALS(rc, IP_NAME_SUCCESS, "Can't add ipv6c"); 00245 test_not_found_none_6(); 00246 } 00247 00248 // 00249 00250 int main() 00251 { 00252 int i; 00253 00254 init(); 00255 test_not_found(); 00256 test_add(); 00257 test_get(); 00258 for (i = 0; i < 5; i++) { 00259 test_remove(); 00260 } 00261 00262 #ifdef _USE_TIRPC 00263 test_not_found_6(); 00264 test_add_6(); 00265 test_get_6(); 00266 for (i = 0; i < 5; i++) { 00267 test_remove_6(); 00268 } 00269 #endif 00270 00271 return 0; 00272 }