Domanda

Contesto: Ubuntu 11.10 e libfuse 2.8.4-1.4ubuntu1 Linux 3.0.0-14-Generic #23-Obuntu SMP lunedì 21 novembre 20:28:43 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

Sto cercando di usare libfuse. Voglio far uscire Fuse_session_loop (da un gestore di segnale o un thread diverso), ma quando chiamo fuse_session_exit non succede nulla fino a quando la sessione non riceve una nuova richiesta.

fuse_session_exit imposta un flag che viene letto da fuse_session_exited. Debug in fuse_session_loop sembra bloccare su fuse_chan_recv, quindi non controlla di nuovo fuse_session_exited fino alla parte superiore del ciclo ...

int fuse_session_loop(struct fuse_session *se)
{
    int res = 0;
    struct fuse_chan *ch = fuse_session_next_chan(se, NULL);
    size_t bufsize = fuse_chan_bufsize(ch);
    char *buf = (char *) malloc(bufsize);
    if (!buf) {
        fprintf(stderr, "fuse: failed to allocate read buffer\n");
        return -1;
    }

    while (!fuse_session_exited(se)) {
        struct fuse_chan *tmpch = ch;
        res = fuse_chan_recv(&tmpch, buf, bufsize); <--- BLOCKING
        if (res == -EINTR)
            continue;
        if (res <= 0)
            break;
        fuse_session_process(se, buf, res, tmpch);
    }

    free(buf);
    fuse_session_reset(se);
    return res < 0 ? -1 : 0;
}

fuse_chan_recv chiama fuse_kern_chan_receive che blocca il "leggi" syscall del dispositivo "/dev/fuse", quindi anche se il flag fuse_session_exited non è ancora impostato.

static int fuse_kern_chan_receive(struct fuse_chan **chp, char *buf,
                  size_t size)
{
    struct fuse_chan *ch = *chp;
    int err;
    ssize_t res;
    struct fuse_session *se = fuse_chan_session(ch);
    assert(se != NULL);

restart:
    res = read(fuse_chan_fd(ch), buf, size); <--- BLOCKING
    err = errno;

    if (fuse_session_exited(se))
        return 0;
    if (res == -1) {
        /* ENOENT means the operation was interrupted, it's safe
           to restart */
        if (err == ENOENT)
            goto restart;

        if (err == ENODEV) {
            fuse_session_exit(se);
            return 0;
        }
        /* Errors occuring during normal operation: EINTR (read
           interrupted), EAGAIN (nonblocking I/O), ENODEV (filesystem
           umounted) */
        if (err != EINTR && err != EAGAIN)
            perror("fuse: reading device");
        return -err;
    }
    if ((size_t) res < sizeof(struct fuse_in_header)) {
        fprintf(stderr, "short read on fuse device\n");
        return -EIO;
    }
    return res;
}

Questo problema sembra effettuare l'esempio Hello_ll.c fornito con libfuse e il mio programma. Mi fa pensare che forse esiste un meccanismo che non funzioni. Forse Fuse_session_exit dovrebbe anche fare qualcosa che interrompa la chiamata di lettura, che per qualche motivo non funziona sul mio sistema.

Qualche idea?

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top