nfs-ganesha 1.4
|
00001 /* 00002 * 00003 * 00004 * Copyright CEA/DAM/DIF (2008) 00005 * contributeur : Philippe DENIEL philippe.deniel@cea.fr 00006 * Thomas LEIBOVICI thomas.leibovici@cea.fr 00007 * 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 3 of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 * --------------------------------------- 00024 */ 00025 00036 #ifdef HAVE_CONFIG_H 00037 #include "config.h" 00038 #endif 00039 00040 /* fsal_types contains constants and type definitions for FSAL */ 00041 #include <errno.h> 00042 #include <pthread.h> 00043 #include "fsal_types.h" 00044 #include "fsal.h" 00045 #include "mfsl_types.h" 00046 #include "mfsl.h" 00047 #include "common_utils.h" 00048 #include "LRU_List.h" 00049 #include "HashData.h" 00050 #include "HashTable.h" 00051 #include "abstract_mem.h" 00052 00053 pthread_t mfsl_async_adt_thrid; 00054 pthread_t *mfsl_async_synclet_thrid; 00055 00056 mfsl_synclet_data_t *synclet_data; 00057 00058 mfsl_parameter_t mfsl_param; 00059 00072 fsal_status_t MFSL_Init(mfsl_parameter_t * init_info /* IN */ 00073 ) 00074 { 00075 unsigned long i = 0; 00076 unsigned int rc = 0; 00077 pthread_attr_t attr_thr; 00078 LRU_status_t lru_status; 00079 00080 /* Keep the parameter in mind */ 00081 mfsl_param = *init_info; 00082 00083 /* Init for thread parameter (mostly for scheduling) */ 00084 pthread_attr_init(&attr_thr); 00085 pthread_attr_setscope(&attr_thr, PTHREAD_SCOPE_SYSTEM); 00086 pthread_attr_setdetachstate(&attr_thr, PTHREAD_CREATE_JOINABLE); 00087 00088 /* Allocate the synclet related structure */ 00089 if((mfsl_async_synclet_thrid = 00090 gsh_malloc(init_info->nb_synclet * sizeof(pthread_t))) == NULL) 00091 MFSL_return(ERR_FSAL_NOMEM, errno); 00092 00093 if((synclet_data = 00094 gsh_calloc(init_info->nb_synclet, 00095 sizeof(mfsl_synclet_data_t))) == NULL) 00096 MFSL_return(ERR_FSAL_NOMEM, errno); 00097 00098 for(i = 0; i < init_info->nb_synclet; i++) 00099 { 00100 synclet_data[i].my_index = i; 00101 if(pthread_cond_init(&synclet_data[i].op_condvar, NULL) != 0) 00102 MFSL_return(ERR_FSAL_INVAL, 0); 00103 00104 if(pthread_mutex_init(&synclet_data[i].mutex_op_condvar, NULL) != 0) 00105 MFSL_return(ERR_FSAL_INVAL, 0); 00106 00107 if(pthread_mutex_init(&synclet_data[i].mutex_op_lru, NULL) != 0) 00108 MFSL_return(ERR_FSAL_INVAL, 0); 00109 00110 if((synclet_data[i].op_lru = LRU_Init(mfsl_param.lru_param, &lru_status)) == NULL) 00111 MFSL_return(ERR_FSAL_INVAL, 0); 00112 00113 synclet_data[i].passcounter = 0; 00114 00115 } /* for */ 00116 00117 /* Now start the threads */ 00118 if((rc = pthread_create(&mfsl_async_adt_thrid, 00119 &attr_thr, 00120 mfsl_async_asynchronous_dispatcher_thread, (void *)NULL)) != 0) 00121 MFSL_return(ERR_FSAL_SERVERFAULT, -rc); 00122 00123 for(i = 0; i < init_info->nb_synclet; i++) 00124 { 00125 if((rc = pthread_create(&mfsl_async_synclet_thrid[i], 00126 &attr_thr, mfsl_async_synclet_thread, (void *)i)) != 0) 00127 MFSL_return(ERR_FSAL_SERVERFAULT, -rc); 00128 } 00129 00130 if(!mfsl_async_hash_init()) 00131 MFSL_return(ERR_FSAL_SERVERFAULT, 0); 00132 00133 /* Regular Exit */ 00134 MFSL_return(ERR_FSAL_NO_ERROR, 0); 00135 }