terom@28: terom@28: #include terom@28: terom@29: #include "dbfs.h" terom@28: #include "../dbfs.h" terom@29: #include "../lib/log.h" terom@28: terom@28: static struct fuse_lowlevel_ops dbfs_llops = { terom@28: terom@28: .init = dbfs_init, terom@28: .destroy = dbfs_destroy, terom@28: terom@28: .lookup = dbfs_lookup, terom@32: // .forget terom@28: .getattr = dbfs_getattr, terom@31: .setattr = dbfs_setattr, terom@32: .readlink = dbfs_readlink, terom@35: .mknod = dbfs_mknod, terom@35: .mkdir = dbfs_mkdir, terom@35: terom@33: .symlink = dbfs_symlink, terom@34: .rename = dbfs_rename, terom@33: terom@30: .open = dbfs_open, terom@30: .read = dbfs_read, terom@31: .write = dbfs_write, terom@30: .flush = dbfs_flush, terom@30: .release = dbfs_release, terom@30: terom@28: .opendir = dbfs_opendir, terom@28: .readdir = dbfs_readdir, terom@28: .releasedir = dbfs_releasedir, terom@28: }; terom@28: terom@28: void dbfs_init (void *userdata, struct fuse_conn_info *conn) { terom@28: INFO("[dbfs.init] userdata=%p, conn=%p", userdata, conn); terom@28: terom@28: } terom@28: terom@28: void dbfs_destroy (void *arg) { terom@28: struct dbfs *ctx = arg; terom@28: INFO("[dbfs.destroy %p]", ctx); terom@28: terom@28: // exit libevent terom@28: event_base_loopexit(ctx->ev_base, NULL); terom@28: } terom@28: terom@28: terom@28: void dbfs_sql_error (struct evsql *evsql, void *arg) { terom@28: struct dbfs *ctx = arg; terom@28: terom@28: // AAAAAAAAAA.... panic terom@28: WARNING("[dbfs] SQL error: BREAKING MAIN LOOP LIEK NAO"); terom@28: terom@28: event_base_loopbreak(ctx->ev_base); terom@28: } terom@28: terom@30: struct dbfs *dbfs_new (struct event_base *ev_base, struct fuse_args *args, const char *db_conninfo) { terom@28: struct dbfs *ctx = NULL; terom@28: terom@28: // alloc ctx terom@28: if ((ctx = calloc(1, sizeof(*ctx))) == NULL) terom@28: ERROR("calloc"); terom@28: terom@28: ctx->ev_base = ev_base; terom@28: ctx->db_conninfo = db_conninfo; terom@28: terom@28: // open sql terom@28: if ((ctx->db = evsql_new_pq(ctx->ev_base, ctx->db_conninfo, dbfs_sql_error, ctx)) == NULL) terom@28: ERROR("evsql_new_pq"); terom@28: terom@28: // open fuse terom@28: if ((ctx->ev_fuse = evfuse_new(ctx->ev_base, args, &dbfs_llops, ctx)) == NULL) terom@28: ERROR("evfuse_new"); terom@28: terom@28: // success terom@28: return ctx; terom@28: terom@28: error: terom@28: if (ctx) terom@30: dbfs_free(ctx); terom@28: terom@28: return NULL; terom@28: } terom@28: terom@30: void dbfs_free (struct dbfs *ctx) { terom@28: // cleanup terom@28: if (ctx->ev_fuse) { terom@28: evfuse_free(ctx->ev_fuse); terom@28: terom@28: ctx->ev_fuse = NULL; terom@28: } terom@28: terom@28: if (ctx->db) { terom@28: // XXX: not yet implemented terom@28: // evsql_close(ctx->db); terom@28: // ctx->db = NULL; terom@28: } terom@28: terom@28: free(ctx); terom@28: }