Changeset 8833

Show
Ignore:
Timestamp:
05/13/11 17:15:07 (2 years ago)
Author:
shuangy
Message:

distributed directory structure for root and lost+found directory. In pvfs2-server.c, it will check if the root directory is set. Need 10~20 seconds for creation when the servers are launched at first time.

Location:
branches/Orange-Elaine-Distr-Dir-Branch/src
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • branches/Orange-Elaine-Distr-Dir-Branch/src/common/misc/mkspace.c

    r8768 r8833  
    2828#include "dist-dir-utils.h" 
    2929 
     30/* 
    3031static char *lost_and_found_string = "lost+found"; 
     32*/ 
    3133 
    3234static TROVE_handle s_used_handles[4] = 
     
    4446} while(0) 
    4547 
     48 
     49#if 0 
    4650static int handle_is_excluded( 
    4751    TROVE_handle handle, TROVE_handle *handles_to_exclude, 
     
    111115    } 
    112116} 
     117#endif 
    113118 
    114119int pvfs2_mkspace( 
     
    123128    int verbose) 
    124129{ 
    125     int ret = - 1, count = 0, keyval_count, i; 
     130    int ret = - 1, count = 0; 
    126131    TROVE_op_id op_id; 
    127132    TROVE_ds_state state; 
     
    133138    TROVE_context_id trove_context = -1; 
    134139    char *merged_handle_ranges = NULL; 
    135     unsigned char *c = NULL; 
    136140    TROVE_handle new_root_handle = TROVE_HANDLE_NULL; 
    137     TROVE_handle root_dirdata_handle = TROVE_HANDLE_NULL; 
    138     TROVE_handle lost_and_found_handle = TROVE_HANDLE_NULL; 
    139     TROVE_handle lost_and_found_dirdata_handle = TROVE_HANDLE_NULL; 
    140  
    141     /* distributed directory parameters */ 
    142     PVFS_dist_dir_attr meta_dist_dir_attr; 
    143     PVFS_dist_dir_attr dirdata_dist_dir_attr; 
    144     PVFS_dist_dir_bitmap dist_dir_bitmap = NULL; 
    145     /* only one dirdata_handle for root and lost_and_found, not using arrays 
    146     PVFS_handle *dirdata_handles; 
    147     */ 
    148141 
    149142    mkspace_print(verbose,"Data storage space     : %s\n",data_path); 
     
    291284    /* 
    292285      if a root_handle is specified, 1) create a dataspace to hold the 
    293       root directory 2) create the dspace for dir entries, 3) set 
    294       attributes on the dspace 
     286      root directory  2) set attributes on the dspace 
     287 
     288      The dirdata objects and the lost+found directory are created in pvfs2-server.c 
    295289    */ 
    296290    if (new_root_handle != TROVE_HANDLE_NULL) 
     
    372366        } 
    373367 
    374         /* 
    375           create a dataspace to hold directory entries; if we have a 
    376           meta handle range, use that one of those ranges (being 
    377           careful to make sure the range has enough space for an 
    378           allocation) to allocate a dataspace to hold directory 
    379           entries.  if we don't have a meta handle range, use 
    380           TROVE_HANDLE_NULL which tells the allocator to use any 
    381           handle available 
    382         */ 
    383         cur_extent.first = cur_extent.last = TROVE_HANDLE_NULL; 
    384         if (meta_handle_ranges) 
    385         { 
    386             get_handle_extent_from_ranges( 
    387                 meta_handle_ranges, &cur_extent, s_used_handles, 1); 
    388  
    389             if ((cur_extent.first == TROVE_HANDLE_NULL) && 
    390                 (cur_extent.last == TROVE_HANDLE_NULL)) 
    391             { 
    392                 gossip_err("No valid meta handle ranges available! " 
    393                            "Using a default\n"); 
    394             } 
    395             else 
    396             { 
    397                 mkspace_print( 
    398                     verbose, "info: using meta handle range %llu-%llu for " 
    399                     "root dirent dspace\n", llu(cur_extent.first), 
    400                     llu(cur_extent.last)); 
    401             } 
    402         } 
    403  
    404         extent_array.extent_count = 1; 
    405         extent_array.extent_array = &cur_extent; 
    406  
    407         ret = trove_dspace_create( 
    408             coll_id, &extent_array, &root_dirdata_handle, 
    409             PVFS_TYPE_DIRDATA, NULL, TROVE_SYNC, NULL, 
    410             trove_context, &op_id, NULL); 
    411  
    412         while (ret == 0) 
    413         { 
    414             ret = trove_dspace_test( 
    415                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    416                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    417         } 
    418  
    419         if ((ret != 1) && (state != 0)) 
    420         { 
    421             gossip_err("dspace create (for dirent storage) failed.\n"); 
    422             return -1; 
    423         } 
    424  
    425         mkspace_print(verbose, "info: created dspace for dirents " 
    426                       "with handle %llu\n", llu(root_dirdata_handle)); 
    427         s_used_handles[1] = root_dirdata_handle; 
    428  
    429         /* set root dirdata dspace attributes */ 
    430         memset(&attr, 0, sizeof(TROVE_ds_attributes_s)); 
    431         attr.uid = getuid(); 
    432         attr.gid = getgid(); 
    433         attr.mode = 0777; 
    434         attr.type = PVFS_TYPE_DIRDATA; 
    435         attr.atime = attr.ctime = PINT_util_get_current_time(); 
    436         attr.mtime = PINT_util_mktime_version(attr.ctime); 
    437  
    438         ret = trove_dspace_setattr( 
    439             coll_id, root_dirdata_handle, &attr, TROVE_SYNC, NULL, 
    440             trove_context, &op_id, NULL); 
    441  
    442         while (ret == 0) 
    443         { 
    444             ret = trove_dspace_test( 
    445                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    446                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    447         } 
    448  
    449         if (ret < 0) 
    450         { 
    451             gossip_err("error: dspace setattr for root dirdata handle " 
    452                        "attributes failed; aborting!\n"); 
    453             return -1; 
    454         } 
    455  
    456  
    457         key.buffer = DIRECTORY_ENTRY_KEYSTR; 
    458         key.buffer_sz = DIRECTORY_ENTRY_KEYLEN; 
    459         val.buffer = &root_dirdata_handle; 
    460         val.buffer_sz = sizeof(TROVE_handle); 
    461              
    462         ret = trove_keyval_write( 
    463             coll_id, new_root_handle, &key, &val, 
    464             TROVE_SYNC, 0, NULL, 
    465             trove_context, &op_id, NULL); 
    466              
    467         while (ret == 0) 
    468         {            
    469             ret = trove_dspace_test( 
    470                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    471                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    472         } 
    473          
    474         if (ret < 0) 
    475         { 
    476             gossip_err("error: keyval write for handle used to store " 
    477                        "dirents failed; aborting!\n"); 
    478             return -1; 
    479         }    
    480  
    481         mkspace_print( 
    482             verbose, "info: wrote attributes for root directory.\n"); 
    483              
    484  
    485         /* !!! set dist-dir-struct keyvals for root handle and its dirdata handle */ 
    486         /* init meta handle dist_dir_struct, num_servers=1, server_no = -1, pre_dsg_num_server=1 */ 
    487         /* should be reusable when init lost+found */ 
    488         ret = PINT_init_dist_dir_state(&meta_dist_dir_attr, 
    489                 &dist_dir_bitmap, 1, 0, 1); 
    490         assert(ret == 0); 
    491  
    492         /* gossip dist_dir_attr and dist_dir_bitmap */ 
    493         mkspace_print(verbose, "info: init dist_dir_attr for root handle %llu: \n" 
    494                 "with tree_height=%d, num_servers=%d, bitmap_size=%d, " 
    495                 "split_size=%d, server_no=%d and branch_level=%d\n", 
    496                 llu(new_root_handle), 
    497                 meta_dist_dir_attr.tree_height, 
    498                 meta_dist_dir_attr.num_servers, 
    499                 meta_dist_dir_attr.bitmap_size, 
    500                 meta_dist_dir_attr.split_size, 
    501                 meta_dist_dir_attr.server_no, 
    502                 meta_dist_dir_attr.branch_level); 
    503         mkspace_print(verbose, "info: init dist_dir_bitmap as:\n"); 
    504         for(i = meta_dist_dir_attr.bitmap_size - 1; 
    505                 i >= 0 ; i--) 
    506         { 
    507             c = (unsigned char *)(dist_dir_bitmap + i); 
    508             mkspace_print(verbose, 
    509                     " i=%d : %02x %02x %02x %02x\n", 
    510                     i, c[3], c[2], c[1], c[0]); 
    511         } 
    512         mkspace_print(verbose, "\n"); 
    513  
    514         /* init dirdata_dist_dir_attr */ 
    515         PINT_dist_dir_attr_copyto(dirdata_dist_dir_attr, meta_dist_dir_attr); 
    516         PINT_dist_dir_set_serverno(0, &dirdata_dist_dir_attr, dist_dir_bitmap); 
    517  
    518         mkspace_print(verbose, "info: init dist_dir_attr for root dirdata handle %llu: \n" 
    519                 "with tree_height=%d, num_servers=%d, bitmap_size=%d, " 
    520                 "split_size=%d, server_no=%d and branch_level=%d\n", 
    521                 llu(root_dirdata_handle), 
    522                 dirdata_dist_dir_attr.tree_height, 
    523                 dirdata_dist_dir_attr.num_servers, 
    524                 dirdata_dist_dir_attr.bitmap_size, 
    525                 dirdata_dist_dir_attr.split_size, 
    526                 dirdata_dist_dir_attr.server_no, 
    527                 dirdata_dist_dir_attr.branch_level); 
    528  
    529         keyval_count = 3; 
    530  
    531         key_a = malloc(sizeof(TROVE_keyval_s) * keyval_count); 
    532         if(!key_a) 
    533         { 
    534             gossip_err("keyval space create (for root and lost+found storage) failed.\n"); 
    535             return -1; 
    536         } 
    537         memset(key_a, 0, sizeof(TROVE_keyval_s) * keyval_count); 
    538  
    539         val_a = malloc(sizeof(TROVE_keyval_s) * keyval_count); 
    540         if(!val_a) 
    541         { 
    542             free(key_a); 
    543             gossip_err("keyval space create (for root and lost+found storage) failed.\n"); 
    544             return -1; 
    545         } 
    546         memset(val_a, 0, sizeof(TROVE_keyval_s) * keyval_count); 
    547  
    548         /* set keyval for root meta handle */ 
    549         key_a[0].buffer = DIST_DIR_ATTR_KEYSTR; 
    550         key_a[0].buffer_sz = DIST_DIR_ATTR_KEYLEN; 
    551  
    552         val_a[0].buffer = &meta_dist_dir_attr; 
    553         val_a[0].buffer_sz = 
    554             sizeof(meta_dist_dir_attr); 
    555  
    556         key_a[1].buffer = DIST_DIRDATA_BITMAP_KEYSTR; 
    557         key_a[1].buffer_sz = DIST_DIRDATA_BITMAP_KEYLEN; 
    558  
    559         val_a[1].buffer_sz = 
    560             meta_dist_dir_attr.bitmap_size *  /* bitmap_size = 1 */ 
    561             sizeof(PVFS_dist_dir_bitmap_basetype); 
    562         val_a[1].buffer = dist_dir_bitmap; 
    563  
    564         key_a[2].buffer = DIST_DIRDATA_HANDLES_KEYSTR; 
    565         key_a[2].buffer_sz = DIST_DIRDATA_HANDLES_KEYLEN; 
    566  
    567         val_a[2].buffer = &root_dirdata_handle; /* only one dirdata server */ 
    568         val_a[2].buffer_sz = meta_dist_dir_attr.num_servers *  
    569             sizeof(root_dirdata_handle); 
    570  
    571         mkspace_print(verbose,  
    572                 " info: writing dist-dir-struct keyvals for root handle: %llu " 
    573                 " with server_no=%d and branch_level=%d \n",  
    574                 llu(new_root_handle), 
    575                 meta_dist_dir_attr.server_no, 
    576                 meta_dist_dir_attr.branch_level); 
    577  
    578         /* write to root meta handle keyval space */ 
    579         ret = trove_keyval_write_list( 
    580             coll_id, new_root_handle, key_a, val_a, keyval_count, 
    581             TROVE_SYNC, 0, NULL, 
    582             trove_context, &op_id, NULL); 
    583  
    584         while (ret == 0) 
    585         { 
    586             ret = trove_dspace_test( 
    587                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    588                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    589         } 
    590  
    591         if (ret < 0) 
    592         { 
    593             gossip_err("error: keyval write for handle used to store " 
    594                        "dirents failed; aborting!\n"); 
    595             return -1; 
    596         } 
    597  
    598         /* adjust dist_dir_attr val_a */ 
    599         val_a[0].buffer = &dirdata_dist_dir_attr; 
    600          
    601         mkspace_print(verbose,  
    602                 " info: writing dist-dir-struct keyvals for root dirdata handle: %llu " 
    603                 " with server_no=%d and branch_level=%d \n",  
    604                 llu(root_dirdata_handle), 
    605                 dirdata_dist_dir_attr.server_no, 
    606                 dirdata_dist_dir_attr.branch_level); 
    607  
    608         /* write to root dirdata handle keyval space */ 
    609         ret = trove_keyval_write_list( 
    610             coll_id, root_dirdata_handle, key_a, val_a, keyval_count, 
    611             TROVE_SYNC, 0, NULL, 
    612             trove_context, &op_id, NULL); 
    613  
    614         while (ret == 0) 
    615         { 
    616             ret = trove_dspace_test( 
    617                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    618                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    619         } 
    620  
    621         if (ret < 0) 
    622         { 
    623             gossip_err("error: dist-dir-struct keyval write for root dirdata handle " 
    624                        "failed; aborting!\n"); 
    625             return -1; 
    626         } 
    627  
    628         mkspace_print( 
    629             verbose, "info: wrote attributes for root directory.\n"); 
    630  
    631  
    632         /**************************************************** 
    633           at this point we need to create and initialize the 
    634           lost+found directory as well 
    635         *****************************************************/ 
    636         cur_extent.first = cur_extent.last = TROVE_HANDLE_NULL; 
    637         if (meta_handle_ranges) 
    638         { 
    639             get_handle_extent_from_ranges( 
    640                 meta_handle_ranges, &cur_extent, s_used_handles, 2); 
    641  
    642             if ((cur_extent.first == TROVE_HANDLE_NULL) && 
    643                 (cur_extent.last == TROVE_HANDLE_NULL)) 
    644             { 
    645                 gossip_err("No valid meta handle ranges available! " 
    646                            "Using a default\n"); 
    647             } 
    648             else 
    649             { 
    650                 mkspace_print( 
    651                     verbose, "info: using meta handle range %llu-%llu for " 
    652                     "lost+found directory dspace\n", llu(cur_extent.first), 
    653                     llu(cur_extent.last)); 
    654             } 
    655         } 
    656         extent_array.extent_count = 1; 
    657         extent_array.extent_array = &cur_extent; 
    658  
    659         ret = trove_dspace_create( 
    660             coll_id, &extent_array, &lost_and_found_handle, 
    661             PVFS_TYPE_DIRECTORY, NULL, TROVE_SYNC, NULL, 
    662             trove_context, &op_id, NULL); 
    663  
    664         while (ret == 0) 
    665         { 
    666             ret = trove_dspace_test( 
    667                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    668                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    669         } 
    670  
    671         if ((ret != 1) && (state != 0)) 
    672         { 
    673             mkspace_print(verbose, 
    674                           "dspace create (for lost+found dir) failed.\n"); 
    675             return -1; 
    676         } 
    677  
    678         mkspace_print(verbose,"info: created lost+found directory " 
    679                       "with handle %llu.\n", llu(lost_and_found_handle)); 
    680         s_used_handles[2] = lost_and_found_handle; 
    681  
    682         /* set lost+found directory dspace attributes */ 
    683         memset(&attr, 0, sizeof(TROVE_ds_attributes_s)); 
    684         attr.uid = getuid(); 
    685         attr.gid = getgid(); 
    686         attr.mode = 0777; 
    687         attr.type = PVFS_TYPE_DIRECTORY; 
    688         attr.atime = attr.ctime = PINT_util_get_current_time(); 
    689         attr.mtime = PINT_util_mktime_version(attr.ctime); 
    690  
    691         ret = trove_dspace_setattr( 
    692             coll_id, lost_and_found_handle, &attr, TROVE_SYNC, NULL, 
    693             trove_context, &op_id, NULL); 
    694  
    695         while (ret == 0) 
    696         { 
    697             ret = trove_dspace_test( 
    698                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    699                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    700         } 
    701  
    702         if (ret < 0) 
    703         { 
    704             gossip_err("error: dspace setattr for lost+found handle " 
    705                        "attributes failed; aborting!\n"); 
    706             return -1; 
    707         } 
    708  
    709         /* create a dataspace to hold directory entries */ 
    710         cur_extent.first = cur_extent.last = TROVE_HANDLE_NULL; 
    711         if (meta_handle_ranges) 
    712         { 
    713             get_handle_extent_from_ranges( 
    714                 meta_handle_ranges, &cur_extent, s_used_handles, 3); 
    715  
    716             if ((cur_extent.first == TROVE_HANDLE_NULL) && 
    717                 (cur_extent.last == TROVE_HANDLE_NULL)) 
    718             { 
    719                 gossip_err("No valid meta handle ranges available! " 
    720                            "Using a default\n"); 
    721             } 
    722             else 
    723             { 
    724                 mkspace_print( 
    725                     verbose, "info: using meta handle range %llu-%llu for " 
    726                     "lost+found dirent dspace\n", llu(cur_extent.first), 
    727                     llu(cur_extent.last)); 
    728             } 
    729         } 
    730         extent_array.extent_count = 1; 
    731         extent_array.extent_array = &cur_extent; 
    732  
    733         ret = trove_dspace_create( 
    734             coll_id, &extent_array, &lost_and_found_dirdata_handle, 
    735             PVFS_TYPE_DIRDATA, NULL, TROVE_SYNC, NULL, 
    736             trove_context, &op_id, NULL); 
    737  
    738         while (ret == 0) 
    739         { 
    740             ret = trove_dspace_test( 
    741                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    742                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    743         } 
    744  
    745         if ((ret != 1) && (state != 0)) 
    746         { 
    747             gossip_err("dspace create (for dirent storage) failed.\n"); 
    748             return -1; 
    749         } 
    750  
    751         mkspace_print( 
    752             verbose, "info: created dspace for dirents " 
    753             "with handle %llu\n", llu(lost_and_found_dirdata_handle)); 
    754         s_used_handles[3] = lost_and_found_dirdata_handle; 
    755  
    756         /* set lost+found dirdata dspace attributes */ 
    757         memset(&attr, 0, sizeof(TROVE_ds_attributes_s)); 
    758         attr.uid = getuid(); 
    759         attr.gid = getgid(); 
    760         attr.mode = 0777; 
    761         attr.type = PVFS_TYPE_DIRDATA; 
    762         attr.atime = attr.ctime = PINT_util_get_current_time(); 
    763         attr.mtime = PINT_util_mktime_version(attr.ctime); 
    764  
    765         ret = trove_dspace_setattr( 
    766             coll_id, lost_and_found_dirdata_handle, &attr, TROVE_SYNC, NULL, 
    767             trove_context, &op_id, NULL); 
    768  
    769         while (ret == 0) 
    770         { 
    771             ret = trove_dspace_test( 
    772                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    773                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    774         } 
    775  
    776         if (ret < 0) 
    777         { 
    778             gossip_err("error: dspace setattr for lost+found handle " 
    779                        "attributes failed; aborting!\n"); 
    780             return -1; 
    781         } 
    782  
    783         key.buffer = DIRECTORY_ENTRY_KEYSTR; 
    784         key.buffer_sz = DIRECTORY_ENTRY_KEYLEN; 
    785         val.buffer = &lost_and_found_dirdata_handle; 
    786         val.buffer_sz = sizeof(TROVE_handle); 
    787  
    788         ret = trove_keyval_write( 
    789             coll_id, lost_and_found_handle, &key, &val, 
    790             TROVE_SYNC, 
    791             0, NULL, trove_context, &op_id, NULL); 
    792  
    793         while (ret == 0) 
    794         { 
    795             ret = trove_dspace_test( 
    796                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    797                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    798         } 
    799  
    800         if (ret < 0) 
    801         { 
    802             gossip_err("error: keyval write for handle used to store " 
    803                        "dirents failed; aborting!\n"); 
    804             return -1; 
    805         } 
    806  
    807         mkspace_print(verbose, "info: wrote attributes for " 
    808                       "lost+found directory.\n"); 
    809  
    810  
    811         /* set dist-dir-struct keyvals for lost+find handle and its dirdata handle  
    812          * use 1 dirdata server now, just as root handle 
    813          * */ 
    814  
    815         /* adjust keyval values, others should be the same as the root handle */ 
    816         val_a[0].buffer = &meta_dist_dir_attr; 
    817         val_a[2].buffer = &lost_and_found_dirdata_handle; 
    818         /* bitmap should be the same as the root handle for now */ 
    819  
    820         mkspace_print(verbose,  
    821                 " info: writing dist-dir-struct keyvals for lost+found handle: %llu " 
    822                 " with server_no=%d and branch_level=%d \n",  
    823                 llu(lost_and_found_handle), 
    824                 meta_dist_dir_attr.server_no, 
    825                 meta_dist_dir_attr.branch_level); 
    826  
    827         /* write to lost+found meta handle keyval space */ 
    828         ret = trove_keyval_write_list( 
    829             coll_id, lost_and_found_handle, key_a, val_a, keyval_count, 
    830             TROVE_SYNC, 0, NULL, 
    831             trove_context, &op_id, NULL); 
    832  
    833         while (ret == 0) 
    834         { 
    835             ret = trove_dspace_test( 
    836                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    837                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    838         } 
    839  
    840         if (ret < 0) 
    841         { 
    842             gossip_err("error: keyval write for handle used to store " 
    843                        "dirents failed; aborting!\n"); 
    844             return -1; 
    845         } 
    846  
    847  
    848         /* adjust dist_dir_attr val */ 
    849         val_a[0].buffer = &dirdata_dist_dir_attr; 
    850  
    851         mkspace_print(verbose,  
    852                 " info: writing dist-dir-struct keyvals for lost+found dirdata handle: %llu " 
    853                 " with server_no=%d and branch_level=%d \n",  
    854                 llu(lost_and_found_dirdata_handle), 
    855                 dirdata_dist_dir_attr.server_no, 
    856                 dirdata_dist_dir_attr.branch_level); 
    857  
    858         /* write to lost+found dirdata handle keyval space */ 
    859         ret = trove_keyval_write_list( 
    860                 coll_id, lost_and_found_dirdata_handle, key_a, val_a, keyval_count, 
    861                 TROVE_SYNC, 0, NULL, 
    862                 trove_context, &op_id, NULL); 
    863  
    864         while (ret == 0) 
    865         { 
    866             ret = trove_dspace_test( 
    867                     coll_id, op_id, trove_context, &count, NULL, NULL, 
    868                     &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    869         } 
    870  
    871         if (ret < 0) 
    872         { 
    873             gossip_err("error: dist-dir-struct keyval write for lost+found dirdata handle " 
    874                     "failed; aborting!\n"); 
    875             return -1; 
    876         } 
    877  
    878         mkspace_print(verbose, "info: wrote attributes for " 
    879                       "lost+found directory.\n"); 
    880  
    881  
    882         /* 
    883           finally, crdirent the lost+found directory into the root 
    884           directory by writing the appropriate keyval info into the 
    885           root dirdata handle space 
    886         */ 
    887         key.buffer = lost_and_found_string; 
    888         key.buffer_sz = strlen(lost_and_found_string) + 1; 
    889         val.buffer = &lost_and_found_handle; 
    890         val.buffer_sz = sizeof(TROVE_handle); 
    891  
    892         ret = trove_keyval_write( 
    893             coll_id, root_dirdata_handle, &key, &val,  
    894             TROVE_SYNC | TROVE_NOOVERWRITE | TROVE_KEYVAL_HANDLE_COUNT | TROVE_KEYVAL_DIRECTORY_ENTRY,  
    895             0, 
    896             NULL, trove_context, &op_id, NULL); 
    897  
    898         while (ret == 0) 
    899         { 
    900             ret = trove_dspace_test( 
    901                 coll_id, op_id, trove_context, &count, NULL, NULL, 
    902                 &state, TROVE_DEFAULT_TEST_TIMEOUT); 
    903         } 
    904  
    905         if (ret < 0) 
    906         { 
    907             gossip_err("error: keyval write for handle used to store " 
    908                        "dirents failed; aborting!\n"); 
    909             return -1; 
    910         } 
    911  
    912         mkspace_print(verbose, "info: adding lost+found directory to " 
    913                       "the root directory.\n"); 
     368 
     369        /* The creation of dirdata objects for the root directory is  
     370         * moved to pvfs2_server.c to setup distributed directory struct. 
     371         * lost+found directory is also created there.  
     372         */ 
     373 
    914374    } 
    915375         
     
    926386 
    927387    /* free space */ 
    928     if (dist_dir_bitmap) 
    929     { 
    930         free(dist_dir_bitmap); 
    931     } 
    932388    if (key_a) 
    933389    { 
  • branches/Orange-Elaine-Distr-Dir-Branch/src/proto/PINT-le-bytefield.c

    r8598 r8833  
    287287                req.u.mgmt_get_dirent.entry = tmp_name; 
    288288                reqsize = extra_size_PVFS_servreq_mgmt_get_dirent; 
     289                break; 
     290            case PVFS_SERV_MGMT_CREATE_ROOT_DIR: 
     291                /* nothing special */ 
    289292                break; 
    290293            case PVFS_SERV_NUM_OPS:  /* sentinel, should not hit */ 
     
    459462        CASE(PVFS_SERV_LISTATTR,  listattr); 
    460463        CASE(PVFS_SERV_MGMT_GET_DIRENT, mgmt_get_dirent); 
     464        CASE(PVFS_SERV_MGMT_CREATE_ROOT_DIR, mgmt_create_root_dir); 
    461465 
    462466        case PVFS_SERV_GETCONFIG: 
     
    575579        case PVFS_SERV_IMM_COPIES: 
    576580        case PVFS_SERV_MGMT_SETPARAM: 
     581        case PVFS_SERV_MGMT_CREATE_ROOT_DIR: 
    577582            /* nothing else */ 
    578583            break; 
     
    675680        CASE(PVFS_SERV_LISTATTR, listattr); 
    676681        CASE(PVFS_SERV_MGMT_GET_DIRENT, mgmt_get_dirent); 
     682        CASE(PVFS_SERV_MGMT_CREATE_ROOT_DIR, mgmt_create_root_dir); 
    677683 
    678684        case PVFS_SERV_GETCONFIG: 
     
    781787        case PVFS_SERV_IMM_COPIES: 
    782788        case PVFS_SERV_MGMT_SETPARAM: 
     789        case PVFS_SERV_MGMT_CREATE_ROOT_DIR: 
    783790            /* nothing else */ 
    784791            break; 
     
    958965            case PVFS_SERV_UNSTUFF: 
    959966            case PVFS_SERV_IMM_COPIES: 
     967            case PVFS_SERV_MGMT_CREATE_ROOT_DIR: 
    960968              /*nothing to free*/ 
    961969                  break; 
     
    11241132                case PVFS_SERV_TREE_SETATTR: 
    11251133                case PVFS_SERV_MGMT_GET_DIRENT: 
     1134                case PVFS_SERV_MGMT_CREATE_ROOT_DIR: 
    11261135                  /*nothing to free */ 
    11271136                   break; 
  • branches/Orange-Elaine-Distr-Dir-Branch/src/proto/pvfs2-req-proto.h

    r8544 r8833  
    8686    PVFS_SERV_TREE_SETATTR = 43, 
    8787    PVFS_SERV_MGMT_GET_DIRENT = 44, 
     88    PVFS_SERV_MGMT_CREATE_ROOT_DIR = 45, 
    8889    /* leave this entry last */ 
    8990    PVFS_SERV_NUM_OPS 
     
    9697    ((x) == PVFS_SERV_MGMT_SETPARAM \ 
    9798  || (x) == PVFS_SERV_MGMT_REMOVE_OBJECT \ 
    98   || (x) == PVFS_SERV_MGMT_REMOVE_DIRENT) 
     99  || (x) == PVFS_SERV_MGMT_REMOVE_DIRENT \ 
     100  || (x) == PVFS_SERV_MGMT_CREATE_ROOT_DIR \ 
     101  || (x) == PVFS_SERV_TREE_SETATTR \ 
     102) 
    99103 
    100104/******************************************************************/ 
     
    20302034    PVFS_error, error); 
    20312035 
     2036 
     2037/* mgmt_create_root_dir */ 
     2038/* - used to create root directory at very first startup time, only called noreq */ 
     2039struct PVFS_servreq_mgmt_create_root_dir 
     2040{ 
     2041    PVFS_handle handle; 
     2042    PVFS_fs_id fs_id; 
     2043}; 
     2044endecode_fields_2_struct( 
     2045    PVFS_servreq_mgmt_create_root_dir, 
     2046    PVFS_handle, handle, 
     2047    PVFS_fs_id, fs_id); 
     2048 
     2049#define PINT_SERVREQ_MGMT_CREATE_ROOT_DIR_FILL(__req,   \ 
     2050                                                  __creds, \ 
     2051                                                  __fsid,  \ 
     2052                                                  __handle,\ 
     2053                                                  __hints) \ 
     2054do {                                                       \ 
     2055    memset(&(__req), 0, sizeof(__req));                    \ 
     2056    (__req).op = PVFS_SERV_MGMT_CREATE_ROOT_DIR;        \ 
     2057    (__req).credentials = (__creds);                       \ 
     2058    (__req).hints = (__hints);                             \ 
     2059    (__req).u.mgmt_create_root_dir.fs_id = (__fsid);    \ 
     2060    (__req).u.mgmt_create_root_dir.handle = (__handle); \ 
     2061} while (0) 
     2062 
     2063 
    20322064/* server request *********************************************/ 
    20332065/* - generic request with union of all op specific structs */ 
     
    20772109        struct PVFS_servreq_tree_setattr tree_setattr; 
    20782110        struct PVFS_servreq_mgmt_get_dirent mgmt_get_dirent; 
     2111        struct PVFS_servreq_mgmt_create_root_dir mgmt_create_root_dir; 
    20792112    } u; 
    20802113}; 
  • branches/Orange-Elaine-Distr-Dir-Branch/src/server/module.mk.in

    r8544 r8833  
    4949                $(DIR)/unstuff.c \ 
    5050                $(DIR)/tree-communicate.c \ 
    51                 $(DIR)/mgmt-get-dirent.c 
     51                $(DIR)/mgmt-get-dirent.c \ 
     52                $(DIR)/mgmt-create-root-dir.c  
    5253 
    5354        # c files that should be added to server library 
  • branches/Orange-Elaine-Distr-Dir-Branch/src/server/pvfs2-server-req.c

    r8508 r8833  
    5454extern struct PINT_server_req_params pvfs2_tree_setattr_params; 
    5555extern struct PINT_server_req_params pvfs2_mgmt_get_dirent_params; 
     56extern struct PINT_server_req_params pvfs2_mgmt_create_root_dir_params; 
    5657 
    5758/* table of incoming request types and associated parameters */ 
     
    103104    /* 43 */ {PVFS_SERV_TREE_SETATTR, &pvfs2_tree_setattr_params}, 
    104105    /* 44 */ {PVFS_SERV_MGMT_GET_DIRENT, &pvfs2_mgmt_get_dirent_params}, 
     106    /* 45 */ {PVFS_SERV_MGMT_CREATE_ROOT_DIR, &pvfs2_mgmt_create_root_dir_params}, 
    105107}; 
    106108 
  • branches/Orange-Elaine-Distr-Dir-Branch/src/server/pvfs2-server.c

    r8545 r8833  
    157157    PINT_server_status_flag *server_status_flag); 
    158158static int server_setup_signal_handlers(void); 
     159static int server_check_if_root_directory_created(void); 
    159160static int server_purge_unexpected_recv_machines(void); 
    160161static int server_setup_process_environment(int background); 
     
    354355        goto server_shutdown; 
    355356    } 
     357 
     358    /* we have to go in to admin mode to take care of creating the root 
     359     * directory (distdir) and making the lost+found directory if needed */ 
     360    ret = server_check_if_root_directory_created(); 
     361    if (ret < 0) 
     362    { 
     363        PVFS_perror_gossip("Error: failed to create root handle! It needs to communicate with all servers. Please try again when all servers are up!!\n", ret); 
     364        goto server_shutdown; 
     365    } 
     366 
    356367 
    357368    gossip_debug_fp(stderr, 'S', GOSSIP_LOGSTAMP_DATETIME, 
     
    12011212    return 0; 
    12021213} 
     1214 
     1215/* checks if the server is the owner of the root handles. if so, ensures that 
     1216 * DIST_DIR_STRUCT exists. if it doesn't, puts the server in  
     1217 * admin mode and submits a create_root_dir state machine to take care of it  
     1218 */ 
     1219static int server_check_if_root_directory_created( void ) 
     1220{ 
     1221 
     1222    PINT_llist *cur_f = server_config.file_systems; 
     1223    struct filesystem_configuration_s *cur_fs; 
     1224    char handle_server[BMI_MAX_ADDR_LEN]; 
     1225    job_status_s js; 
     1226    job_id_t j_id; 
     1227    PVFS_ds_keyval key, val; 
     1228    struct PINT_smcb *tmp_op = NULL; 
     1229    PINT_server_op *tmp_sop = NULL; 
     1230    int ret = -1, outcount = 0; 
     1231 
     1232    PVFS_handle root_handle = 0; 
     1233    PVFS_dist_dir_attr dist_dir_attr; 
     1234 
     1235    /* iterate through list of file systems */ 
     1236    while(cur_f) 
     1237    { 
     1238        cur_fs = PINT_llist_head(cur_f); 
     1239        if (!cur_fs) 
     1240        { 
     1241            break; 
     1242        } 
     1243     
     1244        /* 
     1245           check if root handle is in our handle range for this fs. 
     1246           if it is, we're responsible for creating it on disk when 
     1247           creating the storage space 
     1248         */ 
     1249        root_handle = cur_fs->root_handle; 
     1250 
     1251        ret = PINT_cached_config_get_server_name( handle_server, 
     1252                BMI_MAX_ADDR_LEN-1, root_handle, cur_fs->coll_id); 
     1253        if( ret == 0 && strcmp(handle_server, server_config.host_id) == 0 ) 
     1254        { 
     1255            /* we own this handle, hurrah! now look if we have a DIST_DIR_ATTR keyval 
     1256             * record, we want one. */ 
     1257            key.buffer = Trove_Common_Keys[DIST_DIR_ATTR_KEY].key; 
     1258            key.buffer_sz = Trove_Common_Keys[DIST_DIR_ATTR_KEY].size; 
     1259            val.buffer_sz = sizeof(PVFS_dist_dir_attr); 
     1260            val.buffer = &dist_dir_attr; 
     1261 
     1262            ret = job_trove_keyval_read(cur_fs->coll_id, root_handle,  
     1263                    &key, &val,  
     1264                    0, NULL, NULL, 0, 
     1265                    &js, &j_id, server_job_context,  
     1266                    NULL); 
     1267            while(ret == 0) 
     1268            { 
     1269                ret = job_test(j_id, &outcount, NULL, &js,  
     1270                        PVFS2_SERVER_DEFAULT_TIMEOUT_MS, server_job_context); 
     1271            } 
     1272 
     1273            if(js.error_code != 0) 
     1274            { 
     1275                /* launch root-dir-create noreq state machine */ 
     1276                   ret = server_state_machine_alloc_noreq( 
     1277                   PVFS_SERV_MGMT_CREATE_ROOT_DIR, &(tmp_op)); 
     1278                if (ret < 0) 
     1279                { 
     1280                    return ret; 
     1281                } 
     1282 
     1283                tmp_sop = PINT_sm_frame(tmp_op, PINT_FRAME_CURRENT); 
     1284                tmp_sop->target_fs_id = cur_fs->coll_id; 
     1285                tmp_sop->target_handle = root_handle; 
     1286                ret = server_state_machine_start_noreq(tmp_op); 
     1287 
     1288                if (ret < 0) 
     1289                { 
     1290                    PVFS_perror_gossip("Error: failed to start root directory " 
     1291                            "creation noreq state machine.\n",  
     1292                            ret); 
     1293                    PINT_smcb_free(tmp_op); 
     1294                    return ret; 
     1295                } 
     1296 
     1297#if 0 
     1298                /* create the lost+found directory !!! */ 
     1299                PVFS_sys_attr       attr; 
     1300                PVFS_object_ref     parent_ref; 
     1301                PVFS_sysresp_mkdir  resp_mkdir; 
     1302                PVFS_credentials creds; 
     1303                char *lost_and_found_string = "lost+found"; 
     1304 
     1305                /* Initialize any variables */ 
     1306                memset(&attr,        0, sizeof(attr)); 
     1307                memset(&parent_ref,  0, sizeof(parent_ref)); 
     1308                memset(&resp_mkdir,  0, sizeof(resp_mkdir)); 
     1309 
     1310                parent_ref.fs_id = cur_fs->coll_id; 
     1311                parent_ref.handle = root_handle; 
     1312 
     1313                PINT_util_gen_credentials(&creds); 
     1314 
     1315                attr.owner = getuid(); 
     1316                attr.group = getgid(); 
     1317                attr.perms = 0777; 
     1318                attr.mask = (PVFS_ATTR_SYS_ALL_SETABLE); 
     1319                ret = PINT_cached_config_get_num_meta( 
     1320                        cur_fs->coll_id, 
     1321                        &attr.dirdata_count); 
     1322                if(ret < 0) 
     1323                { 
     1324                    gossip_err("Error: failed to get number of metadata servers\n"); 
     1325                    return ret; 
     1326                } 
     1327 
     1328 
     1329                ret = PVFS_sys_mkdir(lost_and_found_string,  
     1330                        parent_ref,  
     1331                        attr, 
     1332                        &creds,  
     1333                        &resp_mkdir, NULL); 
     1334 
     1335                if (ret < 0) 
     1336                { 
     1337                    PVFS_perror("PVFS_sys_mkdir", ret); 
     1338                    return(ret); 
     1339                } 
     1340#endif 
     1341 
     1342            } 
     1343            else // debug print 
     1344            { 
     1345                gossip_debug(GOSSIP_SERVER_DEBUG, "root dir already setup.\n"); 
     1346            } 
     1347        } 
     1348        cur_f = PINT_llist_next(cur_f); 
     1349    } 
     1350    return 0; 
     1351} 
     1352 
    12031353 
    12041354#ifdef __PVFS2_SEGV_BACKTRACE__ 
     
    20462196} 
    20472197 
     2198/* server_state_machine_complete_noreq() 
     2199 * 
     2200 * stripped down version of the standard complete function. This removes 
     2201 * items associated with handling/freeing requests structs and BMI connections 
     2202 * when cause problems when there is no request or connection to cleanup. 
     2203 * 
     2204 * returns 0 
     2205 */ 
     2206int server_state_machine_complete_noreq(PINT_smcb *smcb) 
     2207{ 
     2208    PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT); 
     2209    PVFS_id_gen_t tmp_id; 
     2210 
     2211    gossip_debug(GOSSIP_SERVER_DEBUG, "%s: %p\n", __func__, smcb); 
     2212    id_gen_fast_register(&tmp_id, s_op); 
     2213 
     2214    qlist_del(&s_op->next); 
     2215 
     2216    return SM_ACTION_TERMINATE; 
     2217} 
     2218 
     2219 
    20482220/* server_state_machine_complete() 
    20492221 * 
  • branches/Orange-Elaine-Distr-Dir-Branch/src/server/pvfs2-server.h

    r8734 r8833  
    615615{ 
    616616    PVFS_handle handle; 
     617}; 
     618 
     619 
     620struct PINT_server_mgmt_create_root_dir_op 
     621{ 
     622    PVFS_handle lost_and_found_handle; 
     623    PVFS_credentials creds; 
     624    int num_dirdata_servers; 
     625    PVFS_handle* handle_array_local;  
     626    PVFS_handle* handle_array_remote;  
     627    int handle_array_local_count; 
     628    int handle_array_remote_count; 
     629    PVFS_error saved_error_code; 
     630    int handle_index; 
    617631}; 
    618632 
     
    713727        struct PINT_server_tree_communicate_op tree_communicate; 
    714728        struct PINT_server_mgmt_get_dirent_op mgmt_get_dirent; 
     729        struct PINT_server_mgmt_create_root_dir_op mgmt_create_root_dir; 
    715730    } u; 
    716731 
     
    815830int server_state_machine_start_noreq( 
    816831    struct PINT_smcb *new_op); 
     832int server_state_machine_complete_noreq(PINT_smcb *smcb); 
    817833 
    818834/* INCLUDE STATE-MACHINE.H DOWN HERE */