nfs-ganesha 1.4
|
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_common.h" 00021 #include <pwd.h> 00022 #include <errno.h> 00023 #include <stdlib.h> 00024 #include <string.h> 00025 #include "HashTable.h" 00026 00027 extern snapshot_t *p_snapshots; 00028 00031 /* define your specific NFS export options here : */ 00032 enum 00033 { 00034 YOUR_OPTION_1 = 0, 00035 YOUR_OPTION_2 = 1, 00036 YOUR_OPTION_3 = 2, 00037 YOUR_OPTION_4 = 3, 00038 }; 00039 00040 const char *fs_specific_opts[] = { 00041 "option1", 00042 "option2", 00043 "option3", 00044 "option4", 00045 NULL 00046 }; 00047 00052 static int Getsubopt(char **optionp, const char *const *tokens, char **valuep) 00053 { 00054 char *endp, *vstart; 00055 int cnt; 00056 00057 if(**optionp == '\0') 00058 return -1; 00059 00060 /* Find end of next token. */ 00061 endp = strchr(*optionp, ','); 00062 if(endp == NULL) 00063 endp = strchr(*optionp, '\0'); 00064 00065 /* Find start of value. */ 00066 vstart = memchr(*optionp, '=', endp - *optionp); 00067 if(vstart == NULL) 00068 vstart = endp; 00069 00070 /* Try to match the characters between *OPTIONP and VSTART against 00071 one of the TOKENS. */ 00072 for(cnt = 0; tokens[cnt] != NULL; ++cnt) 00073 if(memcmp(*optionp, tokens[cnt], vstart - *optionp) == 0 00074 && tokens[cnt][vstart - *optionp] == '\0') 00075 { 00076 /* We found the current option in TOKENS. */ 00077 *valuep = vstart != endp ? vstart + 1 : NULL; 00078 00079 if(*endp != '\0') 00080 *endp++ = '\0'; 00081 *optionp = endp; 00082 00083 return cnt; 00084 } 00085 00086 /* The current suboption does not match any option. */ 00087 *valuep = *optionp; 00088 00089 if(*endp != '\0') 00090 *endp++ = '\0'; 00091 *optionp = endp; 00092 00093 return -1; 00094 } 00095 00108 fsal_status_t ZFSFSAL_BuildExportContext(fsal_export_context_t * exp_context, /* OUT */ 00109 fsal_path_t * p_export_path, /* IN */ 00110 char *fs_specific_options /* IN */ 00111 ) 00112 { 00113 char subopts[256]; 00114 char *p_subop; 00115 char *value; 00116 zfsfsal_export_context_t * p_export_context = (zfsfsal_export_context_t *)exp_context; 00117 00118 /* sanity check */ 00119 if(!p_export_context) 00120 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_BuildExportContext); 00121 00122 if((fs_specific_options != NULL) && (fs_specific_options[0] != '\0')) 00123 { 00124 00125 /* copy the option string (because it is modified by getsubopt call) */ 00126 strncpy(subopts, fs_specific_options, 256); 00127 subopts[255] = '\0'; 00128 p_subop = subopts; /* set initial pointer */ 00129 00130 /* parse the FS specific option string */ 00131 00132 switch (Getsubopt(&p_subop, fs_specific_opts, &value)) 00133 { 00134 case YOUR_OPTION_1: 00135 /* analyze your option 1 and fill the export_context structure */ 00136 break; 00137 00138 case YOUR_OPTION_2: 00139 /* analyze your option 2 and fill the export_context structure */ 00140 break; 00141 00142 case YOUR_OPTION_3: 00143 /* analyze your option 3 and fill the export_context structure */ 00144 break; 00145 00146 case YOUR_OPTION_4: 00147 /* analyze your option 4 and fill the export_context structure */ 00148 break; 00149 00150 default: 00151 { 00152 LogCrit(COMPONENT_FSAL, 00153 "FSAL LOAD PARAMETER: ERROR: Invalid suboption found in EXPORT::FS_Specific : %s : xxxxxx expected.", 00154 value); 00155 Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_BuildExportContext); 00156 } 00157 } 00158 00159 } 00160 00161 /* Save pointer to fsal_staticfsinfo_t in export context */ 00162 p_export_context->fe_static_fs_info = &global_fs_info; 00163 00164 /* Initialize the libzfs library here */ 00165 p_export_context->p_vfs = p_snapshots[0].p_vfs; 00166 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_BuildExportContext); 00167 }