nfs-ganesha 1.4

fsal_upcall_simulator_thread.c

Go to the documentation of this file.
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 
00038 #ifdef HAVE_CONFIG_H
00039 #include "config.h"
00040 #endif
00041 
00042 #ifdef _SOLARIS
00043 #include "solaris_port.h"
00044 #endif
00045 
00046 #include <stdio.h>
00047 #include <string.h>
00048 #include <pthread.h>
00049 #include <fcntl.h>
00050 #include <sys/file.h>           /* for having FNDELAY */
00051 #include "HashData.h"
00052 #include "HashTable.h"
00053 #include "log.h"
00054 #include "ganesha_rpc.h"
00055 #include "nfs23.h"
00056 #include "nfs4.h"
00057 #include "mount.h"
00058 #include "nlm4.h"
00059 #include "rquota.h"
00060 #include "nfs_core.h"
00061 #include "cache_inode.h"
00062 #include "nfs_exports.h"
00063 #include "nfs_creds.h"
00064 #include "nfs_proto_functions.h"
00065 #include "nfs_dupreq.h"
00066 #include "nfs_file_handle.h"
00067 #include "nfs_stat.h"
00068 #include "SemN.h"
00069 
00070 nfs_worker_data_t mydata ;
00071 
00072 static cache_entry_t * choose_pentry( hash_table_t * ht)
00073 {
00074   struct rbt_node *it;
00075   struct rbt_head *tete_rbt;
00076   cache_entry_t * pentry = NULL ;
00077   unsigned int i = 0;
00078   hash_data_t *pdata = NULL;
00079 
00080 
00081   unsigned int counter = 0 ;
00082 
00083   /* Sanity check */
00084   if(ht == NULL)
00085     return NULL ;
00086 
00087   for(i = 0; i < ht->parameter.index_size; i++)
00088     {
00089       
00090 
00091       tete_rbt = &((ht->array_rbt)[i]);
00092       RBT_LOOP(tete_rbt, it)
00093       {
00094         counter += 1 ;
00095         pdata = (hash_data_t *) it->rbt_opaq;
00096         pentry = (cache_entry_t *) (pdata->buffval.pdata) ;
00097 
00098         /* No file invalidation for the moment (file can handle state) */
00099         if( counter >= 10 ) 
00100          return pentry ;
00101 
00102         RBT_INCREMENT(it);
00103       }
00104     }
00105   return NULL ;
00106 } /* choose_pentry */
00107 
00108 
00109 
00110 void *upcall_simulator_thread(void *UnusedArgument)
00111 {
00112   // cache_inode_status_t cache_status = CACHE_INODE_SUCCESS;
00113   char thr_name[32];
00114   int rc = 0 ;
00115   cache_entry_t * pentry = NULL ;
00116   fsal_handle_t * pfsal_handle_invalidate = NULL ;
00117   fsal_attrib_list_t attr ;
00118   cache_inode_status_t cache_status ;
00119 
00120   snprintf(thr_name, sizeof(thr_name), "Upcall Simulator Thread" );
00121   SetNameFunction(thr_name);
00122 
00123   LogFullDebug(COMPONENT_CACHE_INODE, "Starting" ) ;
00124 
00125   LogDebug(COMPONENT_CACHE_INODE, "UPCALL SIMULATOR: my pthread id is %p",(caddr_t) pthread_self() ) ;
00126 
00127   if(FSAL_IS_ERROR(FSAL_InitClientContext(&mydata.thread_fsal_context)))
00128     {
00129       /* Failed init */
00130       LogFatal(COMPONENT_CACHE_INODE,
00131                "Error initializing thread's credential");
00132     }
00133 
00134   /* Init the Cache inode client for this worker */
00135   if(cache_inode_client_init(&mydata.cache_inode_client,
00136                              &(nfs_param.cache_layers_param.cache_inode_client_param),
00137                              SMALL_CLIENT_INDEX, &mydata))
00138     {
00139       /* Failed init */
00140       LogFatal(COMPONENT_CACHE_INODE,
00141                "Cache Inode client could not be initialized");
00142     }
00143   LogFullDebug(COMPONENT_CACHE_INODE,
00144                "Cache Inode client successfully initialized");
00145 
00146   mydata.ht = workers_data[0].ht ;
00147 
00148   LogFullDebug(COMPONENT_CACHE_INODE,
00149                "Cache Content client successfully initialized");
00150 
00151   LogInfo(COMPONENT_CACHE_INODE, "Upcall Simulator successfully initialized");
00152 
00153   /* Thread's infinite loop */
00154   while(1)
00155     {
00156         sleep( 1 ) ;
00157         if( ( pentry = choose_pentry( mydata.ht) ) != NULL )
00158          {
00159            LogCrit( COMPONENT_CACHE_INODE, "About to invalidate entry %p type=%u", pentry, pentry->internal_md.type ) ;
00160 
00161            if((pfsal_handle_invalidate =
00162                cache_inode_get_fsal_handle(pentry, &cache_status)) == NULL)
00163             {
00164               LogCrit( COMPONENT_CACHE_INODE, "Unable to get handle for entry %p to be invalidated", pentry ) ;
00165             }
00166            else if( cache_inode_invalidate( pfsal_handle_invalidate,
00167                                        &attr,
00168                                        mydata.ht,
00169                                        &mydata.cache_inode_client,
00170                                        &cache_status ) != CACHE_INODE_SUCCESS )
00171              {
00172                    LogCrit( COMPONENT_CACHE_INODE, "Could not invalidate entry %p, status=%u", pentry, cache_status ) ;
00173              }
00174            else
00175                 LogInfo( COMPONENT_CACHE_INODE, "Entry %p has been invalidated", pentry ) ;
00176          }                           /* while( 1 ) */
00177     } /* while( 1 ) */
00178 
00179   return NULL;
00180 }                               /* worker_thread */