[CRIU] [PATCH 1/1] locks: remove duplicated locks
asml.silence at gmail.com
asml.silence at gmail.com
Sat Oct 21 17:15:29 MSK 2017
From: Pavel Begunkov <asml.silence at gmail.com>
CRIU creates dictinct lock record for each file descriptor associated
with the same OFD. This patch removes such excess records. Also it
purges crutches doing the same stuff but only for file leases.
Signed-off-by: Pavel Begunkov <asml.silence at gmail.com>
---
criu/file-lock.c | 16 +++++++++++++---
criu/files.c | 2 ++
criu/include/file-lock.h | 3 +--
criu/proc_parse.c | 2 --
4 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/criu/file-lock.c b/criu/file-lock.c
index b7adc097..65150453 100644
--- a/criu/file-lock.c
+++ b/criu/file-lock.c
@@ -106,8 +106,6 @@ int dump_file_locks(void)
continue;
}
- if (fl->fl_kind == FL_LEASE && !fl->updated)
- continue;
file_lock_entry__init(&fle);
fle.pid = fl->real_owner;
@@ -421,6 +419,19 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p)
return 0;
}
+void discard_dup_locks_tail(pid_t pid, int fd)
+{
+ while (!list_empty(&file_lock_list)) {
+ struct file_lock *fl = container_of(file_lock_list.prev, struct file_lock, list);
+
+ if (fl->owners_fd != fd || pid != fl->fl_owner)
+ break;
+
+ list_del(&fl->list);
+ xfree(fl);
+ }
+}
+
int correct_file_leases_type(struct pid *pid, int fd, int lfd)
{
struct file_lock *fl;
@@ -431,7 +442,6 @@ int correct_file_leases_type(struct pid *pid, int fd, int lfd)
if (fl->fl_owner != pid->real || fl->owners_fd != fd)
continue;
- fl->updated = true;
if (fl->fl_kind == FL_LEASE &&
(fl->fl_ltype & LEASE_BREAKING)) {
/*
diff --git a/criu/files.c b/criu/files.c
index 30ecb4bb..977d65cb 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -321,6 +321,8 @@ int do_dump_gen_file(struct fd_parms *p, int lfd,
ret = fd_id_generate(p->pid, e, p);
if (ret == 1) /* new ID generated */
ret = ops->dump(lfd, e->id, p);
+ else if (S_ISREG(p->stat.st_mode))
+ discard_dup_locks_tail(p->pid, e->fd);
return ret;
}
diff --git a/criu/include/file-lock.h b/criu/include/file-lock.h
index 14a33b43..7f1d9d4b 100644
--- a/criu/include/file-lock.h
+++ b/criu/include/file-lock.h
@@ -56,8 +56,6 @@ struct file_lock {
int real_owner;
int owners_fd;
-
- bool updated; /* used to remove duplicate leases */
};
extern struct list_head file_lock_list;
@@ -70,6 +68,7 @@ extern struct collect_image_info file_locks_cinfo;
struct pid;
struct fd_parms;
+extern void discard_dup_locks_tail(pid_t pid, int fd);
extern int correct_file_leases_type(struct pid *, int fd, int lfd);
extern int note_file_lock(struct pid *, int fd, int lfd, struct fd_parms *);
extern int dump_file_locks(void);
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index a4d6998d..a175e067 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -2073,8 +2073,6 @@ static int parse_file_lock_buf(char *buf, struct file_lock *fl,
return -1;
}
- fl->updated = false;
-
if (!strcmp(fl_flag, "POSIX"))
fl->fl_kind = FL_POSIX;
else if (!strcmp(fl_flag, "FLOCK"))
--
2.14.1.473.g3ec7d702a8
More information about the CRIU
mailing list