nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 */ 00004 00014 #ifdef HAVE_CONFIG_H 00015 #include "config.h" 00016 #endif 00017 00018 #include "fsal.h" 00019 #include "log.h" 00020 #include <unistd.h> /* for using gethostname */ 00021 #include <stdlib.h> /* for using exit */ 00022 #include <string.h> 00023 #include <sys/types.h> 00024 00025 #define READDIR_SIZE 5 00026 00027 void printmask(fsal_attrib_mask_t mask) 00028 { 00029 00030 if(FSAL_TEST_MASK(mask, FSAL_ATTR_SUPPATTR)) 00031 LogTest("FSAL_ATTR_SUPPATTR"); 00032 if(FSAL_TEST_MASK(mask, FSAL_ATTR_TYPE)) 00033 LogTest("FSAL_ATTR_TYPE"); 00034 if(FSAL_TEST_MASK(mask, FSAL_ATTR_SIZE)) 00035 LogTest("FSAL_ATTR_SIZE"); 00036 if(FSAL_TEST_MASK(mask, FSAL_ATTR_FSID)) 00037 LogTest("FSAL_ATTR_FSID"); 00038 if(FSAL_TEST_MASK(mask, FSAL_ATTR_ACL)) 00039 LogTest("FSAL_ATTR_ACL "); 00040 if(FSAL_TEST_MASK(mask, FSAL_ATTR_FILEID)) 00041 LogTest("FSAL_ATTR_FILEID"); 00042 if(FSAL_TEST_MASK(mask, FSAL_ATTR_MODE)) 00043 LogTest("FSAL_ATTR_MODE"); 00044 if(FSAL_TEST_MASK(mask, FSAL_ATTR_NUMLINKS)) 00045 LogTest("FSAL_ATTR_NUMLINKS"); 00046 if(FSAL_TEST_MASK(mask, FSAL_ATTR_OWNER)) 00047 LogTest("FSAL_ATTR_OWNER"); 00048 if(FSAL_TEST_MASK(mask, FSAL_ATTR_GROUP)) 00049 LogTest("FSAL_ATTR_GROUP"); 00050 if(FSAL_TEST_MASK(mask, FSAL_ATTR_RAWDEV)) 00051 LogTest("FSAL_ATTR_RAWDEV"); 00052 if(FSAL_TEST_MASK(mask, FSAL_ATTR_ATIME)) 00053 LogTest("FSAL_ATTR_ATIME"); 00054 if(FSAL_TEST_MASK(mask, FSAL_ATTR_CREATION)) 00055 LogTest("FSAL_ATTR_CREATION"); 00056 if(FSAL_TEST_MASK(mask, FSAL_ATTR_CTIME)) 00057 LogTest("FSAL_ATTR_CTIME"); 00058 if(FSAL_TEST_MASK(mask, FSAL_ATTR_CHGTIME)) 00059 LogTest("FSAL_ATTR_CHGTIME"); 00060 if(FSAL_TEST_MASK(mask, FSAL_ATTR_MTIME)) 00061 LogTest("FSAL_ATTR_MTIME"); 00062 if(FSAL_TEST_MASK(mask, FSAL_ATTR_SPACEUSED)) 00063 LogTest("FSAL_ATTR_SPACEUSED"); 00064 if(FSAL_TEST_MASK(mask, FSAL_ATTR_MOUNTFILEID)) 00065 LogTest("FSAL_ATTR_MOUNTFILEID"); 00066 00067 } 00068 00069 char *strtype(fsal_nodetype_t type) 00070 { 00071 switch (type) 00072 { 00073 case FSAL_TYPE_FIFO: 00074 return "FSAL_TYPE_FIFO "; 00075 case FSAL_TYPE_CHR: 00076 return "FSAL_TYPE_CHR "; 00077 case FSAL_TYPE_DIR: 00078 return "FSAL_TYPE_DIR "; 00079 case FSAL_TYPE_BLK: 00080 return "FSAL_TYPE_BLK "; 00081 case FSAL_TYPE_FILE: 00082 return "FSAL_TYPE_FILE "; 00083 case FSAL_TYPE_LNK: 00084 return "FSAL_TYPE_LNK "; 00085 case FSAL_TYPE_JUNCTION: 00086 return "FSAL_TYPE_JUNCTION"; 00087 case 0: 00088 return "(null) "; 00089 00090 default: 00091 return "Unknown type"; 00092 } 00093 } 00094 00095 void printattributes(fsal_attrib_list_t attrs) 00096 { 00097 00098 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_RDATTR_ERR)) 00099 LogTest("FSAL_ATTR_RDATTR_ERR"); 00100 00101 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_TYPE)) 00102 LogTest("Type : %s", strtype(attrs.type)); 00103 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_SIZE)) 00104 LogTest("Size : %llu", attrs.filesize); 00105 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_FSID)) 00106 LogTest("fsId : %llu.%llu", attrs.fsid.major, attrs.fsid.minor); 00107 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_ACL)) 00108 LogTest("ACL List ..."); 00109 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_FILEID)) 00110 LogTest("FileId : %llu", attrs.fileid); 00111 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MODE)) 00112 LogTest("Mode : %#o", attrs.mode); 00113 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_NUMLINKS)) 00114 LogTest("Numlinks : %u", (unsigned int)attrs.numlinks); 00115 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_OWNER)) 00116 LogTest("uid : %d", attrs.owner); 00117 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_GROUP)) 00118 LogTest("gid : %d", attrs.group); 00119 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_RAWDEV)) 00120 LogTest("Rawdev ..."); 00121 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_ATIME)) 00122 LogTest("atime : %s", ctime((time_t *) & attrs.atime.seconds)); 00123 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_CREATION)) 00124 LogTest("creation time : %s", ctime((time_t *) & attrs.creation.seconds)); 00125 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_CTIME)) 00126 LogTest("ctime : %s", ctime((time_t *) & attrs.ctime.seconds)); 00127 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MTIME)) 00128 LogTest("mtime : %s", ctime((time_t *) & attrs.mtime.seconds)); 00129 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_CHGTIME)) 00130 LogTest("chgtime : %s", ctime((time_t *) & attrs.chgtime.seconds)); 00131 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_SPACEUSED)) 00132 LogTest("spaceused : %llu", attrs.spaceused); 00133 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MOUNTFILEID)) 00134 LogTest("mounted_on_fileid : %llu", attrs.mounted_on_fileid); 00135 00136 } 00137 00138 void usage() 00139 { 00140 LogTest( "Usage :\n\ttest_fsal <no_test>"); 00141 LogTest( "\ttests :"); 00142 LogTest( "\t\t1 - getattrs"); 00143 LogTest( "\t\t2 - lookup"); 00144 LogTest( "\t\t3 - lookupPath"); 00145 LogTest( "\t\t4 - readdir (acces par tableau)"); 00146 LogTest( "\t\t5 - readdir (acces liste chainee)"); 00147 LogTest( "\t\t6 - access/test_access"); 00148 LogTest( "\t\t7 - snprintmem/sscanmem"); 00149 LogTest( "\t\t8 - mkdir/rmdir"); 00150 LogTest( "\t\t9 - setattr"); 00151 LogTest( "\t\tA - digest/expend handle"); 00152 LogTest( "\t\tB - dynamic fs info"); 00153 return; 00154 } 00155 00156 int main(int argc, char **argv) 00157 { 00158 00159 char localmachine[256]; 00160 char *test; 00161 fsal_parameter_t init_param; 00162 fsal_status_t st; 00163 uid_t uid; 00164 fsal_export_context_t export_ctx; 00165 fsal_op_context_t op_ctx; 00166 fsal_handle_t root_handle, handle; 00167 fsal_name_t name; 00168 fsal_path_t path; 00169 fsal_attrib_list_t attribs; 00170 fsal_attrib_mask_t mask; 00171 00172 char tracebuff[256]; 00173 00174 if(argc < 2) 00175 { 00176 usage(); 00177 exit(-1); 00178 } 00179 test = argv[1]; 00180 /* retrieving params */ 00181 00182 /* init debug */ 00183 00184 SetNamePgm("test_fsal"); 00185 SetDefaultLogging("TEST"); 00186 SetNameFunction("main"); 00187 InitLogging(); 00188 00189 /* Obtention du nom de la machine */ 00190 if(gethostname(localmachine, sizeof(localmachine)) != 0) 00191 { 00192 LogError(COMPONENT_STDOUT,ERR_SYS, ERR_GETHOSTNAME, errno); 00193 exit(1); 00194 } 00195 else 00196 SetNameHost(localmachine); 00197 00198 AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL); 00199 00200 /* prepare fsal_init */ 00201 00202 /* 1 - fs specific info */ 00203 00204 #ifdef _USE_HPSS_51 00205 00206 init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE; 00207 strcpy(init_param.fs_specific_info.hpss_config.PrincipalName, "hpss_nfs"); 00208 00209 init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE; 00210 strcpy(init_param.fs_specific_info.hpss_config.KeytabPath, "/krb5/hpssserver.keytab"); 00211 00212 #elif defined _USE_HPSS_62 00213 init_param.fs_specific_info.behaviors.AuthnMech = FSAL_INIT_FORCE_VALUE; 00214 init_param.fs_specific_info.hpss_config.AuthnMech = hpss_authn_mech_krb5; 00215 00216 init_param.fs_specific_info.behaviors.Principal = FSAL_INIT_FORCE_VALUE; 00217 strcpy(init_param.fs_specific_info.Principal, "hpssfs"); 00218 00219 init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE; 00220 strcpy(init_param.fs_specific_info.KeytabPath, "/var/hpss/etc/hpss.keytab"); 00221 00222 #endif 00223 00224 /* 2-common info (default) */ 00225 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize); 00226 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink); 00227 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen); 00228 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen); 00229 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc); 00230 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted); 00231 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive); 00232 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving); 00233 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type); 00234 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support); 00235 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support); 00236 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr); 00237 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles); 00238 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time); 00239 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support); 00240 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime); 00241 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous); 00242 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, supported_attrs); 00243 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread); 00244 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite); 00245 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, umask); 00246 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, auth_exportpath_xdev); 00247 00248 /* 3- fsal info */ 00249 init_param.fsal_info.max_fs_calls = 0; 00250 00251 /* Init */ 00252 if(FSAL_IS_ERROR(st = FSAL_Init(&init_param))) 00253 { 00254 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00255 } 00256 00257 /* getting creds */ 00258 uid = getuid(); 00259 LogTest("uid = %d", uid); 00260 00261 st = FSAL_BuildExportContext(&export_ctx, NULL, NULL); 00262 if(FSAL_IS_ERROR(st)) 00263 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00264 00265 st = FSAL_InitClientContext(&op_ctx); 00266 00267 if(FSAL_IS_ERROR(st)) 00268 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00269 00270 st = FSAL_GetClientContext(&op_ctx, &export_ctx, uid, -1, NULL, 0); 00271 00272 if(FSAL_IS_ERROR(st)) 00273 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00274 00275 /* getting root handle */ 00276 00277 if(FSAL_IS_ERROR(st = FSAL_lookup(NULL, NULL, &op_ctx, &root_handle, NULL))) 00278 { 00279 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00280 } 00281 00282 snprintHandle(tracebuff, 256, &root_handle); 00283 LogTest("Root handle = %s", tracebuff); 00284 00285 /* getting what are the supported attributes */ 00286 00287 attribs.asked_attributes = 0; 00288 FSAL_SET_MASK(attribs.asked_attributes, FSAL_ATTR_SUPPATTR); 00289 LogTest("asked attributes :"); 00290 printmask(attribs.asked_attributes); 00291 00292 if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs))) 00293 { 00294 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00295 } 00296 00297 LogTest("supported attributes :"); 00298 printmask(attribs.supported_attributes); 00299 00300 mask = attribs.supported_attributes; 00301 00302 /* TEST 1 */ 00303 00304 if(test[0] == '1') 00305 { 00306 00307 attribs.asked_attributes = 0; 00308 FSAL_SET_MASK(attribs.asked_attributes, FSAL_ATTR_SUPPATTR); 00309 LogTest("asked attributes :"); 00310 printmask(attribs.asked_attributes); 00311 00312 if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs))) 00313 { 00314 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00315 } 00316 00317 LogTest("supported attributes :"); 00318 00319 /* getting all spported attributes of root */ 00320 attribs.asked_attributes = mask; 00321 if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs))) 00322 { 00323 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00324 } 00325 00326 printattributes(attribs); 00327 00328 } 00329 else 00330 /* TEST 2 */ 00331 if(test[0] == '2') 00332 { 00333 00334 /* getting handle and attributes for subdirectory "OSF1_V5" */ 00335 if(FSAL_IS_ERROR(st = FSAL_str2name("cea", 4, &name))) 00336 { 00337 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00338 } 00339 00340 attribs.asked_attributes = mask; 00341 if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) 00342 { 00343 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00344 } 00345 00346 snprintHandle(tracebuff, 256, &handle); 00347 LogTest("/cea handle = %s", tracebuff); 00348 00349 /* displaying attributes */ 00350 printattributes(attribs); 00351 00352 /* getting handle and attributes for subdirectory "bin" */ 00353 if(FSAL_IS_ERROR(st = FSAL_str2name("prot", 5, &name))) 00354 { 00355 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00356 } 00357 root_handle = handle; 00358 attribs.asked_attributes = mask; 00359 if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) 00360 { 00361 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00362 } 00363 00364 snprintHandle(tracebuff, 256, &handle); 00365 LogTest("/cea/prot handle = %s", tracebuff); 00366 00367 /* displaying attributes */ 00368 printattributes(attribs); 00369 00370 /* getting handle and attributes for symlink "AglaePwrSW" */ 00371 if(FSAL_IS_ERROR(st = FSAL_str2name("lama", 5, &name))) 00372 { 00373 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00374 } 00375 root_handle = handle; 00376 attribs.asked_attributes = mask; 00377 if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) 00378 { 00379 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00380 } 00381 00382 snprintHandle(tracebuff, 256, &handle); 00383 LogTest("/cea/prot/lama handle = %s", tracebuff); 00384 00385 /* displaying attributes */ 00386 printattributes(attribs); 00387 00388 } 00389 else 00390 /* TEST 3 */ 00391 if(test[0] == '3') 00392 { 00393 00394 /* lookup root */ 00395 if(FSAL_IS_ERROR(st = FSAL_str2path("/", 30, &path))) 00396 { 00397 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00398 } 00399 attribs.asked_attributes = mask; 00400 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 00401 { 00402 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00403 } 00404 00405 snprintHandle(tracebuff, 256, &handle); 00406 LogTest("/ handle = %s", tracebuff); 00407 00408 /* displaying attributes */ 00409 printattributes(attribs); 00410 00411 /* lookup path */ 00412 if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/lama", 15, &path))) 00413 { 00414 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00415 } 00416 attribs.asked_attributes = mask; 00417 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 00418 { 00419 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00420 } 00421 00422 snprintHandle(tracebuff, 256, &handle); 00423 LogTest("/cea/prot/lama handle = %s", tracebuff); 00424 00425 /* displaying attributes */ 00426 printattributes(attribs); 00427 00428 } 00429 else 00430 /* TEST 4 */ 00431 if(test[0] == '4') 00432 { 00433 00434 /* readdir on root */ 00435 fsal_dir_t dir; 00436 fsal_cookie_t from, to; 00437 fsal_dirent_t entries[READDIR_SIZE]; 00438 fsal_count_t number; 00439 fsal_boolean_t eod = FALSE; 00440 int error = FALSE; 00441 00442 attribs.asked_attributes = mask; 00443 if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) 00444 { 00445 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00446 } 00447 LogTest("'/' attributes :"); 00448 00449 /* displaying attributes */ 00450 printattributes(attribs); 00451 00452 from = FSAL_READDIR_FROM_BEGINNING; 00453 00454 while(!error && !eod) 00455 { 00456 unsigned int i; 00457 char cookiebuff[256]; 00458 00459 snprintCookie(cookiebuff, 256, &from); 00460 LogTest("\nReaddir cookie = %s", cookiebuff); 00461 if(FSAL_IS_ERROR(st = FSAL_readdir(&dir, from, 00462 mask, READDIR_SIZE * sizeof(fsal_dirent_t), 00463 entries, &to, &number, &eod))) 00464 { 00465 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00466 error = TRUE; 00467 } 00468 00469 for(i = 0; (!error) && (i < number); i++) 00470 { 00471 00472 snprintHandle(tracebuff, 256, &entries[i].handle); 00473 00474 snprintCookie(cookiebuff, 256, &entries[i].cookie); 00475 00476 LogTest("\t%s : %s (cookie %s)", tracebuff, 00477 entries[i].name.name, cookiebuff); 00478 } 00479 /* preparing next call */ 00480 from = to; 00481 00482 } 00483 LogTest("Fin de boucle : error=%d ; eod=%d", error, eod); 00484 00485 } 00486 else 00487 /* TEST 5 */ 00488 if(test[0] == '5') 00489 { 00490 00491 /* readdir on root */ 00492 fsal_dir_t dir; 00493 fsal_cookie_t from, to; 00494 fsal_dirent_t entries[READDIR_SIZE]; 00495 fsal_count_t number; 00496 fsal_boolean_t eod = FALSE; 00497 int error = FALSE; 00498 00499 attribs.asked_attributes = mask; 00500 if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) 00501 { 00502 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00503 } 00504 LogTest("'/' attributes :"); 00505 00506 /* displaying attributes */ 00507 printattributes(attribs); 00508 00509 from = FSAL_READDIR_FROM_BEGINNING; 00510 00511 while(!error && !eod) 00512 { 00513 fsal_dirent_t *curr; 00514 00515 char cookiebuff[256]; 00516 00517 snprintCookie(cookiebuff, 256, &from); 00518 00519 LogTest("\nReaddir cookie = %s", cookiebuff); 00520 00521 if(FSAL_IS_ERROR(st = FSAL_readdir(&dir, from, 00522 mask, READDIR_SIZE * sizeof(fsal_dirent_t), 00523 entries, &to, &number, &eod))) 00524 { 00525 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00526 error = TRUE; 00527 } 00528 00529 if(number > 0) 00530 { 00531 curr = entries; 00532 do 00533 { 00534 00535 snprintHandle(tracebuff, 256, &curr->handle); 00536 snprintCookie(cookiebuff, 256, &curr->cookie); 00537 00538 LogTest("\t%s : %s (cookie %s)", tracebuff, 00539 curr->name.name, cookiebuff); 00540 } 00541 while(curr = curr->nextentry); 00542 } 00543 /* preparing next call */ 00544 from = to; 00545 00546 } 00547 LogTest("Fin de boucle : error=%d ; eod=%d", error, eod); 00548 00549 } 00550 else 00551 /* TEST 6 */ 00552 if(test[0] == '6') 00553 { 00554 00555 /* readdir on root */ 00556 fsal_dir_t dir; 00557 fsal_cookie_t from, to; 00558 fsal_dirent_t entries[READDIR_SIZE]; 00559 fsal_count_t number; 00560 fsal_boolean_t eod = FALSE; 00561 int error = FALSE; 00562 00563 attribs.asked_attributes = mask; 00564 if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) 00565 { 00566 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00567 } 00568 LogTest("'/' attributes :"); 00569 00570 /* displaying attributes */ 00571 printattributes(attribs); 00572 00573 from = FSAL_READDIR_FROM_BEGINNING; 00574 00575 while(!error && !eod) 00576 { 00577 unsigned int i; 00578 00579 snprintCookie(tracebuff, 256, &from); 00580 LogTest("\nReaddir cookie = %s", tracebuff); 00581 00582 st = FSAL_readdir(&dir, from, mask, 00583 READDIR_SIZE * sizeof(fsal_dirent_t), 00584 entries, &to, &number, &eod); 00585 00586 if(FSAL_IS_ERROR(st)) 00587 { 00588 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00589 error = TRUE; 00590 } 00591 00592 /* for each entry, we compare the result of FSAL_access 00593 * to FSAL_test_access. */ 00594 for(i = 0; (!error) && (i < number); i++) 00595 { 00596 00597 fsal_status_t st1, st2; 00598 char cookiebuff[256]; 00599 00600 snprintHandle(tracebuff, 256, &entries[i].handle); 00601 snprintCookie(cookiebuff, 256, &entries[i].cookie); 00602 00603 LogTest("\t%s : %s (cookie %s)", tracebuff, 00604 entries[i].name.name, cookiebuff); 00605 00606 if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&entries[i].handle, &op_ctx, &attribs))) 00607 { 00608 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00609 } 00610 00611 /* 1 - test R access */ 00612 00613 st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_R_OK, NULL); 00614 00615 st2 = FSAL_test_access(&op_ctx, FSAL_R_OK, &attribs); 00616 00617 LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor); 00618 LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor); 00619 00620 if(st1.major != st2.major) 00621 { 00622 LogTest 00623 ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d", 00624 st1.major, st2.major); 00625 } 00626 00627 /* 2 - test W access */ 00628 00629 st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_W_OK, NULL); 00630 00631 st2 = FSAL_test_access(&op_ctx, FSAL_W_OK, &attribs); 00632 00633 LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor); 00634 LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor); 00635 00636 if(st1.major != st2.major) 00637 { 00638 LogTest 00639 ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d", 00640 st1.major, st2.major); 00641 } 00642 00643 /* 3 - test X access */ 00644 00645 st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_X_OK, NULL); 00646 00647 st2 = FSAL_test_access(&op_ctx, FSAL_X_OK, &attribs); 00648 00649 LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor); 00650 LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor); 00651 00652 if(st1.major != st2.major) 00653 { 00654 LogTest 00655 ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d", 00656 st1.major, st2.major); 00657 } 00658 00659 } 00660 00661 /* preparing next call */ 00662 from = to; 00663 00664 } 00665 LogTest("Fin de boucle : error=%d ; eod=%d", error, eod); 00666 00667 } 00668 else 00669 /* TEST 7 */ 00670 if(test[0] == '7') 00671 { 00672 00673 /* test snprintmem and sscanmem */ 00674 char test_string[] = 00675 "Ceci est une chaine d'essai.\nLes chiffres : 0123456789\nLes lettres : ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 00676 00677 char buffer[256]; 00678 char string[200]; /* 200 suffit car test_string fait <100 */ 00679 00680 int size1, size2, size3, i; 00681 00682 /* we put bad values in string, to see if it is correctly set. */ 00683 for(i = 0; i < 200; i++) 00684 string[i] = (char)i; 00685 00686 LogTest("Initial data (%d Bytes) = <<%s>>", strlen(test_string), test_string); 00687 00688 /* Write test_string to a buffer. */ 00689 /* We don't give the final '\0'. */ 00690 snprintmem(buffer, 256, test_string, strlen(test_string)); 00691 00692 LogTest("Dest_Buffer (%d Bytes) = <<%s>>", strlen(buffer), buffer); 00693 00694 /* read the value from the buffer */ 00695 sscanmem(string, strlen(test_string), buffer); 00696 00697 /* sets the final 0 to print the content of the buffer */ 00698 LogTest("Retrieved string : following byte = %d", 00699 (int)string[strlen(test_string)]); 00700 string[strlen(test_string)] = '\0'; 00701 00702 LogTest("Retrieved string (%d Bytes) = <<%s>>", strlen(string), string); 00703 00704 /* Automatic tests : */ 00705 size1 = strlen(test_string); 00706 size2 = strlen(buffer); 00707 size3 = strlen(string); 00708 00709 LogTest("-------------------------------------"); 00710 00711 if(size1 <= 0) 00712 LogTest("***** ERROR: source size=0 !!!"); 00713 00714 if(size1 != size3) 00715 LogTest("***** ERROR: source size <> target size"); 00716 else 00717 LogTest("OK: source size = target size"); 00718 00719 if((size1 * 2) != size2) 00720 LogTest("***** ERROR: hexa size <> 2 * source size"); 00721 else 00722 LogTest("OK: hexa size = 2 * source size"); 00723 00724 if(strcmp(test_string, string)) 00725 LogTest("***** ERROR: source string <> target string"); 00726 else 00727 LogTest("OK: source string = target string"); 00728 00729 } 00730 else 00731 /* TEST 8 */ 00732 if(test[0] == '8') 00733 { 00734 00735 fsal_handle_t dir_hdl, subdir_hdl; 00736 fsal_name_t subdir_name; 00737 00738 /* lookup on /cea/prot/S/lama/s8/leibovic */ 00739 00740 if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) 00741 { 00742 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00743 } 00744 attribs.asked_attributes = mask; 00745 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 00746 { 00747 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00748 } 00749 00750 snprintHandle(tracebuff, 256, &handle); 00751 LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff); 00752 00753 sleep(1); 00754 00755 /* creates a directory */ 00756 LogTest("------- Create a directory -------"); 00757 00758 if(FSAL_IS_ERROR(st = FSAL_str2name("tests_GANESHA", 30, &name))) 00759 { 00760 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00761 } 00762 00763 attribs.asked_attributes = mask; 00764 00765 if(FSAL_IS_ERROR(st = FSAL_mkdir(&handle, &name, &op_ctx, 00766 FSAL_MODE_RUSR | FSAL_MODE_WUSR 00767 | FSAL_MODE_XUSR | FSAL_MODE_RGRP 00768 | FSAL_MODE_WGRP, &dir_hdl, &attribs))) 00769 { 00770 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00771 } 00772 else 00773 { 00774 00775 snprintHandle(tracebuff, 256, &dir_hdl); 00776 LogTest("newly created dir handle = %s", tracebuff); 00777 00778 printattributes(attribs); 00779 00780 } 00781 00782 sleep(1); 00783 00784 /* Try to create it again */ 00785 LogTest("------- Try to create it again -------"); 00786 00787 if(FSAL_IS_ERROR(st = FSAL_mkdir(&handle, &name, &op_ctx, 00788 FSAL_MODE_RUSR | FSAL_MODE_WUSR 00789 | FSAL_MODE_XUSR | FSAL_MODE_RGRP 00790 | FSAL_MODE_WGRP, &dir_hdl, &attribs))) 00791 { 00792 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00793 } 00794 else 00795 { 00796 00797 LogTest("**** Error: FSAL should have returned ERR_FSAL_EXIST"); 00798 00799 } 00800 00801 sleep(1); 00802 00803 /* creates a subdirectory */ 00804 LogTest("------- Create a subdirectory -------"); 00805 00806 if(FSAL_IS_ERROR(st = FSAL_str2name("subdir_GANESHA", 30, &subdir_name))) 00807 { 00808 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00809 } 00810 00811 if(FSAL_IS_ERROR(st = FSAL_mkdir(&dir_hdl, &subdir_name, &op_ctx, 00812 FSAL_MODE_RUSR | FSAL_MODE_WUSR 00813 | FSAL_MODE_XUSR | FSAL_MODE_RGRP 00814 | FSAL_MODE_WGRP, &subdir_hdl, &attribs))) 00815 { 00816 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00817 } 00818 else 00819 { 00820 00821 snprintHandle(tracebuff, 256, &subdir_hdl); 00822 LogTest("newly created subdir handle = %s", tracebuff); 00823 00824 printattributes(attribs); 00825 00826 } 00827 00828 /* try to removes the parent directory */ 00829 LogTest("------- Try to removes the parent directory -------"); 00830 00831 if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) 00832 { 00833 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00834 } 00835 else 00836 { 00837 00838 LogTest("FSAL should not have unlinked %s because it is not empty", name.name); 00839 00840 } 00841 00842 sleep(1); 00843 00844 /* removes the subdirectory */ 00845 LogTest("------- Removes the subdirectory -------"); 00846 00847 if(FSAL_IS_ERROR(st = FSAL_unlink(&dir_hdl, &subdir_name, &op_ctx, &attribs))) 00848 { 00849 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00850 } 00851 else 00852 { 00853 00854 LogTest("New attributes for parent directory:"); 00855 printattributes(attribs); 00856 00857 } 00858 00859 /* removes the parent directory */ 00860 LogTest("------- Removes the parent directory -------"); 00861 00862 if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) 00863 { 00864 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00865 } 00866 else 00867 { 00868 00869 LogTest("Unlink %s OK", name.name); 00870 00871 } 00872 00873 } 00874 /* TEST 9 */ 00875 else if(test[0] == '9') 00876 { 00877 00878 fsal_handle_t dir_hdl, subdir_hdl; 00879 fsal_name_t subdir_name; 00880 fsal_attrib_list_t attr_set; 00881 00882 fsal_fsid_t set_fsid = { 1LL, 2LL }; 00883 00884 #ifdef _LINUX 00885 struct tm jour_heure = { 56, 34, 12, 31, 12, 110, 0, 0, 0, 0, 0 }; 00886 #else 00887 struct tm jour_heure = { 56, 34, 12, 31, 12, 110, 0, 0, 0 }; 00888 #endif 00889 00890 /* lookup on /cea/prot/S/lama/s8/leibovic */ 00891 00892 if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) 00893 { 00894 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00895 } 00896 attribs.asked_attributes = mask; 00897 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 00898 { 00899 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00900 } 00901 00902 snprintHandle(tracebuff, 256, &handle); 00903 LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff); 00904 00905 sleep(1); 00906 00907 /* creates a file */ 00908 LogTest("------- Create a file -------"); 00909 00910 if(FSAL_IS_ERROR(st = FSAL_str2name("tests_GANESHA_setattrs", 30, &name))) 00911 { 00912 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00913 } 00914 00915 attribs.asked_attributes = mask; 00916 00917 if(FSAL_IS_ERROR(st = FSAL_create(&handle, &name, &op_ctx, 00918 FSAL_MODE_RUSR | FSAL_MODE_WUSR 00919 | FSAL_MODE_XUSR | FSAL_MODE_RGRP 00920 | FSAL_MODE_WGRP, &dir_hdl, &attribs))) 00921 { 00922 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 00923 } 00924 else 00925 { 00926 00927 snprintHandle(tracebuff, 256, &dir_hdl); 00928 LogTest("newly created file handle = %s", tracebuff); 00929 00930 printattributes(attribs); 00931 00932 } 00933 00934 sleep(1); 00935 00936 LogTest("------- Try to change its attributes -------"); 00937 00938 /* Macro that try to change the value for an attribute */ 00939 00940 #define CHANGE_ATTRS( str_nom, nom, flag, new_val ) do {\ 00941 memset(&attr_set, 0, sizeof(fsal_attrib_list_t) ); \ 00942 LogTest("\nTry to change '%s' :",str_nom); \ 00943 FSAL_SET_MASK( attr_set.asked_attributes , flag ); \ 00944 attr_set.nom = new_val; \ 00945 attribs.asked_attributes = attr_set.asked_attributes; \ 00946 /* attribs.asked_attributes = mask; */\ 00947 st = FSAL_setattrs( &dir_hdl, &op_ctx, &attr_set, &attribs );\ 00948 if ( FSAL_IS_ERROR(st) ) \ 00949 LogError(COMPONENT_STDOUT,ERR_FSAL,st.major,st.minor);\ 00950 else \ 00951 printattributes( attribs ); \ 00952 } while(0) 00953 00954 CHANGE_ATTRS("supported_attributes", supported_attributes, 00955 FSAL_ATTR_SUPPATTR, FSAL_ATTRS_MANDATORY); 00956 00957 CHANGE_ATTRS("type", type, FSAL_ATTR_TYPE, FSAL_TYPE_LNK); 00958 00959 sleep(1); /* to see mtime modification by truncate */ 00960 00961 CHANGE_ATTRS("filesize", filesize, FSAL_ATTR_SIZE, (fsal_size_t) 12); 00962 00963 sleep(1); /* to see mtime modification by truncate */ 00964 00965 CHANGE_ATTRS("fsid", fsid, FSAL_ATTR_FSID, set_fsid); 00966 00967 /* @todo : ACLs */ 00968 00969 CHANGE_ATTRS("fileid", fileid, FSAL_ATTR_FILEID, (fsal_u64_t) 1234); 00970 00971 CHANGE_ATTRS("mode", mode, FSAL_ATTR_MODE, 00972 (FSAL_MODE_RUSR | FSAL_MODE_WUSR | FSAL_MODE_RGRP)); 00973 00974 CHANGE_ATTRS("numlinks", numlinks, FSAL_ATTR_NUMLINKS, 7); 00975 00976 /* FSAL_ATTR_RAWDEV */ 00977 00978 CHANGE_ATTRS("atime", atime.seconds, FSAL_ATTR_ATIME, mktime(&jour_heure)); 00979 00980 jour_heure.tm_min++; 00981 00982 CHANGE_ATTRS("creation", creation.seconds, FSAL_ATTR_CREATION, mktime(&jour_heure)); 00983 00984 jour_heure.tm_min++; 00985 00986 CHANGE_ATTRS("mtime", mtime.seconds, FSAL_ATTR_MTIME, mktime(&jour_heure)); 00987 00988 jour_heure.tm_min++; 00989 00990 CHANGE_ATTRS("ctime", ctime.seconds, FSAL_ATTR_CTIME, mktime(&jour_heure)); 00991 00992 CHANGE_ATTRS("spaceused", spaceused, FSAL_ATTR_SPACEUSED, (fsal_size_t) 12345); 00993 00994 CHANGE_ATTRS("mounted_on_fileid", mounted_on_fileid, 00995 FSAL_ATTR_MOUNTFILEID, (fsal_u64_t) 3210); 00996 00997 CHANGE_ATTRS("owner", owner, FSAL_ATTR_OWNER, 3051); /* deniel */ 00998 00999 CHANGE_ATTRS("group", group, FSAL_ATTR_GROUP, 5953); /* sr */ 01000 01001 sleep(1); 01002 01003 /* removes the parent directory */ 01004 LogTest("------- Removes the directory -------"); 01005 01006 if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) 01007 { 01008 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 01009 } 01010 else 01011 { 01012 01013 LogTest("Unlink %s OK", name.name); 01014 01015 } 01016 01017 } 01018 else if(test[0] == 'A') 01019 { 01020 01021 char digest_buff[FSAL_DIGEST_SIZE_HDLV3]; 01022 01023 /* lookup on /cea/prot/S/lama/s8/leibovic */ 01024 01025 if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) 01026 { 01027 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 01028 } 01029 attribs.asked_attributes = mask; 01030 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 01031 { 01032 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 01033 } 01034 01035 snprintHandle(tracebuff, 256, &handle); 01036 LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff); 01037 01038 /* building digest */ 01039 01040 st = FSAL_DigestHandle(&export_ctx, FSAL_DIGEST_NFSV3, &handle, digest_buff); 01041 01042 if(FSAL_IS_ERROR(st)) 01043 { 01044 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 01045 } 01046 else 01047 { 01048 /* print digest */ 01049 snprintmem(tracebuff, 256, digest_buff, FSAL_DIGEST_SIZE_HDLV3); 01050 LogTest("/cea/prot/S/lama/s8/leibovic: handle_digest = %s", tracebuff); 01051 } 01052 01053 memset(&handle, 0, sizeof(fsal_handle_t)); 01054 01055 /* expend digest */ 01056 01057 st = FSAL_ExpandHandle(&export_ctx, FSAL_DIGEST_NFSV3, digest_buff, &handle); 01058 01059 if(FSAL_IS_ERROR(st)) 01060 { 01061 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 01062 } 01063 else 01064 { 01065 /* print expended handle */ 01066 snprintHandle(tracebuff, 256, &handle); 01067 LogTest("/cea/prot/S/lama/s8/leibovic: handle expended = %s", tracebuff); 01068 } 01069 01070 } 01071 else if(test[0] == 'B') 01072 { 01073 01074 fsal_dynamicfsinfo_t dyninfo; 01075 01076 if(FSAL_IS_ERROR(st = FSAL_dynamic_fsinfo(&root_handle, &op_ctx, &dyninfo))) 01077 { 01078 LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); 01079 exit(st.major); 01080 } 01081 01082 LogTest("total_bytes = %llu", dyninfo.total_bytes); 01083 LogTest("free_bytes = %llu", dyninfo.free_bytes); 01084 LogTest("avail_bytes = %llu", dyninfo.avail_bytes); 01085 LogTest("total_files = %llu", dyninfo.total_files); 01086 LogTest("free_files = %llu", dyninfo.free_files); 01087 LogTest("avail_files = %llu", dyninfo.avail_files); 01088 LogTest("time_delta = %u.%u", dyninfo.time_delta.seconds, 01089 dyninfo.time_delta.nseconds); 01090 01091 } 01092 else 01093 LogTest("%s : test inconnu", test); 01094 01095 return 0; 01096 01097 }