nfs-ganesha 1.4

fsal_up.c

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or
00003  * modify it under the terms of the GNU Lesser General Public
00004  * License as published by the Free Software Foundation; either
00005  * version 3 of the License, or (at your option) any later version.
00006  *
00007  * This program is distributed in the hope that it will be useful,
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00010  * Lesser General Public License for more details.
00011  *
00012  * You should have received a copy of the GNU Lesser General Public
00013  * License along with this library; if not, write to the Free Software
00014  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00015  *
00016  * ---------------------------------------
00017  */
00018 
00025 #ifdef HAVE_CONFIG_H
00026 #include "config.h"
00027 #endif
00028 
00029 #include "fsal.h"
00030 #include "fsal_up.h"
00031 #include "fsal_internal.h"
00032 #include "fsal_convert.h"
00033 #include <sys/types.h>
00034 #include <unistd.h>
00035 #include <utime.h>
00036 #include <sys/time.h>
00037 
00038 #ifdef _USE_FSAL_UP
00039 
00040 fsal_status_t GPFSFSAL_UP_Init( fsal_up_event_bus_parameter_t * pebparam,      /* IN */
00041                                    fsal_up_event_bus_context_t * pupebcontext     /* OUT */)
00042 {
00043   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_UP_init);
00044 }
00045 
00046 fsal_status_t GPFSFSAL_UP_AddFilter( fsal_up_event_bus_filter_t * pupebfilter,  /* IN */
00047                                         fsal_up_event_bus_context_t * pupebcontext /* INOUT */ )
00048 {
00049   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_UP_addfilter);
00050 }
00051 
00052 fsal_status_t GPFSFSAL_UP_GetEvents( struct glist_head * pevent_head,             /* OUT */
00053                                      fsal_count_t * event_nb,                     /* IN */
00054                                      fsal_time_t timeout,                         /* IN */
00055                                      fsal_count_t * peventfound,                  /* OUT */
00056                                      fsal_up_event_bus_context_t * pupebcontext   /* IN */ )
00057 {
00058   int rc = 0;
00059   struct stat buf;
00060   struct glock fl;
00061   struct callback_arg callback;
00062   cache_inode_fsal_data_t pfsal_data;
00063   fsal_handle_t *tmp_handlep = NULL;
00064   gpfsfsal_handle_t *phandle;
00065   int reason = 0;
00066   int flags = 0;
00067   unsigned int *fhP;
00068   cache_inode_fsal_data_t *event_fsal_data;
00069   fsal_up_event_t *pevent;
00070 
00071   tmp_handlep = gsh_malloc(sizeof(fsal_handle_t));
00072   if (tmp_handlep == NULL)
00073     {
00074       LogCrit(COMPONENT_FSAL, "Error: Could not malloc ... ENOMEM");
00075       Return(ERR_FSAL_NOMEM, ENOMEM, INDEX_FSAL_UP_getevents);
00076     }
00077 
00078   pfsal_data.fh_desc.start = (caddr_t)tmp_handlep;
00079   pfsal_data.fh_desc.len = sizeof(*tmp_handlep);
00080   phandle = (gpfsfsal_handle_t *) pfsal_data.fh_desc.start;
00081 
00082   if (pupebcontext == NULL || event_nb == NULL)
00083     {
00084       LogDebug(COMPONENT_FSAL, "Error: GPFSFSAL_UP_GetEvents() received"
00085                " unexpectedly NULL arguments.");
00086       Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_UP_getevents);
00087     }
00088 
00089   gpfsfsal_export_context_t *p_export_context =
00090     (gpfsfsal_export_context_t *)&pupebcontext->FS_export_context;
00091 
00092   phandle->data.handle.handle_size = OPENHANDLE_HANDLE_LEN;
00093   phandle->data.handle.handle_key_size = 0;
00094   callback.mountdirfd = p_export_context->mount_root_fd;
00095   callback.handle = (struct gpfs_file_handle *) &phandle->data.handle;
00096   callback.reason = &reason;
00097   callback.flags = &flags;
00098   callback.buf = &buf;
00099   callback.fl = &fl;
00100 
00101   rc = gpfs_ganesha(OPENHANDLE_INODE_UPDATE, &callback);
00102   if (rc != 0)
00103     {
00104       LogCrit(COMPONENT_FSAL,
00105         "Error: OPENHANDLE_INODE_UPDATE failed. rc %d, errno %d", rc, errno);
00106       gsh_free(tmp_handlep);
00107       Return(ERR_FSAL_SERVERFAULT, 0, INDEX_FSAL_UP_getevents);
00108     }
00109 
00110   LogDebug(COMPONENT_FSAL,
00111            "inode update: rc %d reason %d update ino %ld",
00112            rc, reason, callback.buf->st_ino);
00113   LogDebug(COMPONENT_FSAL,
00114            "inode update: tmp_handlep:%p flags:%x callback.handle:%p  pfsal_data.fh_desc.start:%p handle size = %u handle_type:%d handle_version:%d key_size = %u f_handle:%p", tmp_handlep, *callback.flags, callback.handle,
00115            pfsal_data.fh_desc.start,
00116            callback.handle->handle_size,
00117            callback.handle->handle_type,
00118            callback.handle->handle_version,
00119            callback.handle->handle_key_size,
00120            callback.handle->f_handle);
00121 
00122   callback.handle->handle_version = OPENHANDLE_VERSION;
00123 
00124   // TODO: Workaround until we get new GPFS code.
00125   callback.handle->handle_type = 7;
00126 
00127   fhP = (int *)&(callback.handle->f_handle[0]);
00128   LogDebug(COMPONENT_FSAL,
00129            " inode update: handle %08x %08x %08x %08x %08x %08x %08x\n",
00130            fhP[0],fhP[1],fhP[2],fhP[3],fhP[4],fhP[5],fhP[6]);
00131 
00132   /* Here is where we decide what type of event this is
00133    * ... open,close,read,...,invalidate? */
00134   pthread_mutex_lock(pupebcontext->event_pool_lock);
00135   pevent = pool_alloc(pupebcontext->event_pool, NULL);
00136   pthread_mutex_unlock(pupebcontext->event_pool_lock);
00137 
00138   event_fsal_data = &pevent->event_data.event_context.fsal_data;
00139   event_fsal_data->fh_desc.start = (caddr_t)tmp_handlep;
00140   event_fsal_data->fh_desc.len = sizeof(*tmp_handlep);
00141   GPFSFSAL_ExpandHandle(NULL, FSAL_DIGEST_SIZEOF, &(event_fsal_data->fh_desc));
00142   switch (reason)
00143     {
00144       case INODE_LOCK_GRANTED: /* Lock Event */
00145         LogDebug(COMPONENT_FSAL,
00146                  "inode lock granted: owner %p pid %d type %d start %lld len %lld",
00147                  fl.lock_owner, fl.flock.l_pid, fl.flock.l_type,
00148                  (long long) fl.flock.l_start, (long long) fl.flock.l_len);
00149         pevent->event_data.type.lock_grant.lock_owner = fl.lock_owner;
00150         pevent->event_data.type.lock_grant.lock_param.lock_length = fl.flock.l_len;
00151         pevent->event_data.type.lock_grant.lock_param.lock_start = fl.flock.l_start;
00152         pevent->event_data.type.lock_grant.lock_param.lock_type = fl.flock.l_type;
00153         pevent->event_type = FSAL_UP_EVENT_LOCK_GRANT;
00154         break;
00155       case INODE_LOCK_AGAIN: /* Lock Event */
00156         LogDebug(COMPONENT_FSAL,
00157                  "inode lock again: owner %p pid %d type %d start %lld len %lld",
00158                  fl.lock_owner, fl.flock.l_pid, fl.flock.l_type,
00159                  (long long) fl.flock.l_start, (long long) fl.flock.l_len);
00160         pevent->event_data.type.lock_grant.lock_owner = fl.lock_owner;
00161         pevent->event_data.type.lock_grant.lock_param.lock_length = fl.flock.l_len;
00162         pevent->event_data.type.lock_grant.lock_param.lock_start = fl.flock.l_start;
00163         pevent->event_data.type.lock_grant.lock_param.lock_type = fl.flock.l_type;
00164         pevent->event_type = FSAL_UP_EVENT_LOCK_GRANT;
00165         break;
00166       case INODE_UPDATE: /* Update Event */
00167         LogDebug(COMPONENT_FSAL,
00168                  "inode update: flags:%x update ino %ld n_link:%d",
00169                  flags, callback.buf->st_ino, (int)callback.buf->st_nlink);
00170         pevent->event_data.type.update.upu_flags = 0;
00171         pevent->event_data.type.update.upu_stat_buf = buf;
00172         if (flags & UP_NLINK)
00173           pevent->event_data.type.update.upu_flags |= FSAL_UP_NLINK;
00174         pevent->event_type = FSAL_UP_EVENT_UPDATE;
00175         break;
00176       default: /* Invalidate Event - Default */
00177         pevent->event_type = FSAL_UP_EVENT_INVALIDATE;
00178     }
00179   glist_add_tail(pevent_head, &pevent->event_list);
00180   /* Increment the numebr of events we are returning.*/
00181   (*event_nb)++;
00182 
00183   /* Return() will increment statistics ... but that object is
00184    * allocated by different threads ... is that a memory leak? */
00185   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_UP_getevents);
00186 }
00187 
00188 #endif /* _USE_FSAL_UP */