nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 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 #ifdef _SOLARIS 00041 #include "solaris_port.h" 00042 #endif /* _SOLARIS */ 00043 00044 #include "LRU_List.h" 00045 #include "log.h" 00046 #include "HashData.h" 00047 #include "HashTable.h" 00048 #include "fsal.h" 00049 #include "cache_inode.h" 00050 #include "cache_content.h" 00051 00052 #include <unistd.h> 00053 #include <sys/types.h> 00054 #include <sys/param.h> 00055 #include <time.h> 00056 #include <pthread.h> 00057 #include <errno.h> 00058 #include <string.h> 00059 00072 int cache_content_init(cache_content_client_parameter_t param, 00073 cache_content_status_t * pstatus) 00074 { 00075 /* Try to create the cache directory */ 00076 if(mkdir(param.cache_dir, 0750) != 0 && errno != EEXIST) 00077 { 00078 /* Cannot create the directory for caching data */ 00079 fprintf(stderr, "Can't create cache dir = %s, error = ( %d, %s )\n", 00080 param.cache_dir, errno, strerror(errno)); 00081 00082 *pstatus = CACHE_CONTENT_INVALID_ARGUMENT; 00083 return -1; 00084 } 00085 00086 /* Successfull exit */ 00087 return 0; 00088 } /* cache_content_init */ 00089 00100 int cache_content_init_dir(cache_content_client_parameter_t param, 00101 unsigned short export_id) 00102 { 00103 char path_to_dir[MAXPATHLEN]; 00104 00105 snprintf(path_to_dir, MAXPATHLEN, "%s/export_id=%d", param.cache_dir, 0); 00106 00107 if(mkdir(path_to_dir, 0750) != 0 && errno != EEXIST) 00108 { 00109 return -1; 00110 } 00111 00112 return 0; 00113 } /* cache_content_init_dir */ 00114 00127 int cache_content_client_init(cache_content_client_t * pclient, 00128 cache_content_client_parameter_t param, 00129 char *name) 00130 { 00131 pclient->nb_prealloc = param.nb_prealloc_entry; 00132 pclient->flush_force_fsal = param.flush_force_fsal; 00133 pclient->max_fd = param.max_fd ; 00134 pclient->use_fd_cache = param.use_fd_cache; 00135 strncpy(pclient->cache_dir, param.cache_dir, MAXPATHLEN); 00136 00137 pclient->content_pool = pool_init("Data Cache Client Pool", 00138 sizeof(cache_content_entry_t), 00139 pool_basic_substrate, 00140 NULL, NULL, NULL); 00141 if(!(pclient->content_pool)) 00142 { 00143 LogCrit(COMPONENT_CACHE_CONTENT, 00144 "Error : can't init data_cache client entry pool"); 00145 return 1; 00146 } 00147 00148 /* Successfull exit */ 00149 return 0; 00150 } /* cache_content_init */