nfs-ganesha 1.4
|
00001 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=4:tabstop=4: 00003 */ 00004 00005 #include "fsal_types.h" 00006 00007 #ifndef _POSIXDB_INTERNAL_H 00008 #define _POSIXDB_INTERNAL_H 00009 00010 #define MAX_HANDLEIDSTR_SIZE 21 // (size for "18446744073709551616" + 1 char for '\0') 00011 #define MAX_DEVICEIDSTR_SIZE 21 // (size for "18446744073709551616" + 1 char for '\0') 00012 #define MAX_INODESTR_SIZE 21 // (size for "18446744073709551616" + 1 char for '\0') 00013 #define MAX_HANDLETSSTR_SIZE 11 // (size for "4294967296" + 1 char for '\0') 00014 #define MAX_CTIMESTR_SIZE 11 00015 #define MAX_NLINKSTR_SIZE 11 00016 #define MAX_FTYPESTR_SIZE 11 00017 00018 #define ReturnCodeDB( _code_, _minor_ ) do { \ 00019 fsal_posixdb_status_t _struct_status_; \ 00020 if(isFullDebug(COMPONENT_FSAL)) \ 00021 { \ 00022 LogCrit(COMPONENT_FSAL, "Exiting %s ( %s:%i ) with status code = %i/%i\n", __FUNCTION__, __FILE__, __LINE__ - 2, _code_, _minor_ ); \ 00023 } \ 00024 (_struct_status_).major = (_code_) ; \ 00025 (_struct_status_).minor = (_minor_) ; \ 00026 return (_struct_status_); \ 00027 } while(0) 00028 00029 #define CheckCommand( _res_ ) do { \ 00030 if (PQresultStatus( _res_ ) != PGRES_COMMAND_OK) \ 00031 { \ 00032 LogCrit(COMPONENT_FSAL, "PGSQL Command Failed in %s ( %s:%i ) with %s", __FUNCTION__, __FILE__, __LINE__, (PQresultErrorMessage(_res_))); \ 00033 PQclear(_res_); \ 00034 RollbackTransaction( p_conn, _res_ ); \ 00035 ReturnCodeDB(ERR_FSAL_POSIXDB_CMDFAILED, (PQresultStatus( _res_ ))); \ 00036 } \ 00037 } while (0) 00038 00039 #define CheckResult( _res_ ) do { \ 00040 if (PQresultStatus( _res_ ) != PGRES_TUPLES_OK) \ 00041 { \ 00042 LogCrit(COMPONENT_FSAL, "PGSQL Select Failed in %s ( %s:%i ) with %s", __FUNCTION__, __FILE__, __LINE__, (PQresultErrorMessage(_res_))); \ 00043 PQclear(_res_); \ 00044 RollbackTransaction( p_conn, _res_ ); \ 00045 ReturnCodeDB(ERR_FSAL_POSIXDB_CMDFAILED, (PQresultStatus( _res_ ))); \ 00046 } \ 00047 } while (0) 00048 00049 #define CheckConn( _p_conn_ ) do { \ 00050 if (PQstatus( _p_conn_ ) != CONNECTION_OK) { \ 00051 LogCrit(COMPONENT_FSAL, "Reconnecting to database..."); \ 00052 PQreset( _p_conn_ );\ 00053 if (PQstatus( _p_conn_ ) != CONNECTION_OK) ReturnCodeDB(ERR_FSAL_POSIXDB_BADCONN, PQstatus( _p_conn_ ));/* Connexion still bad */ \ 00054 fsal_posixdb_initPreparedQueries( _p_conn_ ); \ 00055 } \ 00056 } while (0) 00057 00058 #define BeginTransaction( _conn_, _res_ ) do { \ 00059 PGTransactionStatusType transStatus = PQtransactionStatus(_conn_);\ 00060 if (transStatus != PQTRANS_ACTIVE && transStatus != PQTRANS_INTRANS) { \ 00061 _res_ = PQexec(_conn_, "BEGIN"); \ 00062 CheckCommand(_res_); \ 00063 PQclear(_res_); \ 00064 } \ 00065 } while (0) 00066 00067 #define EndTransaction( _conn_, _res_ ) do { \ 00068 _res_ = PQexec(_conn_, "END"); \ 00069 CheckCommand(_res_); \ 00070 PQclear(_res_); \ 00071 } while (0) 00072 00073 #define RollbackTransaction( _conn_, _res_ ) do { \ 00074 _res_ = PQexec(_conn_, "ROLLBACK"); \ 00075 PQclear(_res_); \ 00076 } while (0) 00077 00091 fsal_posixdb_status_t fsal_posixdb_buildOnePath(fsal_posixdb_conn * p_conn, /* IN */ 00092 posixfsal_handle_t * p_handle, /* IN */ 00093 fsal_path_t * p_path /* OUT */ ); 00094 00111 fsal_posixdb_status_t fsal_posixdb_recursiveDelete(fsal_posixdb_conn * p_conn, /* IN */ 00112 char *handleid_str, /* IN */ 00113 char *handlets_str, /* IN */ 00114 fsal_nodetype_t ftype); /* IN */ 00115 00138 fsal_posixdb_status_t fsal_posixdb_deleteParent(fsal_posixdb_conn * p_conn, /* IN */ 00139 char *handleid_str, /* IN */ 00140 char *handlets_str, /* IN */ 00141 char *handleidparent_str, /* IN */ 00142 char *handletsparent_str, /* IN */ 00143 char *filename, /* IN */ 00144 int nlink) /* IN */ ; 00145 00152 fsal_posixdb_status_t fsal_posixdb_internal_delete(fsal_posixdb_conn * p_conn, /* IN */ 00153 char *handleidparent_str, /* IN */ 00154 char *handletsparent_str, /* IN */ 00155 char *filename, /* IN */ 00156 fsal_posixdb_fileinfo_t * 00157 p_object_info /* IN */ ); 00158 00168 fsal_posixdb_status_t fsal_posixdb_initPreparedQueries(fsal_posixdb_conn * p_conn); 00169 00183 fsal_posixdb_status_t posixdb_internal_fillFileinfoFromStrValues(fsal_posixdb_fileinfo_t * 00184 p_info, char *devid_str, 00185 char *inode_str, 00186 char *nlink_str, 00187 char *ctime_str, 00188 char *ftype_str); 00189 00190 /* this manages a mini-cache for the last few handles handled 00191 * it is invalidated as soon has there is a modification in the database 00192 */ 00193 00194 /* enter an entry in cache path */ 00195 00196 void fsal_posixdb_CachePath(posixfsal_handle_t * p_handle, /* IN */ 00197 fsal_path_t * p_path /* IN */ ); 00198 00199 /* invalidate cache in case of a modification */ 00200 00201 void fsal_posixdb_InvalidateCache(); 00202 00203 /* get a path from the cache 00204 * return true if the entry is found, 00205 * false else. 00206 */ 00207 00208 int fsal_posixdb_GetPathCache(posixfsal_handle_t * p_handle, /* IN */ 00209 fsal_path_t * p_path /* OUT */ ); 00210 00211 /* update informations about a handle */ 00212 int fsal_posixdb_UpdateInodeCache(posixfsal_handle_t * p_handle); /* IN */ 00213 00214 /* retrieve last informations about a handle */ 00215 int fsal_posixdb_GetInodeCache(posixfsal_handle_t * p_handle); /* IN/OUT */ 00216 00217 #endif