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 00030 #ifndef _MFSL_ASYNC_TYPES_H 00031 #define _MFSL_ASYNC_TYPES_H 00032 00033 #ifndef TRUE 00034 #define TRUE 1 00035 #endif 00036 #ifndef FALSE 00037 #define FALSE 0 00038 #endif 00039 00040 /* 00041 * labels in the config file 00042 */ 00043 00044 #define CONF_LABEL_MFSL_ASYNC "MFSL_Async" 00045 00046 #define MFSL_ASYNC_DEFAULT_NB_SYNCLETS 10 00047 #define MFSL_ASYNC_DEFAULT_SLEEP_TIME 60 00048 #define MFSL_ASYNC_DEFAULT_BEFORE_GC 10 00049 #define MFSL_ASYNC_DEFAULT_NB_PREALLOCATED_DIRS 10 00050 #define MFSL_ASYNC_DEFAULT_NB_PREALLOCATED_FILES 100 00051 00052 /* other includes */ 00053 #include <sys/types.h> 00054 #include <sys/param.h> 00055 #include <pthread.h> 00056 #include <dirent.h> /* for MAXNAMLEN */ 00057 #include "config_parsing.h" 00058 #include "LRU_List.h" 00059 #include "HashTable.h" 00060 #include "err_fsal.h" 00061 #include "err_mfsl.h" 00062 00063 typedef enum mfsl_async_health__ 00064 { MFSL_ASYNC_SYNCHRONOUS = 0, 00065 MFSL_ASYNC_ASYNCHRONOUS = 1, 00066 MFSL_ASYNC_NEVER_SYNCED = 2 00067 } mfsl_async_health_t; 00068 00069 typedef struct mfsl_object_specific_data__ 00070 { 00071 fsal_attrib_list_t async_attr; 00072 unsigned int deleted; 00073 } mfsl_object_specific_data_t; 00074 00075 typedef struct mfsl_object__ 00076 { 00077 fsal_handle_t handle; 00078 pthread_mutex_t lock; 00079 mfsl_async_health_t health; 00080 } mfsl_object_t; 00081 00082 typedef struct mfsl_precreated_object__ 00083 { 00084 mfsl_object_t mobject; 00085 fsal_name_t name; 00086 fsal_attrib_list_t attr; 00087 unsigned int inited; 00088 } mfsl_precreated_object_t; 00089 00090 typedef struct mfsl_synclet_context__ 00091 { 00092 pthread_mutex_t lock; 00093 } mfsl_synclet_context_t; 00094 00095 typedef enum mfsl_async_addr_type__ 00096 { MFSL_ASYNC_ADDR_DIRECT = 1, 00097 MFSL_ASYNC_ADDR_INDIRECT = 2 00098 } mfsl_async_addr_type_t; 00099 00100 typedef struct mfsl_synclet_data__ 00101 { 00102 unsigned int my_index; 00103 pthread_cond_t op_condvar; 00104 pthread_mutex_t mutex_op_condvar; 00105 fsal_op_context_t root_fsal_context; 00106 mfsl_synclet_context_t synclet_context; 00107 pthread_mutex_t mutex_op_lru; 00108 unsigned int passcounter; 00109 LRU_list_t *op_lru; 00110 } mfsl_synclet_data_t; 00111 00112 typedef enum mfsl_async_op_type__ 00113 { 00114 MFSL_ASYNC_OP_CREATE = 0, 00115 MFSL_ASYNC_OP_MKDIR = 1, 00116 MFSL_ASYNC_OP_LINK = 2, 00117 MFSL_ASYNC_OP_REMOVE = 3, 00118 MFSL_ASYNC_OP_RENAME = 4, 00119 MFSL_ASYNC_OP_SETATTR = 5, 00120 MFSL_ASYNC_OP_TRUNCATE = 6, 00121 MFSL_ASYNC_OP_SYMLINK = 7 00122 } mfsl_async_op_type_t; 00123 00124 static const char *mfsl_async_op_name[] = { "MFSL_ASYNC_OP_CREATE", 00125 "MFSL_ASYNC_OP_MKDIR", 00126 "MFSL_ASYNC_OP_LINK", 00127 "MFSL_ASYNC_OP_REMOVE", 00128 "MFSL_ASYNC_OP_RENAME", 00129 "MFSL_ASYNC_OP_SETATTR", 00130 "MFSL_ASYNC_OP_TRUNCATE", 00131 "MFSL_ASYNC_OP_SYMLINK" 00132 }; 00133 00134 typedef struct mfsl_async_op_create_args__ 00135 { 00136 fsal_name_t precreate_name; 00137 mfsl_object_t *pmfsl_obj_dirdest; 00138 fsal_name_t filename; 00139 fsal_accessmode_t mode; 00140 fsal_uid_t owner; 00141 fsal_gid_t group; 00142 } mfsl_async_op_create_args_t; 00143 00144 typedef struct mfsl_async_op_create_res__ 00145 { 00146 fsal_attrib_list_t attr; 00147 } mfsl_async_op_create_res_t; 00148 00149 typedef struct mfsl_async_op_mkdir_args__ 00150 { 00151 fsal_name_t precreate_name; 00152 mfsl_object_t *pmfsl_obj_dirdest; 00153 fsal_name_t dirname; 00154 fsal_accessmode_t mode; 00155 fsal_uid_t owner; 00156 fsal_gid_t group; 00157 } mfsl_async_op_mkdir_args_t; 00158 00159 typedef struct mfsl_async_op_mkdir_res__ 00160 { 00161 fsal_attrib_list_t attr; 00162 } mfsl_async_op_mkdir_res_t; 00163 00164 typedef struct mfsl_async_op_link_args__ 00165 { 00166 mfsl_object_t *pmobject_src; 00167 mfsl_object_t *pmobject_dirdest; 00168 fsal_name_t name_link; 00169 } mfsl_async_op_link_args_t; 00170 00171 typedef struct mfsl_async_op_link_res__ 00172 { 00173 fsal_attrib_list_t attr; 00174 } mfsl_async_op_link_res_t; 00175 00176 typedef struct mfsl_async_op_remove_args__ 00177 { 00178 mfsl_object_t *pmobject; 00179 fsal_name_t name; 00180 } mfsl_async_op_remove_args_t; 00181 00182 typedef struct mfsl_async_op_remove_res__ 00183 { 00184 fsal_attrib_list_t attr; 00185 } mfsl_async_op_remove_res_t; 00186 00187 typedef struct mfsl_async_op_rename_args__ 00188 { 00189 mfsl_object_t *pmobject_src; 00190 fsal_name_t name_src; 00191 mfsl_object_t *pmobject_dirdest; 00192 fsal_name_t name_dest; 00193 } mfsl_async_op_rename_args_t; 00194 00195 typedef struct mfsl_async_op_rename_res__ 00196 { 00197 fsal_attrib_list_t attrsrc; 00198 fsal_attrib_list_t attrdest; 00199 } mfsl_async_op_rename_res_t; 00200 00201 typedef struct mfsl_async_op_setattr_args__ 00202 { 00203 mfsl_object_t *pmobject; 00204 fsal_attrib_list_t attr; 00205 } mfsl_async_op_setattr_args_t; 00206 00207 typedef struct mfsl_async_op_setattr_res__ 00208 { 00209 fsal_attrib_list_t attr; 00210 } mfsl_async_op_setattr_res_t; 00211 00212 typedef struct mfsl_async_op_truncate_args__ 00213 { 00214 mfsl_object_t *pmobject; 00215 fsal_size_t size; 00216 } mfsl_async_op_truncate_args_t; 00217 00218 typedef struct mfsl_async_op_truncate_res__ 00219 { 00220 fsal_attrib_list_t attr; 00221 } mfsl_async_op_truncate_res_t; 00222 00223 typedef struct mfsl_async_op_symlink_args__ 00224 { 00225 fsal_name_t precreate_name; 00226 fsal_name_t linkname; 00227 mfsl_object_t *pmobject_dirdest; 00228 } mfsl_async_op_symlink_args_t; 00229 00230 typedef struct mfsl_async_op_symlink_res__ 00231 { 00232 fsal_attrib_list_t attr; 00233 } mfsl_async_op_symlink_res_t; 00234 00235 typedef union mfsl_async_op_args__ 00236 { 00237 mfsl_async_op_create_args_t create; 00238 mfsl_async_op_mkdir_args_t mkdir; 00239 mfsl_async_op_link_args_t link; 00240 mfsl_async_op_remove_args_t remove; 00241 mfsl_async_op_rename_args_t rename; 00242 mfsl_async_op_setattr_args_t setattr; 00243 mfsl_async_op_truncate_args_t truncate; 00244 mfsl_async_op_symlink_args_t symlink; 00245 } mfsl_async_op_args_t; 00246 00247 typedef union mfsl_async_op_res__ 00248 { 00249 mfsl_async_op_create_res_t create; 00250 mfsl_async_op_mkdir_res_t mkdir; 00251 mfsl_async_op_link_res_t link; 00252 mfsl_async_op_remove_res_t remove; 00253 mfsl_async_op_rename_res_t rename; 00254 mfsl_async_op_setattr_res_t setattr; 00255 mfsl_async_op_truncate_res_t truncate; 00256 mfsl_async_op_symlink_res_t symlink; 00257 } mfsl_async_op_res_t; 00258 00259 typedef struct mfsl_async_op_desc__ 00260 { 00261 struct timeval op_time; 00262 mfsl_async_op_type_t op_type; 00263 mfsl_async_op_args_t op_args; 00264 mfsl_async_op_res_t op_res; 00265 mfsl_object_t *op_mobject; 00266 fsal_status_t(*op_func) (struct mfsl_async_op_desc__ *); 00267 fsal_op_context_t fsal_op_context; 00268 caddr_t ptr_mfsl_context; 00269 unsigned int related_synclet_index; 00270 } mfsl_async_op_desc_t; 00271 00272 void *mfsl_synclet_thread(void *Arg); 00273 void *mfsl_asynchronous_dispatcher_thread(void *Arg); 00274 00275 /* Async Operations on FSAL */ 00276 fsal_status_t mfsl_async_create(mfsl_async_op_desc_t * popasyncdesc); 00277 fsal_status_t mfsl_async_mkdir(mfsl_async_op_desc_t * popasyncdesc); 00278 fsal_status_t mfsl_async_link(mfsl_async_op_desc_t * popasyncdesc); 00279 fsal_status_t mfsl_async_remove(mfsl_async_op_desc_t * popasyncdesc); 00280 fsal_status_t mfsl_async_rename(mfsl_async_op_desc_t * popasyncdesc); 00281 fsal_status_t mfsl_async_setattr(mfsl_async_op_desc_t * popasyncdesc); 00282 fsal_status_t mfsl_async_truncate(mfsl_async_op_desc_t * popasyncdesc); 00283 fsal_status_t mfsl_async_symlink(mfsl_async_op_desc_t * popasyncdesc); 00284 00285 typedef struct mfsl_parameter__ 00286 { 00287 unsigned int nb_pre_async_op_desc; 00288 unsigned int nb_synclet; 00289 unsigned int async_window_sec; 00290 unsigned int async_window_usec; 00291 unsigned int nb_before_gc; 00292 LRU_parameter_t lru_async_param; 00293 unsigned int nb_pre_create_dirs; 00294 unsigned int nb_pre_create_files; 00295 char pre_create_obj_dir[MAXPATHLEN]; 00296 char tmp_symlink_dir[MAXPATHLEN]; 00297 LRU_parameter_t lru_param; 00298 } mfsl_parameter_t; 00299 00300 typedef struct mfsl_context__ 00301 { 00302 pool_t *pool_spec_data; 00303 pool_t *pool_async_op; 00304 pthread_mutex_t lock; 00305 unsigned int synclet_index; 00306 pool_t *pool_dirs; 00307 pool_t *pool_files; 00308 } mfsl_context_t; 00309 00310 int mfsl_async_hash_init(void); 00311 int mfsl_async_set_specdata(mfsl_object_t * key, mfsl_object_specific_data_t * value); 00312 int mfsl_async_get_specdata(mfsl_object_t * key, mfsl_object_specific_data_t ** value); 00313 int mfsl_async_remove_specdata(mfsl_object_t * key); 00314 00315 void *mfsl_async_synclet_thread(void *Arg); 00316 void *mfsl_async_asynchronous_dispatcher_thread(void *Arg); 00317 fsal_status_t mfsl_async_post_async_op(mfsl_async_op_desc_t * popdes, 00318 mfsl_object_t * pmobject); 00319 fsal_status_t MFSL_async_post(mfsl_async_op_desc_t * popdesc); 00320 00321 fsal_status_t mfsl_async_init_precreated_directories(fsal_op_context_t *pcontext, 00322 pool_t *pool_dirs); 00323 00324 fsal_status_t mfsl_async_init_precreated_files(fsal_op_context_t *pcontext, 00325 pool_t *pool_dirs); 00326 00327 fsal_status_t mfsl_async_init_clean_precreated_objects(fsal_op_context_t * pcontext); 00328 00329 int mfsl_async_is_object_asynchronous(mfsl_object_t * object); 00330 00331 fsal_status_t mfsl_async_init_symlinkdir(fsal_op_context_t * pcontext); 00332 00333 void constructor_preacreated_entries(void *ptr); 00334 00335 fsal_status_t MFSL_PrepareContext(fsal_op_context_t * pcontext); 00336 00337 fsal_status_t MFSL_RefreshContext(mfsl_context_t * pcontext, 00338 fsal_op_context_t * pfsal_context); 00339 00340 fsal_status_t MFSL_ASYNC_GetSyncletContext(mfsl_synclet_context_t * pcontext, 00341 fsal_op_context_t * pfsal_context); 00342 00343 fsal_status_t MFSL_ASYNC_RefreshSyncletContext(mfsl_synclet_context_t * pcontext, 00344 fsal_op_context_t * pfsal_context); 00345 00346 int MFSL_ASYNC_is_synced(mfsl_object_t * mobject); 00347 00348 #endif /* _MFSL_ASYNC_TYPES_H */