src/dbfs/interrupt.c
author Tero Marttila <terom@fixme.fi>
Tue, 18 Nov 2008 02:06:52 +0200
changeset 42 40a3b13ffc9d
parent 41 6abda2fa4579
child 44 9e76ee9729b6
permissions -rw-r--r--
defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
41
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#include "dbfs.h"
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
42
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
     4
void _dbfs_interrupt_reply (evutil_socket_t _unused1, short _unused2, void *req_ptr) {
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
     5
    struct fuse_req *req = req_ptr;
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
     6
    err_t err;
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
     7
    
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
     8
    // error the req
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
     9
    if ((err = -fuse_reply_err(req, EINTR)))
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    10
        EWARNING(err, "fuse_reply_err");
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    11
}
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    12
41
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
void dbfs_interrupt_query (struct fuse_req *req, void *query_ptr) {
42
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    14
    struct dbfs *ctx = fuse_req_userdata(req);
41
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
    struct evsql_query *query = query_ptr;
42
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    16
    struct timeval tv;
41
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
    err_t err;
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
42
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    19
    // abort query
41
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
    evsql_query_abort(NULL, query);
42
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    21
    
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    22
    /*
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    23
     * Due to a locking bug in libfuse (at least 2.7.4), we can't call fuse_reply_err from the interrupt function, so we must
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    24
     * schedule after this function returns.
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    25
     */
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    26
    tv.tv_sec = 0;
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    27
    tv.tv_usec = 0;
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    28
    if (event_base_once(ctx->ev_base, -1, EV_TIMEOUT, _dbfs_interrupt_reply, req, &tv))
40a3b13ffc9d defer fuse_reply_err using event_base_once, interrupt happens without deadlock now
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    29
        PWARNING("event_base_once failed, dropping req reply: %p", req);
41
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
}
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
void _dbfs_interrupt_ctx (struct fuse_req *req, void *ctx_ptr) {
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
    // dereference ctx
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
    struct dbfs_interrupt_ctx *ctx = ctx_ptr;
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
    
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
    // just cancel query if pending
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
    if (ctx->query) {
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
        evsql_query_abort(NULL, ctx->query);
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
        ctx->query = NULL;
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
    }
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
    // mark as interrupted
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
    ctx->interrupted = 1;
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
}
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
int dbfs_interrupt_register (struct fuse_req *req, struct dbfs_interrupt_ctx *ctx) {
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
    // initialize
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
    ctx->query = NULL;
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
    ctx->interrupted = 0;
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
    // just pass over to fuse_req_interrupt_func
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
    fuse_req_interrupt_func(req, _dbfs_interrupt_ctx, ctx);
6abda2fa4579 touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
}