nfs-ganesha 1.4

posixdb.h

Go to the documentation of this file.
00001 
00005 #ifndef _FSAL_POSIX_DBEXT_H
00006 #define _FSAL_POSIX_DBEXT_H
00007 
00008 /*
00009  * DB relative includes & defines
00010  */
00011 #ifdef _USE_PGSQL
00012 /*
00013  * POSTGRESQL
00014  */
00015 #include <libpq-fe.h>
00016 #define fsal_posixdb_conn PGconn
00017 
00018 #elif defined(_USE_MYSQL)
00019 /*
00020  * MYSQL
00021  */
00022 #include <mysql.h>
00023 #include <mysqld_error.h>
00024 #include <errmsg.h>
00025 
00026 /* index for prepared requests */
00027 
00028 #define BUILDONEPATH          0
00029 
00030 #define NB_PREPARED_REQ       1
00031 
00032 typedef struct fsal_posixdb_conn__
00033 {
00034   MYSQL db_conn;
00035 
00036   /* array of prepared requests */
00037   MYSQL_STMT *stmt_tab[NB_PREPARED_REQ];
00038 
00039 } fsal_posixdb_conn;
00040 
00041 #elif defined(_USE_SQLITE3)
00042 /*
00043  * SQLite v3
00044  */
00045 #include <sqlite3.h>
00046 
00047 /* index for prepared requests */
00048 
00049 #define BUILDONEPATH          0
00050 #define LOOKUPPATHS           1
00051 #define LOOKUPPATHSEXT        2
00052 #define LOOKUPHANDLEBYNAME    3
00053 #define LOOKUPHANDLEBYNAMEFU  4
00054 #define LOOKUPROOTHANDLE      5
00055 #define LOOKUPHANDLEBYINODEFU 6
00056 #define LOOKUPHANDLEFU        7
00057 #define LOOKUPHANDLE          8
00058 #define UPDATEHANDLE          9
00059 #define UPDATEHANDLENLINK     10
00060 #define LOOKUPPARENT          11
00061 #define LOOKUPCHILDRENFU      12
00062 #define LOOKUPCHILDREN        13
00063 #define COUNTCHILDREN         14
00064 #define INSERTHANDLE          15
00065 #define UPDATEPARENT          16
00066 #define INSERTPARENT          17
00067 #define DELETEPARENT          18
00068 #define DELETEHANDLE          19
00069 
00070 #ifndef  HOST_NAME_MAX
00071 #define HOST_NAME_MAX          64
00072 #endif
00073 
00074 #define NB_PREPARED_REQ       20
00075 
00076 typedef struct fsal_posixdb_conn__
00077 {
00078   sqlite3 *db_conn;
00079 
00080   /* array of prepared requests */
00081   sqlite3_stmt *stmt_tab[NB_PREPARED_REQ];
00082 
00083 } fsal_posixdb_conn;
00084 
00085 #else
00086 
00087 #error "No DB compilation flag set for POSIXDB."
00088 
00089 #endif
00090 
00091 /*
00092  * DB independant definitions 
00093  */
00094 
00095 #ifdef _APPLE
00096 #define FSAL_MAX_DBHOST_NAME_LEN 64
00097 #else
00098 #define FSAL_MAX_DBHOST_NAME_LEN  HOST_NAME_MAX
00099 #endif
00100 
00101 #define FSAL_MAX_DBPORT_STR_LEN   8
00102 #define FSAL_MAX_DB_NAME_LEN      64
00103 
00104 #ifdef _APPLE
00105 #define FSAL_MAX_DB_LOGIN_LEN    256
00106 #else
00107 #define FSAL_MAX_DB_LOGIN_LEN     LOGIN_NAME_MAX
00108 #endif
00109 
00110 #define FSAL_POSIXDB_MAXREADDIRBLOCKSIZE 64
00111 
00112 #ifndef _USE_SQLITE3
00113 
00114 typedef struct
00115 {
00116   char host[FSAL_MAX_DBHOST_NAME_LEN];
00117   char port[FSAL_MAX_DBPORT_STR_LEN];
00118   char dbname[FSAL_MAX_DB_NAME_LEN];
00119   char login[FSAL_MAX_DB_LOGIN_LEN];
00120   char passwdfile[PATH_MAX];
00121 } fsal_posixdb_conn_params_t;
00122 
00123 #else
00124 
00125 typedef struct
00126 {
00127   char dbfile[FSAL_MAX_PATH_LEN];
00128   char tempdir[FSAL_MAX_PATH_LEN];
00129 } fsal_posixdb_conn_params_t;
00130 
00131 #endif
00132 
00133 typedef struct
00134 {
00135   posixfsal_handle_t handle;
00136   fsal_name_t name;
00137 } fsal_posixdb_child;
00138 
00139 /*
00140  * POSIXDB structures (for status and results)
00141  */
00142 
00143 typedef enum fsal_posixdb_errorcode
00144 {
00145   ERR_FSAL_POSIXDB_NOERR = 0,   /* no error */
00146   ERR_FSAL_POSIXDB_BADCONN,     /* not connected to the database */
00147   ERR_FSAL_POSIXDB_NOENT,       /* no such object in the database */
00148   ERR_FSAL_POSIXDB_CMDFAILED,   /* a command failed */
00149   ERR_FSAL_POSIXDB_FAULT,       /* sanity check failed, ... */
00150   ERR_FSAL_POSIXDB_NOPATH,
00151   ERR_FSAL_POSIXDB_TOOMANYPATHS,
00152   ERR_FSAL_POSIXDB_PATHTOOLONG,
00153   ERR_FSAL_POSIXDB_CONSISTENCY, /* entry is not consistent */
00154   ERR_FSAL_POSIXDB_NO_MEM       /* allocation error */
00155 } fsal_posixdb_errorcode;
00156 
00157 typedef struct fsal_posixdb_status_t
00158 {
00159   int major;
00160   int minor;
00161 } fsal_posixdb_status_t;
00162 
00163 #define FSAL_POSIXDB_IS_ERROR( _status_ ) \
00164           ( ! ( ( _status_ ).major == ERR_FSAL_POSIXDB_NOERR ) )
00165 
00166 #define FSAL_POSIXDB_IS_NOENT( _status_ ) \
00167           ( ( _status_ ).major == ERR_FSAL_POSIXDB_NOENT )
00168 
00169 /* for initializing DB cache */
00170 int fsal_posixdb_cache_init();
00171 
00183 fsal_posixdb_status_t fsal_posixdb_connect(fsal_posixdb_conn_params_t * p_params,       /* IN */
00184                                            fsal_posixdb_conn ** p_conn /* OUT */ );
00185 
00195 fsal_posixdb_status_t fsal_posixdb_disconnect(fsal_posixdb_conn * p_conn);
00196 
00214 fsal_posixdb_status_t fsal_posixdb_getInfoFromName(fsal_posixdb_conn * p_conn,  /* IN */
00215                                                    posixfsal_handle_t * p_parent_directory_handle,      /* IN */
00216                                                    fsal_name_t * p_objectname,  /* IN */
00217                                                    fsal_path_t * p_path,        /* OUT */
00218                                                    posixfsal_handle_t *
00219                                                    p_handle /* OUT */ );
00220 
00240 fsal_posixdb_status_t fsal_posixdb_getInfoFromHandle(fsal_posixdb_conn * p_conn,        /* IN */
00241                                                      posixfsal_handle_t * p_object_handle,      /* IN */
00242                                                      fsal_path_t * p_paths,     /* OUT */
00243                                                      int paths_size,    /* IN */
00244                                                      int *p_count /* OUT */ );
00245 
00264 fsal_posixdb_status_t fsal_posixdb_add(fsal_posixdb_conn * p_conn,      /* IN */
00265                                        fsal_posixdb_fileinfo_t * p_object_info, /* IN */
00266                                        posixfsal_handle_t * p_parent_directory_handle,  /* IN */
00267                                        fsal_name_t * p_filename,        /* IN */
00268                                        posixfsal_handle_t * p_object_handle /* OUT */ );
00269 
00290 fsal_posixdb_status_t fsal_posixdb_replace(fsal_posixdb_conn * p_conn,  /* IN */
00291                                            fsal_posixdb_fileinfo_t * p_object_info,     /* IN */
00292                                            posixfsal_handle_t * p_parent_directory_handle_old,  /* IN */
00293                                            fsal_name_t * p_filename_old,        /* IN */
00294                                            posixfsal_handle_t * p_parent_directory_handle_new,  /* IN */
00295                                            fsal_name_t * p_filename_new /* IN */ );
00296 
00312 fsal_posixdb_status_t fsal_posixdb_delete(fsal_posixdb_conn * p_conn,   /* IN */
00313                                           posixfsal_handle_t * p_parent_directory_handle,       /* IN */
00314                                           fsal_name_t * p_filename,     /* IN */
00315                                           fsal_posixdb_fileinfo_t *
00316                                           p_object_info /* IN */ );
00317 
00329 fsal_posixdb_status_t fsal_posixdb_deleteHandle(fsal_posixdb_conn * p_conn,     /* IN */
00330                                                 posixfsal_handle_t * p_handle /* IN */ );
00331 
00349 fsal_posixdb_status_t fsal_posixdb_getChildren(fsal_posixdb_conn * p_conn,      /* IN */
00350                                                posixfsal_handle_t * p_parent_directory_handle,  /* IN */
00351                                                unsigned int max_count, fsal_posixdb_child ** p_children,        /* OUT */
00352                                                unsigned int *p_count /* OUT */ );
00353 
00363 fsal_posixdb_status_t fsal_posixdb_export(fsal_posixdb_conn * p_conn,   /* IN */
00364                                           FILE * out /* IN */ );
00365 
00375 fsal_posixdb_status_t fsal_posixdb_import(fsal_posixdb_conn * p_conn,   /* IN */
00376                                           FILE * in /* IN */ );
00377 
00385 fsal_posixdb_status_t fsal_posixdb_flush(fsal_posixdb_conn * p_conn /* IN */ );
00386 
00398 fsal_posixdb_status_t fsal_posixdb_getParentDirHandle(fsal_posixdb_conn * p_conn,       /* IN */
00399                                                       posixfsal_handle_t * p_object_handle,     /* IN */
00400                                                       posixfsal_handle_t * p_parent_directory_handle    /* OUT */
00401     );
00402 
00414 fsal_posixdb_status_t fsal_posixdb_lockHandleForUpdate(fsal_posixdb_conn * p_conn,      /* IN */
00415                                                        fsal_posixdb_fileinfo_t *
00416                                                        p_info /* IN */ );
00417 
00427 fsal_posixdb_status_t fsal_posixdb_cancelHandleLock(fsal_posixdb_conn * p_conn /* IN */ );
00428 
00429 #endif