The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andy Tai <lichengtai@yahoo.com>
To: linux-kernel@vger.kernel.org
Cc: atai@atai.org
Subject: file locking (fcntl) bug in 2.4.19
Date: Thu, 29 Aug 2002 20:52:36 -0700 (PDT)	[thread overview]
Message-ID: <20020830035236.44060.qmail@web10501.mail.yahoo.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]

Hi, there is a bug on file locking (via fcntl) on
linux kernel 2.4.19 when locking files in a NFS
volume.

Try to mount a remote NFS server on a directory in a
machine running Linux 2.4.19 as follows:

mount -o nfsvers=3,intr <remote NFS server path> /mnt

Then run the attached program which demonstrates the
bug:

lockbug /mnt/xx

and it keeps showing the error 

lock failed with error: No locks available

The file has not been locked so there must be locks
available.  The error message is wrong.

Trying this on a file in a local drive does not show
the error.

The attached program basically forks a child and in
the child it tries to lock a file descriptor that was
opened in the parent.

Thanks for any help on working around this bug.

__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

[-- Attachment #2: lockbug.c --]
[-- Type: application/octet-stream, Size: 2161 bytes --]

/* code is derived from Samba
   Copyright (C) Andrew Tridgell 1992-1998
   Copyright (C) Jeremy Allison 2001
   Copyright (C) Simo Sorce 2001


   modification herein Copyright 2002 Li-Cheng Tai
   This code is covered by the GNU General Public License, version 2 or later */
   
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/wait.h>
/*******************************************************************
A fcntl wrapper that will deal with EINTR.
********************************************************************/

int sys_fcntl_ptr(int fd, int cmd, void *arg)
{
    int ret;

    do {
            ret = fcntl(fd, cmd, arg);
    } while (ret == -1 && errno == EINTR);
    return ret;
}

int fcntl_lock(int f, uint64_t offset, uint64_t count)
{
    struct flock lock;
    int ret;
    
    lock.l_type = F_WRLCK;
    lock.l_whence = SEEK_SET;
    lock.l_start = offset;
    lock.l_len = count;
    lock.l_pid = 0;

    ret = sys_fcntl_ptr(f,F_SETLK,&lock);
    if (ret == -1)
    {
        fprintf(stderr, "lock failed with error: %s\n", strerror(errno));
        exit(1);
    }
    else
    {
        lock.l_type = F_UNLCK;
        lock.l_whence = SEEK_SET;
        lock.l_start = offset;
        lock.l_len = count;
        lock.l_pid = 0;
        ret = sys_fcntl_ptr(f,F_SETLK,&lock);
        if (ret == -1)
        {
            fprintf(stderr, "unlock failed with error: %s\n", strerror(errno));
            exit(1);
        }
    }
    return 1;
}

int main(int argc, char *argv[])
{
    int f, i, status;
    
    
    if (argc != 2)
    {
        fprintf(stderr, "Usage: %s file_name \n", argv[0]);
    }
    f = open(argv[1], O_CREAT | O_RDWR);
    if (!f)
    {
        fprintf(stderr, "unlock failed with error: %s\n", strerror(errno));
        exit(1);
    }
    while (1)
    {
        i = fork();
        if (i > 0)
        {
            sleep(2);
            wait(&status);
            continue;
        }
        else
        {
            fcntl_lock(f, 2147483539L, 1);
            exit(0);
        }
    }
    close(f);
    return 0;
}

             reply	other threads:[~2002-08-30  3:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-30  3:52 Andy Tai [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-08-30 12:25 file locking (fcntl) bug in 2.4.19 Matthew Wilcox
2002-08-30 20:50 ` Andy Tai
2002-08-31  4:13   ` Andy Tai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020830035236.44060.qmail@web10501.mail.yahoo.com \
    --to=lichengtai@yahoo.com \
    --cc=atai@atai.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox