diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-04-10 11:40:10 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-04-10 11:40:10 +0200 |
commit | 98bfb4f6aa76aa3a5242fe2db3d1fabc69a5bdae (patch) | |
tree | fc0de056cc219cb91d926ea632dd0d9532657480 | |
parent | e269892480767b089cb999e87cc05becfdef26d2 (diff) | |
download | pgfuse-98bfb4f6aa76aa3a5242fe2db3d1fabc69a5bdae.tar.gz pgfuse-98bfb4f6aa76aa3a5242fe2db3d1fabc69a5bdae.tar.bz2 |
more cleanup
fixed lost connections after fuse reinitializations
-rw-r--r-- | config.h | 33 | ||||
-rw-r--r-- | pgfuse.c | 31 | ||||
-rw-r--r-- | pgsql.h | 5 |
3 files changed, 53 insertions, 16 deletions
diff --git a/config.h b/config.h new file mode 100644 index 0000000..8795ef6 --- /dev/null +++ b/config.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 2012 Andreas Baumann <abaumann@yahoo.com> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +/* standard block size, rather a simulation currently */ +#define STANDARD_BLOCK_SIZE 512 + +/* maximal number of open files, limited currently due to a too simple + * hash table implementation of open file handles */ +#define MAX_NOF_OPEN_FILES 256 + +/* maximum size of a file, rather arbitrary, 2^31 is a current implementation + * limit, before fixing this, the storing and efficiency has to be rethought + * anyway.. */ +#define MAX_FILE_SIZE 65535 + +#endif @@ -29,20 +29,9 @@ #include <fuse.h> /* for user-land filesystem */ #include <fuse_opt.h> /* fuse command line parser */ +#include "config.h" /* compiled in defaults */ #include "pgsql.h" /* implements Postgresql accessers */ -/* standard block size, rather a simulation currently */ -#define STANDARD_BLOCK_SIZE 512 - -/* maximal number of open files, limited currently due to a too simple - * hash table implementation of open file handles */ -#define MAX_NOF_OPEN_FILES 256 - -/* maximum size of a file, rather arbitrary, 2^31 is a current implementation - * limit, before fixing this, the storing and efficiency has to be rethought - * anyway.. */ -#define MAX_FILE_SIZE 65535 - /* --- internal file handles */ typedef struct PgFuseFile { @@ -74,6 +63,13 @@ static void *pgfuse_init( struct fuse_conn_info *conn ) } memset( pgfuse_files, 0, sizeof( PgFuseFile ) * MAX_NOF_OPEN_FILES ); + + data->conn = PQconnectdb( data->conninfo ); + if( PQstatus( data->conn ) != CONNECTION_OK ) { + syslog( LOG_ERR, "Connection to database failed: %s", + PQerrorMessage( data->conn ) ); + PQfinish( data->conn ); + } return data; } @@ -85,6 +81,8 @@ static void pgfuse_destroy( void *userdata ) syslog( LOG_INFO, "Unmounting file system on '%s' (%s)", data->mountpoint, data->conninfo ); } + + PQfinish( data->conn ); } @@ -737,6 +735,9 @@ int main( int argc, char *argv[] ) exit( EXIT_FAILURE ); } + /* just test if the connection can be established, do the + * real connection in the fuse init function! + */ conn = PQconnectdb( pgfuse.conninfo ); if( PQstatus( conn ) != CONNECTION_OK ) { fprintf( stderr, "Connection to database failed: %s", @@ -744,18 +745,16 @@ int main( int argc, char *argv[] ) PQfinish( conn ); exit( EXIT_FAILURE ); } + PQfinish( conn ); - openlog( basename( argv[0] ), LOG_PID, LOG_USER ); + openlog( basename( argv[0] ), LOG_PID, LOG_USER ); memset( &userdata, 0, sizeof( PgFuseData ) ); userdata.conninfo = pgfuse.conninfo; - userdata.conn = conn; userdata.mountpoint = pgfuse.mountpoint; userdata.verbose = pgfuse.verbose; res = fuse_main( args.argc, args.argv, &pgfuse_oper, &userdata ); - - PQfinish( conn ); exit( res ); } @@ -15,6 +15,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef PGSQL_H +#define PGSQL_H + #include <sys/types.h> /* size_t */ #include <sys/stat.h> /* mode_t */ @@ -40,3 +43,5 @@ int psql_create_dir( PGconn *conn, const int parent_id, const char *path, const int psql_write_buf( PGconn *conn, const int id, const char *path, const char *buf, const size_t len ); int psql_write_meta( PGconn *conn, const int id, const char *path, PgMeta meta ); + +#endif |