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