nfs-ganesha 1.4
|
00001 00010 #ifdef HAVE_CONFIG_H 00011 #include "config.h" 00012 #endif 00013 00014 #include "fsal.h" 00015 #include "fsal_internal.h" 00016 #include "fsal_convert.h" 00017 #include <pwd.h> 00018 #include <errno.h> 00019 #include <stdlib.h> 00020 #include <string.h> 00021 #include <unistd.h> 00022 #include <time.h> 00023 #include <stdio.h> 00024 #include <pthread.h> 00025 #include <mntent.h> /* for handling mntent */ 00026 #include <libgen.h> /* for dirname */ 00027 #include <sys/vfs.h> /* for fsid */ 00028 00032 fsal_status_t GPFSFSAL_BuildExportContext(fsal_export_context_t *export_context, /* OUT */ 00033 fsal_path_t * p_export_path, /* IN */ 00034 char *fs_specific_options /* IN */ 00035 ) 00036 { 00037 int rc, fd, mntexists; 00038 FILE *fp; 00039 struct mntent *p_mnt; 00040 struct statfs stat_buf; 00041 00042 fsal_status_t status; 00043 fsal_op_context_t op_context; 00044 gpfsfsal_export_context_t *p_export_context = (gpfsfsal_export_context_t *)export_context; 00045 00046 /* sanity check */ 00047 if((p_export_context == NULL) || (p_export_path == NULL)) 00048 { 00049 LogCrit(COMPONENT_FSAL, 00050 "NULL mandatory argument passed to %s()", __FUNCTION__); 00051 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_BuildExportContext); 00052 } 00053 00054 /* open mnt file */ 00055 fp = setmntent(MOUNTED, "r"); 00056 00057 if(fp == NULL) 00058 { 00059 rc = errno; 00060 LogCrit(COMPONENT_FSAL, "Error %d in setmntent(%s): %s", rc, MOUNTED, 00061 strerror(rc)); 00062 Return(posix2fsal_error(rc), rc, INDEX_FSAL_BuildExportContext); 00063 } 00064 00065 /* Check if mount point is really a gpfs share. If not, we can't continue.*/ 00066 mntexists = 0; 00067 while((p_mnt = getmntent(fp)) != NULL) 00068 if(p_mnt->mnt_dir != NULL && p_mnt->mnt_type != NULL) 00069 /* There is probably a macro for "gpfs" type ... not sure where it is. */ 00070 if (strncmp(p_mnt->mnt_type, "gpfs", 4) == 0) 00071 if (strncmp(p_mnt->mnt_dir, p_export_path->path, strlen(p_mnt->mnt_dir)) == 0) 00072 mntexists = 1; 00073 00074 endmntent(fp); 00075 00076 if (mntexists == 0) 00077 { 00078 LogMajor(COMPONENT_FSAL, 00079 "FSAL BUILD EXPORT CONTEXT: ERROR: Could not open GPFS mount point %s does not exist.", 00080 p_export_path->path); 00081 ReturnCode(ERR_FSAL_INVAL, 0); 00082 } 00083 00084 /* save file descriptor to root of GPFS share */ 00085 fd = open(p_export_path->path, O_RDONLY | O_DIRECTORY); 00086 if(fd < 0) 00087 { 00088 LogMajor(COMPONENT_FSAL, 00089 "FSAL BUILD EXPORT CONTEXT: ERROR: Could not open GPFS mount point %s: rc = %d", 00090 p_export_path->path, errno); 00091 ReturnCode(ERR_FSAL_INVAL, 0); 00092 } 00093 p_export_context->mount_root_fd = fd; 00094 LogFullDebug(COMPONENT_FSAL, "GPFSFSAL_BuildExportContext: %d", p_export_context->mount_root_fd); 00095 00096 /* Save pointer to fsal_staticfsinfo_t in export context */ 00097 p_export_context->fe_static_fs_info = &global_fs_info; 00098 00099 /* save filesystem ID */ 00100 rc = statfs(p_export_path->path, &stat_buf); 00101 if(rc) 00102 { 00103 close(fd); 00104 LogMajor(COMPONENT_FSAL, 00105 "statfs call failed on file %s: %d", p_export_path->path, rc); 00106 ReturnCode(ERR_FSAL_INVAL, 0); 00107 } 00108 p_export_context->fsid[0] = stat_buf.f_fsid.__val[0]; 00109 p_export_context->fsid[1] = stat_buf.f_fsid.__val[1]; 00110 00111 /* save file handle to root of GPFS share */ 00112 op_context.export_context = export_context; 00113 // op_context.credential = ??? 00114 status = fsal_internal_get_handle(&op_context, 00115 p_export_path, 00116 (fsal_handle_t *)(&(p_export_context->mount_root_handle))); 00117 if(FSAL_IS_ERROR(status)) 00118 { 00119 close(p_export_context->mount_root_fd); 00120 LogMajor(COMPONENT_FSAL, 00121 "FSAL BUILD EXPORT CONTEXT: ERROR: Conversion from gpfs filesystem root path to handle failed : %d", 00122 status.minor); 00123 ReturnCode(ERR_FSAL_INVAL, 0); 00124 } 00125 00126 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_BuildExportContext); 00127 } 00128 00137 fsal_status_t GPFSFSAL_CleanUpExportContext(fsal_export_context_t * p_export_context) 00138 { 00139 if(p_export_context == NULL) 00140 { 00141 LogCrit(COMPONENT_FSAL, 00142 "NULL mandatory argument passed to %s()", __FUNCTION__); 00143 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_CleanUpExportContext); 00144 } 00145 00146 close(((gpfsfsal_export_context_t *)p_export_context)->mount_root_fd); 00147 00148 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_CleanUpExportContext); 00149 } 00150 00151 /* @} */