nfs-ganesha 1.4
|
00001 /* 00002 * 00003 * 00004 * Copyright CEA/DAM/DIF (2008) 00005 * contributeur : Philippe DENIEL philippe.deniel@cea.fr 00006 * Thomas LEIBOVICI thomas.leibovici@cea.fr 00007 * 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 3 of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 * --------------------------------------- 00024 */ 00025 00037 #ifndef _NFS_FILE_HANDLE_H 00038 #define _NFS_FILE_HANDLE_H 00039 00040 #include <sys/types.h> 00041 #include <sys/param.h> 00042 00043 00044 #include <dirent.h> /* for having MAXNAMLEN */ 00045 #include <netdb.h> /* for having MAXHOSTNAMELEN */ 00046 #include "log.h" 00047 #include "nfs23.h" 00048 #ifdef _USE_NLM 00049 #include "nlm4.h" 00050 #endif 00051 00052 /* 00053 * Structure of the filehandle 00054 * these structures must be naturally aligned. The xdr buffer from/to which 00055 * they come/go are 4 byte aligned. 00056 */ 00057 00058 #define ULTIMATE_ANSWER 0x42 00059 00060 #define GANESHA_FH_VERSION ULTIMATE_ANSWER - 1 00061 00062 /* This must be exactly 32 bytes long, and aligned on 32 bits */ 00063 typedef struct file_handle_v2 00064 { 00065 uint8_t fhversion; /* set to 0x41 to separate from Linux knfsd len = 1 byte */ 00066 uint8_t xattr_pos; /* Used for xattr management len = 1 byte */ 00067 uint16_t exportid; /* must be correlated to exportlist_t::id len = 2 bytes */ 00068 uint8_t fsopaque[28]; /* persistent part of FSAL handle, opaque len = 28 bytes */ 00069 } file_handle_v2_t; 00070 00071 /* An NFSv2 handle of fixed size. use for allocations only. 00072 * there is no padding because v2 handles must be fixed size. 00073 */ 00074 00075 struct alloc_file_handle_v2 { 00076 struct file_handle_v2 handle; /* the real handle */ 00077 }; 00078 00079 /* This is up to 64 bytes long, aligned on 32 bits */ 00080 typedef struct file_handle_v3 00081 { 00082 uint8_t fhversion; /* set to 0x41 to separate from Linux knfsd len = 1 byte */ 00083 uint8_t xattr_pos; /* Used for xattr management len = 1 byte */ 00084 uint16_t exportid; /* must be correlated to exportlist_t::id len = 2 bytes */ 00085 uint8_t fs_len; /* actual length of opaque handle len = 1 byte */ 00086 uint8_t fsopaque[]; /* persistent part of FSAL handle, opaque len <= 59 bytes */ 00087 } file_handle_v3_t; 00088 00089 /* An NFSv3 handle of maximum size. use this for allocations, sizeof, and memset only. 00090 * the pad space is where the opaque handle expands into. pad is struct aligned 00091 */ 00092 00093 struct alloc_file_handle_v3 { 00094 struct file_handle_v3 handle; /* the real handle */ 00095 uint8_t pad[58]; /* pad to mandatory max 64 bytes */ 00096 }; 00097 00098 /* nfs3_sizeof_handle 00099 * return the actual size of a handle based on the sized fsopaque 00100 */ 00101 00102 static inline size_t nfs3_sizeof_handle(struct file_handle_v3 *hdl) 00103 { 00104 return offsetof(struct file_handle_v3, fsopaque) + hdl->fs_len; 00105 } 00106 00107 /* This is up to 128 bytes, aligned on 32 bits 00108 */ 00109 typedef struct file_handle_v4 00110 { 00111 uint8_t fhversion; /* set to 0x41 to separate from Linux knfsd len = 1 byte */ 00112 uint8_t xattr_pos; /* len = 1 byte */ 00113 uint16_t exportid; /* must be correlated to exportlist_t::id len = 2 bytes */ 00114 uint32_t srvboot_time; /* 0 if FH won't expire len = 4 bytes */ 00115 uint16_t pseudofs_id; /* Id for the pseudo fs related to this fh len = 2 bytes */ 00116 uint16_t refid; /* used for referral len = 2 bytes */ 00117 uint8_t ds_flag; /* TRUE if FH is a 'DS file handle' len = 1 byte */ 00118 uint8_t pseudofs_flag; /* TRUE if FH is within pseudofs len = 1 byte */ 00119 uint8_t fs_len; /* actual length of opaque handle len = 1 byte */ 00120 uint8_t fsopaque[]; /* persistent part of FSAL handle len <= 113 bytes */ 00121 } file_handle_v4_t; 00122 00123 /* An NFSv4 handle of maximum size. use for allocations, sizeof, and memset only 00124 * the pad space is where the opaque handle expands into. pad is struct aligned 00125 */ 00126 struct alloc_file_handle_v4 { 00127 struct file_handle_v4 handle; /* the real handle */ 00128 uint8_t pad[112]; /* pad to mandatory max 128 bytes */ 00129 }; 00130 00131 /* nfs4_sizeof_handle 00132 * return the actual size of a handle based on the sized fsopaque 00133 */ 00134 00135 static inline size_t nfs4_sizeof_handle(struct file_handle_v4 *hdl) 00136 { 00137 return offsetof(struct file_handle_v4, fsopaque) + hdl->fs_len; 00138 } 00139 00140 #define LEN_FH_STR 1024 00141 00142 00143 /* File handle translation utility */ 00144 int nfs4_FhandleToFSAL(nfs_fh4 * pfh4, 00145 struct fsal_handle_desc *fh_desc, 00146 fsal_op_context_t * pcontext); 00147 int nfs3_FhandleToFSAL(nfs_fh3 * pfh3, 00148 struct fsal_handle_desc *fh_desc, 00149 fsal_op_context_t * pcontext); 00150 int nfs2_FhandleToFSAL(fhandle2 * pfh2, 00151 struct fsal_handle_desc *fh_desc, 00152 fsal_op_context_t * pcontext); 00153 00154 int nfs4_FSALToFhandle(nfs_fh4 *pfh4, 00155 fsal_handle_t *pfsalhandle, 00156 compound_data_t *data); 00157 int nfs3_FSALToFhandle(nfs_fh3 * pfh3, fsal_handle_t * pfsalhandle, 00158 exportlist_t * pexport); 00159 int nfs2_FSALToFhandle(fhandle2 * pfh2, fsal_handle_t * pfsalhandle, 00160 exportlist_t * pexport); 00161 00162 /* Extraction of export id from a file handle */ 00163 short nfs2_FhandleToExportId(fhandle2 * pfh2); 00164 short nfs4_FhandleToExportId(nfs_fh4 * pfh4); 00165 short nfs3_FhandleToExportId(nfs_fh3 * pfh3); 00166 00167 #ifdef _USE_NLM 00168 short nlm4_FhandleToExportId(netobj * pfh3); 00169 #endif 00170 00171 /* nfs3 validation */ 00172 int nfs3_Is_Fh_Invalid(nfs_fh3 *pfh3); 00173 00174 /* NFSv4 specific FH related functions */ 00175 int nfs4_Is_Fh_Empty(nfs_fh4 * pfh); 00176 int nfs4_Is_Fh_Xattr(nfs_fh4 * pfh); 00177 int nfs4_Is_Fh_Pseudo(nfs_fh4 * pfh); 00178 int nfs4_Is_Fh_Expired(nfs_fh4 * pfh); 00179 int nfs4_Is_Fh_Invalid(nfs_fh4 * pfh); 00180 int nfs4_Is_Fh_Referral(nfs_fh4 * pfh); 00181 int nfs4_Is_Fh_DSHandle(nfs_fh4 * pfh); 00182 00183 /* This one is used to detect Xattr related FH */ 00184 int nfs3_Is_Fh_Xattr(nfs_fh3 * pfh); 00185 00186 /* File handle print function (;ostly use for debugging) */ 00187 void print_fhandle2(log_components_t component, fhandle2 *fh); 00188 void print_fhandle3(log_components_t component, nfs_fh3 *fh); 00189 void print_fhandle4(log_components_t component, nfs_fh4 *fh); 00190 void print_fhandle_nlm(log_components_t component, netobj *fh); 00191 void print_buff(log_components_t component, char *buff, int len); 00192 void LogCompoundFH(compound_data_t * data); 00193 00194 void sprint_fhandle2(char *str, fhandle2 *fh); 00195 void sprint_fhandle3(char *str, nfs_fh3 *fh); 00196 void sprint_fhandle4(char *str, nfs_fh4 *fh); 00197 void sprint_fhandle_nlm(char *str, netobj *fh); 00198 void sprint_buff(char *str, char *buff, int len); 00199 void sprint_mem(char *str, char *buff, int len); 00200 00201 void nfs4_sprint_fhandle(nfs_fh4 * fh4p, char *outstr) ; 00202 00203 #define LogHandleNFS4( label, fh4p ) \ 00204 do { \ 00205 if(isFullDebug(COMPONENT_NFS_V4)) \ 00206 { \ 00207 char str[LEN_FH_STR]; \ 00208 sprint_fhandle4(str, fh4p); \ 00209 LogFullDebug(COMPONENT_NFS_V4, "%s%s", label, str); \ 00210 } \ 00211 } while (0) 00212 00213 #endif /* _NFS_FILE_HANDLE_H */