nfs-ganesha 1.4

pnfs_getdeviceinfo.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  */
00004 
00011 #ifdef HAVE_CONFIG_H
00012 #include "config.h"
00013 #endif
00014 
00015 #ifdef _SOLARIS
00016 #include "solaris_port.h"
00017 #endif                          /* _SOLARIS */
00018 
00019 #include <stdio.h>
00020 #include <string.h>
00021 #include <pthread.h>
00022 #include <fcntl.h>
00023 #include <sys/file.h>           /* for having FNDELAY */
00024 #include "HashData.h"
00025 #include "HashTable.h"
00026 #include "log.h"
00027 #include "ganesha_rpc.h"
00028 #include "nfs23.h"
00029 #include "nfs4.h"
00030 #include "mount.h"
00031 #include "nfs_core.h"
00032 #include "cache_inode.h"
00033 #include "nfs_exports.h"
00034 #include "nfs_creds.h"
00035 #include "nfs_proto_functions.h"
00036 #include "nfs_file_handle.h"
00037 #include "nfs_tools.h"
00038 #include "pnfs.h" 
00039 #include "pnfs_internal.h"
00040 
00055 pnfs_parameter_t pnfs_param ;
00056 
00057 nfsstat4 PARALLEL_FS_pnfs_getdeviceinfo( GETDEVICEINFO4args  * pgetdeviceinfoargs,
00058                                          compound_data_t     * data,
00059                                          GETDEVICEINFO4res   * pgetdeviceinfores )
00060 {
00061   unsigned int offset = 0;
00062   uint32_t int32 = 0;
00063   char tmpchar[MAXNAMLEN];
00064   unsigned int tmplen = 0;
00065   unsigned int padlen = 0;
00066   unsigned int i = 0;
00067 
00068   char *buff = NULL ;
00069 
00070   buff = (char *)pgetdeviceinfores->GETDEVICEINFO4res_u.gdir_resok4.gdir_device_addr.da_addr_body.da_addr_body_val ;
00071 
00072   /* nflda_stripe_indices.nflda_stripe_indices_len */
00073   int32 = htonl(pnfs_param.stripe_width);
00074   memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32));
00075   offset += sizeof(int32);
00076 
00077   for(i = 0; i < pnfs_param.stripe_width; i++)
00078     {
00079       /* nflda_stripe_indices.nflda_stripe_indices_val */
00080       int32 = htonl(i);
00081       memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32));
00082       offset += sizeof(int32);
00083     }
00084 
00085   /* nflda_multipath_ds_list.nflda_multipath_ds_list_len */
00086   int32 = htonl(pnfs_param.stripe_width);
00087   memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32));
00088   offset += sizeof(int32);
00089 
00090   for(i = 0; i < pnfs_param.stripe_width; i++)
00091     {
00092       /* nflda_multipath_ds_list.nflda_multipath_ds_list_val[i].multipath_list4_len */
00093       int32 = htonl(1);
00094       memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32));
00095       offset += sizeof(int32);
00096 
00097       /* nflda_multipath_ds_list.nflda_multipath_ds_list_val[i].multipath_list4_val[0].na_r_netid */
00098       int32 = htonl(3);         /* because strlen( "tcp" ) = 3 */
00099       memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32));
00100       offset += sizeof(int32);
00101 
00102       memset(tmpchar, 0, MAXNAMLEN);
00103       strncpy(tmpchar, "tcp", MAXNAMLEN);
00104       memcpy((char *)(buff + offset), tmpchar, 4);      /* 4 bytes = 3 bytes for "tcp" and 1 to keep XDR alignment */
00105       offset += 4;
00106 
00107       /* nflda_multipath_ds_list.nflda_multipath_ds_list_val[i].multipath_list4_val[0].na_r_addr */
00108       memset(tmpchar, 0, MAXNAMLEN);
00109       snprintf(tmpchar, MAXNAMLEN, "%s.%u.%u",
00110                pnfs_param.ds_param[i].ipaddr_ascii,
00111                pnfs_param.ds_param[i].ipport & 0x0F,
00112                pnfs_param.ds_param[i].ipport >> 8);
00113       tmplen = strnlen(tmpchar, MAXNAMLEN);
00114 
00115       /* XDR padding : keep stuff aligned on 32 bits pattern */
00116       if(tmplen % 4 == 0)
00117         padlen = 0;
00118       else
00119         padlen = 4 - (tmplen % 4);
00120 
00121       /* len of na_r_addr */
00122       int32 = htonl(tmplen);
00123       memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32));
00124       offset += sizeof(int32);
00125 
00126       memcpy((char *)(buff + offset), tmpchar, tmplen + padlen);
00127       offset += tmplen + padlen;
00128 
00129     }                           /* for */
00130  
00131   pgetdeviceinfores->GETDEVICEINFO4res_u.gdir_resok4.gdir_device_addr.da_addr_body.da_addr_body_len = offset ;
00132  
00133   pgetdeviceinfores->gdir_status = NFS4_OK;
00134 
00135   return pgetdeviceinfores->gdir_status  ;
00136 }                               /* pnfs_getdeviceinfo */
00137