nfs-ganesha 1.4

fsal_fsinfo.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  */
00004 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 
00018 #include "fsal.h"
00019 #include "fsal_internal.h"
00020 #include "fsal_convert.h"
00021 #include "namespace.h"
00022 
00023 #ifdef _LINUX
00024 #include <sys/vfs.h>
00025 #endif
00026 
00027 #ifdef _APPLE
00028 #include <sys/param.h>
00029 #include <sys/mount.h>
00030 #endif
00031 
00051 fsal_status_t FUSEFSAL_dynamic_fsinfo(fsal_handle_t *handle,   /* IN */
00052                                       fsal_op_context_t * p_context,        /* IN */
00053                                       fsal_dynamicfsinfo_t * dynamicinfo        /* OUT */
00054     )
00055 {
00056 
00057   int rc;
00058   struct statvfs stbuff;
00059   char object_path[FSAL_MAX_PATH_LEN];
00060   fusefsal_handle_t *filehandle = (fusefsal_handle_t *)handle;
00061 
00062   /* sanity checks. */
00063   if(!filehandle || !dynamicinfo || !p_context)
00064     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_dynamic_fsinfo);
00065 
00066   /* get the full path for the object */
00067   rc = NamespacePath(filehandle->data.inode,
00068                      filehandle->data.device, filehandle->data.validator, object_path);
00069   if(rc)
00070     Return(ERR_FSAL_STALE, rc, INDEX_FSAL_dynamic_fsinfo);
00071 
00072   /* set context for the next operation, so it can be retrieved by FS thread */
00073   fsal_set_thread_context(p_context);
00074 
00075   if(p_fs_ops->statfs)
00076     {
00077       TakeTokenFSCall();
00078       rc = p_fs_ops->statfs(object_path, &stbuff);
00079       ReleaseTokenFSCall();
00080 
00081       if(rc)
00082         Return(fuse2fsal_error(rc, TRUE), rc, INDEX_FSAL_dynamic_fsinfo);
00083 
00084       dynamicinfo->total_bytes = stbuff.f_frsize * stbuff.f_blocks;
00085       dynamicinfo->free_bytes = stbuff.f_frsize * stbuff.f_bfree;
00086       dynamicinfo->avail_bytes = stbuff.f_frsize * stbuff.f_bavail;
00087 
00088       dynamicinfo->total_files = stbuff.f_files;
00089       dynamicinfo->free_files = stbuff.f_ffree;
00090       dynamicinfo->avail_files = stbuff.f_favail;
00091     }
00092   else
00093     {
00094       /* return dummy values for beeing compliant with any client behavior */
00095 
00096       LogDebug(COMPONENT_FSAL,
00097                "FSAL_dynamic_fsinfo: statfs is not implemented on this filesystem. Returning dummy values.");
00098 
00099       dynamicinfo->total_bytes = INT_MAX;
00100       dynamicinfo->free_bytes = INT_MAX;
00101       dynamicinfo->avail_bytes = INT_MAX;
00102 
00103       dynamicinfo->total_files = 1024 * 1024;
00104       dynamicinfo->free_files = 1024 * 1024;
00105       dynamicinfo->avail_files = 1024 * 1024;
00106     }
00107 
00108   /* return time precision depending on utime calls implemented */
00109   if(p_fs_ops->utimens)
00110     {
00111       dynamicinfo->time_delta.seconds = 0;
00112       dynamicinfo->time_delta.nseconds = 1;
00113     }
00114   else
00115     {
00116       dynamicinfo->time_delta.seconds = 1;
00117       dynamicinfo->time_delta.nseconds = 0;
00118     }
00119 
00120   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_dynamic_fsinfo);
00121 
00122 }