summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-07-24 13:24:33 +0200
committerSimon Rettberg2020-07-24 13:24:33 +0200
commit2fe1dc1fb47aaaff6c9d7d9e3f6e4f1e304bbb66 (patch)
tree0834b9f6f1443672de7eeaae20c2675445bcea5f
parent[FUSE] Detach old receive thread when creating anew one, update var (diff)
downloaddnbd3-2fe1dc1fb47aaaff6c9d7d9e3f6e4f1e304bbb66.tar.gz
dnbd3-2fe1dc1fb47aaaff6c9d7d9e3f6e4f1e304bbb66.tar.xz
dnbd3-2fe1dc1fb47aaaff6c9d7d9e3f6e4f1e304bbb66.zip
[FUSE] Cleanup
-rw-r--r--src/fuse/connection.c14
-rw-r--r--src/fuse/main.c43
2 files changed, 24 insertions, 33 deletions
diff --git a/src/fuse/connection.c b/src/fuse/connection.c
index f9e942b..2fa7c57 100644
--- a/src/fuse/connection.c
+++ b/src/fuse/connection.c
@@ -256,9 +256,7 @@ bool connection_read( dnbd3_async_t *request )
if ( !dnbd3_get_block( connection.sockFd, request->offset, request->length, (uint64_t)request, 0 ) ) {
shutdown( connection.sockFd, SHUT_RDWR );
connection.sockFd = -1;
- pthread_mutex_unlock( &connection.sendMutex );
signal_call( connection.panicSignal );
- return true;
}
}
pthread_mutex_unlock( &connection.sendMutex );
@@ -268,9 +266,7 @@ bool connection_read( dnbd3_async_t *request )
void connection_close()
{
static bool signalled = false;
- if ( true ) {
- logadd( LOG_INFO, "Tearing down dnbd3 connections and workers" );
- }
+ logadd( LOG_INFO, "Tearing down dnbd3 connections and workers" );
pthread_mutex_lock( &mutexInit );
keepRunning = false;
if ( threadInitDone && !signalled ) {
@@ -502,10 +498,10 @@ static void* connection_backgroundThread( void *something UNUSED )
if ( timing_reachedPrecise( &nextKeepalive, &now ) ) {
pthread_mutex_lock( &connection.sendMutex );
if ( connection.sockFd != -1 ) {
- dnbd3_request_t request;
- request.magic = dnbd3_packet_magic;
- request.cmd = CMD_KEEPALIVE;
- request.handle = request.offset = request.size = 0;
+ dnbd3_request_t request = {
+ .magic = dnbd3_packet_magic,
+ .cmd = CMD_KEEPALIVE,
+ };
fixup_request( request );
ssize_t ret = sock_sendAll( connection.sockFd, &request, sizeof request, 2 );
if ( (size_t)ret != sizeof request ) {
diff --git a/src/fuse/main.c b/src/fuse/main.c
index 70181ad..736dfc8 100644
--- a/src/fuse/main.c
+++ b/src/fuse/main.c
@@ -64,19 +64,17 @@ static void printVersion();
static int image_stat( fuse_ino_t ino, struct stat *stbuf )
{
- stbuf->st_ctim = stbuf->st_atim = stbuf->st_mtim = startupTime;
- stbuf->st_uid = owner;
- stbuf->st_ino = ino;
switch ( ino ) {
case INO_ROOT:
stbuf->st_mode = S_IFDIR | 0550;
stbuf->st_nlink = 2;
+ stbuf->st_mtim = startupTime;
break;
-
case INO_IMAGE:
stbuf->st_mode = S_IFREG | 0440;
stbuf->st_nlink = 1;
stbuf->st_size = imageSize;
+ stbuf->st_mtim = startupTime;
break;
case INO_STATS:
stbuf->st_mode = S_IFREG | 0440;
@@ -84,47 +82,46 @@ static int image_stat( fuse_ino_t ino, struct stat *stbuf )
stbuf->st_size = 4096;
clock_gettime( CLOCK_REALTIME, &stbuf->st_mtim );
break;
-
default:
return -1;
}
+ stbuf->st_ctim = stbuf->st_atim = startupTime;
+ stbuf->st_uid = owner;
+ stbuf->st_ino = ino;
return 0;
}
static void image_ll_getattr( fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi )
{
- struct stat stbuf;
-
+ struct stat stbuf = { 0 };
( void ) fi;
- memset( &stbuf, 0, sizeof( stbuf ) );
- if ( image_stat( ino, &stbuf ) == -1 )
+ if ( image_stat( ino, &stbuf ) == -1 ) {
fuse_reply_err( req, ENOENT );
- else
- fuse_reply_attr( req, &stbuf, 1.0 ); // 1.0 seconds validity timeout
+ } else {
+ fuse_reply_attr( req, &stbuf, ino == INO_IMAGE ? 120 : 1 ); // seconds validity timeout
+ }
}
static void image_ll_lookup( fuse_req_t req, fuse_ino_t parent, const char *name )
{
- struct fuse_entry_param e;
( void )parent;
if ( strcmp( name, IMAGE_NAME ) == 0 || strcmp( name, STATS_NAME ) == 0 ) {
- memset( &e, 0, sizeof( e ) );
+ struct fuse_entry_param e = { 0 };
if ( strcmp( name, IMAGE_NAME ) == 0 ) {
e.ino = INO_IMAGE;
+ e.attr_timeout = e.entry_timeout = 120;
} else {
e.ino = INO_STATS;
+ e.attr_timeout = e.entry_timeout = 1;
+ }
+ if ( image_stat( e.ino, &e.attr ) == 0 ) {
+ fuse_reply_entry( req, &e );
+ return;
}
- e.attr_timeout = 1.0;
- e.entry_timeout = 1.0;
- image_stat( e.ino, &e.attr );
-
- fuse_reply_entry( req, &e );
- }
- else {
- fuse_reply_err( req, ENOENT );
}
+ fuse_reply_err( req, ENOENT );
}
struct dirbuf {
@@ -134,12 +131,10 @@ struct dirbuf {
static void dirbuf_add( fuse_req_t req, struct dirbuf *b, const char *name, fuse_ino_t ino )
{
- struct stat stbuf;
+ struct stat stbuf = { .st_ino = ino };
size_t oldsize = b->size;
b->size += fuse_add_direntry( req, NULL, 0, name, NULL, 0 );
b->p = ( char * ) realloc( b->p, b->size );
- memset( &stbuf, 0, sizeof( stbuf ) );
- stbuf.st_ino = ino;
fuse_add_direntry( req, b->p + oldsize, b->size - oldsize, name, &stbuf, b->size );
return;
}