Skip to content

Commit

Permalink
Exit process with error code if s3backer store setup fails at startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
archiecobbs committed Feb 28, 2019
1 parent 21ffe47 commit 0b0e908
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGES
@@ -1,6 +1,7 @@
Version Next

- Don't claim cache hit if partial write required reading the block (pr #103)
- Exit process with error code if s3backer store setup fails at startup

Version 1.5.0 released June 9, 2018

Expand Down
39 changes: 21 additions & 18 deletions fuse_ops.c
Expand Up @@ -128,18 +128,33 @@ const struct fuse_operations s3backer_fuse_ops = {

/* Configuration and underlying s3backer_store */
static struct fuse_ops_conf *config;
static struct fuse_ops_private *the_priv;

/****************************************************************************
* PUBLIC FUNCTION DEFINITIONS *
****************************************************************************/

const struct fuse_operations *
fuse_ops_create(struct fuse_ops_conf *config0)
fuse_ops_create(struct fuse_ops_conf *config0, struct s3backer_store *s3b)
{
if (config != NULL) {
(*config0->log)(LOG_ERR, "s3backer_get_fuse_ops(): duplicate invocation");
/* Sanity check */
assert(config0 != null);
assert(s3b != null);

/* Prevent duplicate invocation */
if (config != NULL || the_priv != NULL) {
(*config0->log)(LOG_ERR, "fuse_ops_create(): duplicate invocation");
return NULL;
}

/* Create private structure */
if ((the_priv = calloc(1, sizeof(*the_priv))) == NULL) {
(*config->log)(LOG_ERR, "fuse_ops_create(): %s", strerror(errno));
return NULL;
}
the_priv->s3b = s3b;

/* Now we're ready */
config = config0;
return &s3backer_fuse_ops;
}
Expand All @@ -152,28 +167,16 @@ static void *
fuse_op_init(struct fuse_conn_info *conn)
{
struct s3b_config *const s3bconf = config->s3bconf;
struct fuse_ops_private *priv;
struct fuse_ops_private *const priv = the_priv;

/* Create private structure */
if ((priv = calloc(1, sizeof(*priv))) == NULL) {
(*config->log)(LOG_ERR, "fuse_op_init(): %s", strerror(errno));
exit(1);
}
assert(priv != NULL);
assert(priv->s3b != NULL);
priv->block_bits = ffs(config->block_size) - 1;
priv->start_time = time(NULL);
priv->file_atime = priv->start_time;
priv->file_mtime = priv->start_time;
priv->stats_atime = priv->start_time;
priv->file_size = config->num_blocks * config->block_size;

/* Create backing store */
if ((priv->s3b = s3backer_create_store(s3bconf)) == NULL) {
(*config->log)(LOG_ERR, "fuse_op_init(): can't create s3backer_store: %s", strerror(errno));
free(priv);
return NULL;
}

/* Done */
(*config->log)(LOG_INFO, "mounting %s", s3bconf->mount);
return priv;
}
Expand Down
3 changes: 2 additions & 1 deletion fuse_ops.h
Expand Up @@ -36,6 +36,7 @@

/* Forward decl's */
struct s3b_config;
struct s3backer_store;

/* Function types */
typedef void printer_t(void *prarg, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
Expand All @@ -58,5 +59,5 @@ struct fuse_ops_conf {
};

/* fuse_ops.c */
const struct fuse_operations *fuse_ops_create(struct fuse_ops_conf *config);
const struct fuse_operations *fuse_ops_create(struct fuse_ops_conf *config, struct s3backer_store *s3b);

14 changes: 12 additions & 2 deletions main.c
Expand Up @@ -47,6 +47,7 @@ int
main(int argc, char **argv)
{
const struct fuse_operations *fuse_ops;
struct s3backer_store *s3b;
struct s3b_config *config;

/* Get configuration */
Expand All @@ -67,8 +68,17 @@ main(int argc, char **argv)
return 0;
}

/* Get FUSE operation hooks */
fuse_ops = fuse_ops_create(&config->fuse_ops);
/* Create backing store */
if ((s3b = s3backer_create_store(config)) == NULL) {
(*config->log)(LOG_ERR, "error creating s3backer_store: %s", strerror(errno));
return 1;
}

/* Setup FUSE operation hooks */
if ((fuse_ops = fuse_ops_create(&config->fuse_ops, s3b)) == NULL) {
(*s3b->destroy)(s3b);
return 1;
}

/* Start */
(*config->log)(LOG_INFO, "s3backer process %lu for %s started", (u_long)getpid(), config->mount);
Expand Down
2 changes: 1 addition & 1 deletion s3b_config.c
Expand Up @@ -593,7 +593,7 @@ s3backer_get_config(int argc, char **argv)
}

/*
* Create the s3backer_store used at runtime. This method is invoked by fuse_op_init().
* Create the s3backer_store used at runtime.
*/
struct s3backer_store *
s3backer_create_store(struct s3b_config *conf)
Expand Down

0 comments on commit 0b0e908

Please sign in to comment.