[Pvfs2-cvs] commit by pcarns in pvfs2-1/src/common/misc: pint-cached-config.c

CVS commit program cvs at parl.clemson.edu
Tue May 20 16:01:04 EDT 2008


Update of /projects/cvsroot/pvfs2-1/src/common/misc
In directory parlweb1:/tmp/cvs-serv31723/src/common/misc

Modified Files:
      Tag: small-file-branch
	pint-cached-config.c 
Log Message:
merging some layout related updates from trunk to small-file-branch


Index: pint-cached-config.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/common/misc/pint-cached-config.c,v
diff -p -u -r1.22.2.7 -r1.22.2.8
--- pint-cached-config.c	7 Apr 2008 15:07:18 -0000	1.22.2.7
+++ pint-cached-config.c	20 May 2008 20:01:04 -0000	1.22.2.8
@@ -484,9 +484,10 @@ int PINT_cached_config_map_servers(
     struct PINT_llist *server_list;
     struct host_handle_mapping_s *cur_mapping = NULL;
     struct config_fs_cache_s *cur_config_cache = NULL;
-    int num_io_servers, i, j, ret;
+    int num_io_servers, i, ret;
     int start_index = -1;
     int index;
+    int random_attempts;
 
     assert(inout_num_datafiles);
 
@@ -580,8 +581,13 @@ int PINT_cached_config_map_servers(
             break;
 
         case PVFS_SYS_LAYOUT_RANDOM:
+            /* this layout randomizes the order but still uses each server
+             * only once
+             */
 
-            /* all random */
+            /* limit this layout to a number of datafiles no greater than
+             * the number of servers
+             */
             if(num_io_servers < *inout_num_datafiles)
             {
                 *inout_num_datafiles = num_io_servers;
@@ -590,34 +596,51 @@ int PINT_cached_config_map_servers(
             /* init all the addrs to 0, so we know whether we've set an
              * address at a particular index or not
              */
+            memset(addr_array, 0, (*inout_num_datafiles)*sizeof(*addr_array));
+
             for(i = 0; i < *inout_num_datafiles; ++i)
             {
+                /* go through server list in order */
+                cur_mapping = PINT_llist_head(server_list);
+                assert(cur_mapping);
+                server_list = PINT_llist_next(server_list);
+
+                /* select random index into caller's list */
                 index = rand() % *inout_num_datafiles;
-                for(j = 0; j < i; ++j)
+                random_attempts = 1;
+
+                /* if we have already filled that index, try another random
+                 * index 
+                 */ 
+                while(addr_array[index] != 0 && random_attempts < 6)
                 {
-                    if(addr_array[index] == 0)
-                    {
-                        cur_mapping = PINT_llist_head(server_list);
-                        assert(cur_mapping);
-                        server_list = PINT_llist_next(server_list);
-
-                        /* found an unused index */
-                        ret = BMI_addr_lookup(
-                            &addr_array[index],
-                            cur_mapping->alias_mapping->bmi_address);
-                        if (ret)
-                        {
-                            return ret;
-                        }
-
-                        if(handle_extent_array)
-                        {
-                            handle_extent_array[index].extent_count =
-                                cur_mapping->handle_extent_array.extent_count;
-                            handle_extent_array[index].extent_array =
-                                cur_mapping->handle_extent_array.extent_array;
-                        }
-                    }
+                    index = rand() % *inout_num_datafiles;
+                    random_attempts++;
+                }
+
+                /* if we exhausted a max number of randomization attempts,
+                 * then just go linearly through list
+                 */
+                while(addr_array[index] != 0)
+                {
+                    index = (index + 1) % *inout_num_datafiles;
+                }
+
+                /* found an unused index */
+                ret = BMI_addr_lookup(
+                    &addr_array[index],
+                    cur_mapping->alias_mapping->bmi_address);
+                if (ret)
+                {
+                    return ret;
+                }
+
+                if(handle_extent_array)
+                {
+                    handle_extent_array[index].extent_count =
+                        cur_mapping->handle_extent_array.extent_count;
+                    handle_extent_array[index].extent_array =
+                        cur_mapping->handle_extent_array.extent_array;
                 }
             }
             break;



More information about the Pvfs2-cvs mailing list