nfs-ganesha 1.4

fsal_tools.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 
00013 #ifdef HAVE_CONFIG_H
00014 #include "config.h"
00015 #endif
00016 
00017 #include "fsal.h"
00018 #include "fsal_convert.h"
00019 #include "fsal_internal.h"
00020 #include "config_parsing.h"
00021 #include <string.h>
00022 
00023 /* case unsensitivity */
00024 #define STRCMP   strcasecmp
00025 
00026 char *LUSTREFSAL_GetFSName()
00027 {
00028   return "LUSTRE";
00029 }
00030 
00047 int LUSTREFSAL_handlecmp(fsal_handle_t * handle_1, fsal_handle_t * handle_2,
00048                          fsal_status_t * status)
00049 {
00050   lustrefsal_handle_t * handle1 = (lustrefsal_handle_t *)handle_1;
00051   lustrefsal_handle_t * handle2 = (lustrefsal_handle_t *)handle_2;
00052 
00053   *status = FSAL_STATUS_NO_ERROR;
00054 
00055   if(!handle1 || !handle2)
00056     {
00057       status->major = ERR_FSAL_FAULT;
00058       return -1;
00059     }
00060 
00061   return (handle1->data.fid.f_seq != handle2->data.fid.f_seq)
00062       || (handle1->data.fid.f_oid != handle2->data.fid.f_oid)
00063       || (handle1->data.fid.f_ver != handle2->data.fid.f_ver);
00064 
00065 }
00066 
00081 unsigned int LUSTREFSAL_Handle_to_HashIndex(fsal_handle_t *handle,
00082                                             unsigned int cookie,
00083                                             unsigned int alphabet_len,
00084                                             unsigned int index_size)
00085 {
00086   unsigned long long lval;
00087   lustrefsal_handle_t * p_handle = (lustrefsal_handle_t *)handle;
00088 
00089   /* polynom of prime numbers */
00090   lval = 3 * cookie * alphabet_len + 1873 * p_handle->data.fid.f_seq
00091       + 3511 * p_handle->data.fid.f_oid + 2999 * p_handle->data.fid.f_ver + 10267;
00092 
00093   return lval % index_size;
00094 }
00095 
00096 /*
00097  * FSAL_Handle_to_RBTIndex
00098  * This function is used for generating a RBT node ID
00099  * in order to identify entries into the RBT.
00100  *
00101  * \param p_handle      The handle to be hashed
00102  * \param cookie        Makes it possible to have different hash value for the
00103  *                      same handle, when cookie changes.
00104  *
00105  * \return The hash value
00106  */
00107 
00108 unsigned int LUSTREFSAL_Handle_to_RBTIndex(fsal_handle_t *handle,
00109                                            unsigned int cookie)
00110 {
00111   unsigned long long lval;
00112   lustrefsal_handle_t * p_handle = (lustrefsal_handle_t *)handle;
00113 
00114   /* polynom of prime numbers */
00115   lval = 2239 * cookie + 3559 * p_handle->data.fid.f_seq + 5 * p_handle->data.fid.f_oid
00116       + 1409 * p_handle->data.fid.f_ver + 20011;
00117 
00118   return high32m(lval) ^ low32m(lval);
00119 }
00120 
00137 fsal_status_t LUSTREFSAL_DigestHandle(fsal_export_context_t * exp_context,     /* IN */
00138                                       fsal_digesttype_t output_type,       /* IN */
00139                                       fsal_handle_t *in_fsal_handle, /* IN */
00140                                       struct fsal_handle_desc *fh_desc     /* IN/OUT */ )
00141 {
00142   unsigned int ino32;
00143   lustrefsal_export_context_t * p_expcontext = (lustrefsal_export_context_t *)exp_context;
00144   lustrefsal_handle_t * p_in_fsal_handle = (lustrefsal_handle_t *)in_fsal_handle;
00145   size_t fh_size;
00146 
00147   /* sanity checks */
00148   if(!p_in_fsal_handle || !fh_desc || !fh_desc->start || !p_expcontext)
00149     ReturnCode(ERR_FSAL_FAULT, 0);
00150 
00151   switch (output_type)
00152     {
00153 
00154     /* NFS handle digest */
00155     case FSAL_DIGEST_NFSV2:
00156     case FSAL_DIGEST_NFSV3:
00157     case FSAL_DIGEST_NFSV4:
00158       fh_size = sizeof(p_in_fsal_handle->data) ;
00159       if(fh_desc->len < fh_size)
00160         {
00161                LogMajor( COMPONENT_FSAL,
00162                              "LUSTRE DigestHandle: space too small for handle.  need %lu, have %lu",
00163                              fh_size, fh_desc->len);
00164                ReturnCode(ERR_FSAL_TOOSMALL, 0);
00165             }
00166       memcpy(fh_desc->start, (caddr_t)p_in_fsal_handle, fh_size);
00167       fh_desc->len = fh_size;
00168       break;
00169 
00170       /* FileId digest for NFSv2 */
00171     case FSAL_DIGEST_FILEID2:
00172 
00173       ino32 = low32m(p_in_fsal_handle->data.inode);
00174 
00175       memset(fh_desc->start, 0, FSAL_DIGEST_SIZE_FILEID2);
00176       memcpy(fh_desc->start, &ino32, sizeof( ino32 ));
00177       fh_desc->len = FSAL_DIGEST_SIZE_FILEID2; 
00178       break;
00179 
00180       /* FileId digest for NFSv3 */
00181     case FSAL_DIGEST_FILEID3:
00182       memset(fh_desc->start, 0, FSAL_DIGEST_SIZE_FILEID3);
00183       memcpy(fh_desc->start, &(p_in_fsal_handle->data.inode), sizeof(fsal_u64_t));
00184       fh_desc->len = FSAL_DIGEST_SIZE_FILEID3;
00185       break;
00186 
00187       /* FileId digest for NFSv4 */
00188     case FSAL_DIGEST_FILEID4:
00189       memset(fh_desc->start, 0, FSAL_DIGEST_SIZE_FILEID4);
00190       memcpy(fh_desc->start, &(p_in_fsal_handle->data.inode), sizeof(fsal_u64_t));
00191       fh_desc->len = FSAL_DIGEST_SIZE_FILEID4;
00192       break;
00193 
00194     default:
00195       ReturnCode(ERR_FSAL_SERVERFAULT, 0);
00196 
00197     }
00198 
00199   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00200 
00201 }
00202 
00218 fsal_status_t LUSTREFSAL_ExpandHandle(fsal_export_context_t * pexpcontext,     /* IN not used */
00219                                    fsal_digesttype_t in_type,   /* IN */
00220                                    struct fsal_handle_desc *fh_desc  /* IN/OUT */ )
00221 {
00222   lustrefsal_export_context_t * p_expcontext = (lustrefsal_export_context_t *)pexpcontext;
00223   lustrefsal_handle_t dummy_handle ;
00224   size_t fh_size;
00225 
00226   /* sanity checks */
00227   if(!fh_desc || !fh_desc->start || !p_expcontext)
00228     ReturnCode(ERR_FSAL_FAULT, 0);
00229 
00230   fh_size = sizeof( dummy_handle.data ); /* All LUSTRE handle have the same size */
00231   if(in_type == FSAL_DIGEST_NFSV2)
00232     {
00233       if(fh_desc->len < fh_size)
00234         {
00235           LogMajor(COMPONENT_FSAL,
00236                    "LUSTRE ExpandHandle: V2 size too small for handle.  should be %lu, got %lu",
00237                    fh_size, fh_desc->len);
00238           ReturnCode(ERR_FSAL_SERVERFAULT, 0);
00239         }
00240     }
00241   else if(in_type != FSAL_DIGEST_SIZEOF && fh_desc->len != fh_size)
00242     {
00243       LogMajor(COMPONENT_FSAL,
00244                "LUSTRE ExpandHandle: size mismatch for handle.  should be %lu, got %lu",
00245                fh_size, fh_desc->len);
00246       ReturnCode(ERR_FSAL_SERVERFAULT, 0);
00247     }
00248   fh_desc->len = fh_size;  /* pass back the actual size */
00249   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00250 }
00251 
00260 fsal_status_t LUSTREFSAL_SetDefault_FS_specific_parameter(fsal_parameter_t *
00261                                                           out_parameter)
00262 {
00263   /* defensive programming... */
00264   if(out_parameter == NULL)
00265     ReturnCode(ERR_FSAL_FAULT, 0);
00266 
00267   /* set default values for all parameters of fs_specific_info */
00268 
00269 #ifdef _USE_PGSQL
00270 
00271   /* pgsql db */
00272   strcpy(out_parameter->fs_specific_info.dbparams.host, "localhost");
00273   strcpy(out_parameter->fs_specific_info.dbparams.port, "5432");
00274   out_parameter->fs_specific_info.dbparams.dbname[0] = '\0';
00275   out_parameter->fs_specific_info.dbparams.login[0] = '\0';
00276   out_parameter->fs_specific_info.dbparams.passwdfile[0] = '\0';
00277 
00278 #elif defined(_USE_MYSQL)
00279 
00280   strcpy(out_parameter->fs_specific_info.dbparams.host, "localhost");
00281   strcpy(out_parameter->fs_specific_info.dbparams.port, "");
00282   out_parameter->fs_specific_info.dbparams.dbname[0] = '\0';
00283   out_parameter->fs_specific_info.dbparams.login[0] = '\0';
00284   out_parameter->fs_specific_info.dbparams.passwdfile[0] = '\0';
00285 
00286 #endif
00287 
00288   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00289 
00290 }
00291 
00313 /* load specific filesystem configuration options */
00314 
00315 fsal_status_t LUSTREFSAL_load_FS_specific_parameter_from_conf(config_file_t in_config,
00316                                                               fsal_parameter_t *
00317                                                               out_parameter)
00318 {
00319 
00320   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00321 
00322 }                               /* FSAL_load_FS_specific_parameter_from_conf */