nfs-ganesha 1.4
|
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 #ifdef _USE_GSSRPC 00027 #include <gssrpc/types.h> 00028 #include <gssrpc/rpc.h> 00029 #include <gssrpc/auth.h> 00030 #include <gssrpc/pmap_clnt.h> 00031 #else 00032 #include <rpc/types.h> 00033 #include <rpc/rpc.h> 00034 #include <rpc/auth.h> 00035 #include <rpc/pmap_clnt.h> 00036 #endif 00037 00038 #include "log.h" 00039 #include "nfs23.h" 00040 #include "nfs4.h" 00041 #include "mount.h" 00042 #include "nfs_core.h" 00043 #include "cache_inode.h" 00044 #include "nfs_exports.h" 00045 #include "nfs_creds.h" 00046 #include "nfs_proto_functions.h" 00047 #include "nfs_file_handle.h" 00048 #include "nfs_tools.h" 00049 #include "pnfs.h" 00050 #include "abstract_mem.h" 00051 00052 #include "pnfs_internal.h" 00053 00054 nfsstat4 PARALLEL_FS_pnfs_layoutget( LAYOUTGET4args * playoutgetargs, 00055 compound_data_t * data, 00056 LAYOUTGET4res * playoutgetres ) 00057 { 00058 unsigned int offset = 0; 00059 uint32_t int32 = 0; 00060 int64_t int64 = 0LL; 00061 unsigned int padlen = 0; 00062 char deviceid[NFS4_DEVICEID4_SIZE]; 00063 unsigned int i; 00064 char * buff = NULL ; 00065 unsigned int stripe = 1 ; 00066 nfs_fh4 * pnfsfh4 ; 00067 00068 if( !data || !playoutgetres ) 00069 return NFS4ERR_SERVERFAULT ; 00070 00071 pnfsfh4 = &data->currentFH ; 00072 00073 if((buff = gsh_malloc(1024)) == NULL) 00074 { 00075 playoutgetres->logr_status = NFS4ERR_SERVERFAULT; 00076 return playoutgetres->logr_status ; 00077 } 00078 00079 /* No return on close for the moment */ 00080 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_return_on_close = FALSE; 00081 00082 /* Manages the stateid */ 00083 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_stateid.seqid = 1; 00084 memcpy(playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_stateid.other, 00085 playoutgetargs->loga_stateid.other, 12); 00086 //file_state->stateid_other, 12); 00087 00088 /* Now the layout specific information */ 00089 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_layout.logr_layout_len = 1; 00090 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_layout.logr_layout_val = 00091 gsh_malloc(sizeof(layout4)); 00092 00093 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_layout.logr_layout_val[0].lo_offset = 00094 playoutgetargs->loga_offset; 00095 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_layout.logr_layout_val[0].lo_length = 0xFFFFFFFFFFFFFFFFLL; /* Whole file */ 00096 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_layout.logr_layout_val[0].lo_iomode = 00097 playoutgetargs->loga_iomode; 00098 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_layout.logr_layout_val[0]. 00099 lo_content.loc_type = LAYOUT4_NFSV4_1_FILES; 00100 00101 00104 /* nfl_deviceid */ 00105 memset(deviceid, 0, NFS4_DEVICEID4_SIZE); 00106 deviceid[0] = 1 ; 00107 memcpy((char *)(buff + offset), deviceid, NFS4_DEVICEID4_SIZE); 00108 offset += NFS4_DEVICEID4_SIZE; 00109 00110 /* nfl_util */ 00111 int32 = htonl(0x2000); 00112 memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32)); 00113 offset += sizeof(int32); 00114 00115 /* nfl_first_stripe_index */ 00116 int32 = 0; 00117 memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32)); 00118 offset += sizeof(int32); 00119 00120 /* nfl_pattern_offset */ 00121 int64 = 0LL; 00122 memcpy((char *)(buff + offset), (char *)&int64, sizeof(int64)); 00123 offset += sizeof(int64); 00124 00125 /* nfl_fh_list.nfl_fh_list_len */ 00126 int32 = htonl( stripe ); 00127 memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32)); 00128 offset += sizeof(int32); 00129 00130 for(i = 0; i < stripe; i++) 00131 { 00132 /* nfl_fh_list.nfl_fh_list_val[i].nfs_fh4_len */ 00133 int32 = htonl(pnfsfh4->nfs_fh4_len); 00134 memcpy((char *)(buff + offset), (char *)&int32, sizeof(int32)); 00135 offset += sizeof(int32); 00136 00137 /* nfl_fh_list.nfl_fh_list_val[i].nfs_fh4_len */ 00138 memcpy((char *)(buff + offset), pnfsfh4->nfs_fh4_val, pnfsfh4->nfs_fh4_len ) ; 00139 00140 /* Turn the file handle to a 'DS file handle' */ 00141 //if(pds_file->filepart[i].is_ganesha == FALSE) 00142 // ((char *)(buff + offset))[2] = 9; 00143 00144 /* Update the offset for encoding */ 00145 offset += pnfsfh4->nfs_fh4_len ; 00146 00147 /* XDR padding : keep stuff aligned on 32 bits pattern */ 00148 if( pnfsfh4->nfs_fh4_len == 0) 00149 padlen = 0; 00150 else 00151 padlen = 4 - ( pnfsfh4->nfs_fh4_len % 4); 00152 00153 if(padlen > 0) 00154 memset((char *)(buff + offset), 0, padlen); 00155 00156 offset += padlen; 00157 } /* for */ 00158 00159 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_layout.logr_layout_val[0]. 00160 lo_content.loc_body.loc_body_len = offset ; 00161 playoutgetres->LAYOUTGET4res_u.logr_resok4.logr_layout.logr_layout_val[0]. 00162 lo_content.loc_body.loc_body_val = buff; 00163 00164 playoutgetres->logr_status = NFS4_OK ; 00165 return NFS4_OK ; 00166 } /* pnfs_layoutget */ 00167