[CRIU] Re: [PATCH] reg-files: Serialize linking of ghost files
Cyrill Gorcunov
gorcunov at openvz.org
Mon Sep 17 06:47:14 EDT 2012
On Mon, Sep 17, 2012 at 02:31:18PM +0400, Cyrill Gorcunov wrote:
> On Mon, Sep 17, 2012 at 02:26:47PM +0400, Pavel Emelyanov wrote:
> > On 09/17/2012 12:50 PM, Cyrill Gorcunov wrote:
> > > In case if there at least two tasks with same ghost
> > > file we've a race in open_path -- both task may enter
> > > the open_path at same time and try to link ghost file
> > > to same name leading to
> > >
> > > | 26445: Error (files-reg.c:363): Can't link
> > > | /home/crtools/test/zdtm/live/static/write_read10.test (deleted).cr.1.ghost ->
> > > | /home/crtools/test/zdtm/live/static/write_read10.test (deleted)
> > >
> > > The both tasks have ghost files as
> > >
> > > | id: 0x3 flags: 0x8002 pos: 0000000000000000 ... name: "/home/crtools/test/zdtm/live/static/write_read10.test (deleted)"
> > >
> > > and
> > >
> > > | id: 0x10 flags: 0x8002 pos: 0000000000000000 ... name: "/home/crtools/test/zdtm/live/static/write_read10.test (deleted)"
> > >
> > > Thus, to serialize link/unlink procedure we use per-ghost-file mutex.
> >
> > In that case users can be just unsigned int
>
> Yes, but I didn't want to squash everything in one patch. I'll do that on top.
Here is one on top.
-------------- next part --------------
>From 795c64b4d9f556ee46676dc51289dd2c8d034e28 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Mon, 17 Sep 2012 14:44:47 +0400
Subject: [PATCH] files-reg: Change @users to int
No need for atomic_t here since we're under mutex anyway.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
files-reg.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/files-reg.c b/files-reg.c
index 3620d23..33147a3 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -37,7 +37,7 @@ struct ghost_file {
char *path;
};
};
- atomic_t users;
+ unsigned int users;
mutex_t lock;
};
@@ -115,11 +115,11 @@ static int open_remap_ghost(struct reg_file_info *rfi,
close(gfd);
gf->id = rfe->remap_id;
- atomic_set(&gf->users, 0);
+ gf->users = 0;
mutex_init(&gf->lock);
list_add_tail(&gf->list, &ghost_files);
gf_found:
- atomic_inc(&gf->users);
+ gf->users++;
rfi->ghost = gf;
return 0;
@@ -370,7 +370,8 @@ static int open_path(struct file_desc *d,
if (rfi->ghost) {
unlink(rfi->path);
- if (atomic_dec_and_test(&rfi->ghost->users)) {
+ BUG_ON(!rfi->ghost->users);
+ if (rfi->ghost->users-- == 1) {
pr_info("Unlink the ghost %s\n", rfi->ghost->path);
unlink(rfi->ghost->path);
}
--
1.7.7.6
More information about the CRIU
mailing list