Project

General

Profile

Actions

Bug #2679

closed

POSIX file lock not released on process termination

Added by Daniel Godas-Lopez almost 12 years ago. Updated about 10 years ago.

Status:
Can't reproduce
Priority:
High
Assignee:
-
Category:
-
Target version:
-
% Done:

0%

Source:
Community (user)
Tags:
Backport:
Regression:
Severity:
Reviewed:
Affected Versions:
ceph-qa-suite:
Component(FS):
Labels (FS):
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

I obtained a POSIX file lock with the following code:

--- snip ---

...
std::string x = "/tmp/ceph_mount/lock_file";
std::ofstream lock_file(x);
lock_file.close();

// Lock automatically released by the OS when the process dies

if (Sync::get_file_lock(x) == -1) {
return false;
}

...

--- snip ---

The code should create the file if it doesnt exist or just open it and
close it if it does. Then the lock is taken. This is the code for
get_file_lock:

---snip---

static int get_file_lock(const std::string& path,
bool block = false,
bool exclusive = true) {
int fd, flags;

if ((fd = open(path.c_str(), O_RDONLY)) == -1)
throw LockingException(path);

flags = (exclusive ? LOCK_EX : LOCK_SH);
flags |= (block ? 0 : LOCK_NB);

if (flock(fd, flags) == 0)
return fd;

close(fd);
return -1;
}

---snip---

I never release the lock but I expect the operating system (and ceph)
to release it when the process terminates as this is normal POSIX
behaviour. The observed behaviour is that the lock never gets released
and after the process dies I can do the following:

---snip---

dev proc # cat locks
1: POSIX ADVISORY WRITE 4425 07:00:132 0 EOF
2: FLOCK ADVISORY WRITE 2906 fd:02:783456 0 EOF

---snip---

The lock taken by the process is the second one and the PID is correct
(it's the PID of the process that obtained the lock). However the process
doesn't exist any more, which I can verify with ps.

fcntl locks work as expected, the following code proves it:

--- snip ---

struct flock s;

s.l_type = (exclusive ? F_WRLCK : F_RDLCK);
s.l_whence = SEEK_SET;
s.l_start = 0;
s.l_len = 0;
s.l_pid = getpid();

if (block) {
if (fcntl(fd, F_SETLKW, &s) != -1)
return fd;
} else {
if (fcntl(fd, F_SETLK, &s) != -1)
return fd;
}

--- snip ---

Actions #1

Updated by Sage Weil over 11 years ago

  • Project changed from Linux kernel client to CephFS
  • Category deleted (fs/ceph)
Actions #2

Updated by Greg Farnum about 10 years ago

  • Priority changed from Normal to High

Let's see if we can reproduce this as it's some combination of kclient, MDS, or protocol bug.

Actions #3

Updated by Zheng Yan about 10 years ago

  • Status changed from New to Can't reproduce
Actions

Also available in: Atom PDF