All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Kirch <okir@suse.de>
To: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: nfs@lists.sourceforge.net, akpm@osdl.org
Subject: Re: [PATCH fs/locks 2 of 3] Use proper tgid in locks_remove_posix
Date: Mon, 11 Jul 2005 16:23:13 +0200	[thread overview]
Message-ID: <20050711142313.GA25020@suse.de> (raw)
In-Reply-To: <1121089937.13326.41.camel@lade.trondhjem.org>

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

On Mon, Jul 11, 2005 at 09:52:17AM -0400, Trond Myklebust wrote:
> In the case of NLM, we use the function nlm_find_lockowner() to create a
> mapping between fl_owner and a 32-bit numerical value which we call
> "pid", but which is really just a unique number. This mapping is
> preserved at least for the lifetime of the lock, and is shared between
> all locks that reference the same fl_owner.
> The "pid" of this mapping is the number that is seen by the server.

Alright. I stand corrected.

I originally reproduced this problem on SLES (ie 2.6.5), where the
lockowner stuff didn't exist yet. I then retested on 2.6.12, and found
the same problem - but didn't notice the mechanism is entirely different.
So whatever I'm seeing on 2.6.12 is different from what I saw on 2.6.5.

I'll do some more testing - in case anyone else would like to do so, too,
the test app is attached.

Olaf
-- 
Olaf Kirch   |  --- o --- Nous sommes du soleil we love when we play
okir@suse.de |    / | \   sol.dhoop.naytheet.ah kin.ir.samse.qurax

[-- Attachment #2: two-thread-unlock.c --]
[-- Type: text/plain, Size: 1414 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <fcntl.h>
#include <pthread.h>
#include <string.h>

int	fd;
int	running = 1;
int	locked = 0;

int
get_lock (int fd)
{
	struct flock    lock_it;
	int		res = 0;

	lock_it.l_type = F_WRLCK;
	lock_it.l_whence = SEEK_SET;
	lock_it.l_start = 0;
	lock_it.l_len = 0;

	if (fcntl (fd, F_SETLK, &lock_it) < 0) {
		perror ("fcntl(F_WRLCK)");
		res = -1;
	}

	return res;
}


void *
do_lock(void *arg)
{
	if (get_lock(fd) >= 0) {
		printf("Locked file\n");
		sleep(1);
		locked = 1;
	}

	while (running)
		sleep(1);
	return NULL;
}

void *
do_close(void *arg)
{
	int i;

	for (i = 0; !locked && i < 10; ++i)
		sleep(1);
	if (locked)
		close(fd);
	else
		printf("Never obtained the lock\n");
	running = 0;
	return NULL;
}

int
main(int argc, char** argv)
{
#define THREADS 1

	pthread_t	locker_thread;
	pthread_t	close_thread;

	if (argc != 2) {
		fprintf(stderr, "%s <path>\n", argv[0]);
		exit(-1);
	}

	if ((fd = open (argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
		perror ("open");
		return 1;
	}

	pthread_create(&locker_thread, NULL, do_lock, NULL);
	pthread_create(&close_thread, NULL, do_close, NULL);
	sleep(2);

	running = 0;
	pthread_join(locker_thread, NULL);
	pthread_join(close_thread, NULL);

	return 0;
}

  reply	other threads:[~2005-07-11 14:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-11 10:32 [PATCH fs/locks 2 of 3] Use proper tgid in locks_remove_posix Olaf Kirch
2005-07-11 12:16 ` Trond Myklebust
2005-07-11 12:48   ` Olaf Kirch
2005-07-11 13:02     ` Trond Myklebust
2005-07-11 13:16       ` Olaf Kirch
2005-07-11 13:33         ` Peter Staubach
2005-07-11 13:52         ` Trond Myklebust
2005-07-11 14:23           ` Olaf Kirch [this message]
2005-07-16 15:15 ` Olaf Hering
2005-07-17 16:42   ` Olaf Kirch

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=20050711142313.GA25020@suse.de \
    --to=okir@suse.de \
    --cc=akpm@osdl.org \
    --cc=nfs@lists.sourceforge.net \
    --cc=trond.myklebust@fys.uio.no \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.