Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
criu
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhul
criu
Commits
18000564
Commit
18000564
authored
Sep 02, 2014
by
Pavel Emelyanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
locks: Split lock-in-fd check in a helper
Signed-off-by:
Pavel Emelyanov
<
xemul@parallels.com
>
parent
3a6f57cb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
20 deletions
+33
-20
file-lock.c
file-lock.c
+33
-20
No files found.
file-lock.c
View file @
18000564
...
...
@@ -123,6 +123,35 @@ static inline bool lock_file_match(struct file_lock *fl, struct fd_parms *p)
makedev
(
fl
->
maj
,
fl
->
min
)
==
p
->
stat
.
st_dev
;
}
static
int
lock_check_fd
(
int
lfd
,
struct
file_lock
*
fl
)
{
int
ret
;
ret
=
flock
(
lfd
,
LOCK_EX
|
LOCK_NB
);
pr_debug
(
" `- %d/%d
\n
"
,
ret
,
errno
);
if
(
ret
!=
0
)
{
if
(
errno
!=
EAGAIN
)
{
pr_err
(
"Bogus lock test result %d
\n
"
,
ret
);
return
-
1
;
}
return
0
;
}
else
{
/*
* The ret == 0 means, that new lock doesn't conflict
* with any others on the file. But since we do know,
* that there should be some other one (file is found
* in /proc/locks), it means that the lock is already
* on file pointed by fd.
*/
pr_debug
(
" `- downgrading lock back
\n
"
);
if
(
fl
->
fl_ltype
==
F_RDLCK
)
flock
(
lfd
,
LOCK_SH
);
}
return
1
;
}
int
note_file_lock
(
struct
pid
*
pid
,
int
fd
,
int
lfd
,
struct
fd_parms
*
p
)
{
struct
file_lock
*
fl
;
...
...
@@ -153,27 +182,11 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p)
continue
;
pr_debug
(
"Checking lock holder %d:%d
\n
"
,
pid
->
real
,
fd
);
ret
=
flock
(
lfd
,
LOCK_EX
|
LOCK_NB
);
pr_debug
(
" `- %d/%d
\n
"
,
ret
,
errno
);
if
(
ret
!=
0
)
{
if
(
errno
!=
EAGAIN
)
{
pr_err
(
"Bogus lock test result %d
\n
"
,
ret
);
return
-
1
;
}
ret
=
lock_check_fd
(
lfd
,
fl
);
if
(
ret
<
0
)
return
ret
;
if
(
ret
==
0
)
continue
;
}
else
if
(
fl
->
fl_ltype
==
F_RDLCK
)
{
pr_debug
(
" `- downgrading lock back
\n
"
);
flock
(
lfd
,
LOCK_SH
);
}
/*
* The ret == 0 means, that new lock doesn't conflict
* with any others on the file. But since we do know,
* that there should be some other one (file is found
* in /proc/locks), it means that the lock is already
* on file pointed by fd.
*/
}
fl
->
real_owner
=
pid
->
virt
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment