lkml.org 
[lkml]   [2000]   [Aug]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [FIX] Make deadlock detection work for file locking
    Date
    From
    Hi,

    Christian Ehrhardt <ehrhardt@mathematik.uni-ulm.de> writes:
    >
    > Mostly curious: What kind of problems did you have with deadlock
    > detection? AFAICS your patch looks ok, but deadlock detections seems
    > to be functionally equivilent with or without the patch.

    Well, actually the following program just hangs on 2.4.0-test7pre4
    and reports EDEADLOCK after the patch is applied.

    Cheers,
    Stephen
    --
    Stephen Rothwell, Open Source Researcher, Linuxcare, Inc.
    +61-2-62628990 tel, +61-2-62628991 fax
    sfr@linuxcare.com, http://www.linuxcare.com/
    Linuxcare. Support for the revolution.

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <fcntl.h>

    int main(int argc, char **argv)
    {
    struct flock fl;
    int fd;
    unsigned char c;
    int pipe_fd[2];

    if (pipe(pipe_fd) == -1) {
    perror("pipe");
    return 1;
    }
    switch (fork()) {
    case -1:
    perror("fork");
    return 1;
    case 0:
    if (read(pipe_fd[0], &c, 1) == -1) {
    perror("read pipe child");
    return 1;
    }
    fd = open("deadlock.testfile", O_RDWR);
    if (fd == -1) {
    perror("open child");
    return 1;
    }
    fl.l_type = F_WRLCK;
    fl.l_whence = 0;
    fl.l_start = 20;
    fl.l_len = 10;
    if (fcntl(fd, F_SETLK, &fl) == -1) {
    perror("fcntl child 1");
    return 1;
    }
    fl.l_type = F_WRLCK;
    fl.l_whence = 0;
    fl.l_start = 10;
    fl.l_len = 10;
    if (fcntl(fd, F_SETLKW, &fl) == -1) {
    perror("fcntl child 2");
    return 1;
    }
    break;
    default:
    fd = open("deadlock.testfile", O_RDWR|O_CREAT, 0600);
    if (fd == -1) {
    perror("open parent 1");
    return 1;
    }
    fl.l_type = F_WRLCK;
    fl.l_whence = 0;
    fl.l_start = 10;
    fl.l_len = 10;
    if (fcntl(fd, F_SETLK, &fl) == -1) {
    perror("fcntl parent 1");
    return 1;
    }
    if (write(pipe_fd[1], "x", 1) == -1) {
    perror("write pipe parent 1");
    return 1;
    }
    sleep(5);
    fl.l_type = F_WRLCK;
    fl.l_whence = 0;
    fl.l_start = 20;
    fl.l_len = 10;
    if (fcntl(fd, F_SETLKW, &fl) == -1) {
    perror("fcntl parent 2");
    return 1;
    }
    break;
    }
    return 0;
    }
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 12:37    [W:0.029 / U:61.792 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site