[CRIU] [PATCH 3/5] locks: Fix breaking lease type after dump

Pavel Begunkov asml.silence at gmail.com
Mon Aug 14 01:27:07 MSK 2017


Type of breaking lease in /proc is always 'READ'. This
patch sets it to 'lease target type' using fcntl(F_GETLEASE)

task #39

Signed-off-by: Pavel Begunkov <asml.silence at gmail.com>
---
 criu/file-lock.c         | 24 ++++++++++++++++++++++++
 criu/files.c             |  3 +++
 criu/include/file-lock.h |  1 +
 3 files changed, 28 insertions(+)

diff --git a/criu/file-lock.c b/criu/file-lock.c
index 496eac74d..e13834f64 100644
--- a/criu/file-lock.c
+++ b/criu/file-lock.c
@@ -334,6 +334,30 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p)
 	return 0;
 }
 
+int correct_file_leases(struct pid *pid, int fd, int lfd)
+{
+	struct file_lock *fl;
+	int target_type;
+
+	list_for_each_entry(fl, &file_lock_list, list) {
+		if (fl->fl_owner != pid->real || fl->owners_fd != fd)
+			continue;
+
+		if (fl->fl_kind == FL_LEASE && fl->fl_ltype & LEASE_BREAKING) {
+			target_type = fcntl(lfd, F_GETLEASE);
+			if (target_type < 0) {
+				perror("Can't get lease type\n");
+				return -1;
+			}
+
+			fl->fl_ltype &= ~O_ACCMODE;
+			fl->fl_ltype |= target_type;
+			break;
+		}
+	}
+	return 0;
+}
+
 static int open_break_cb(int ns_root_fd, struct reg_file_info *rfi, void *arg)
 {
 	int fd, flags = *(int *)arg | O_NONBLOCK;
diff --git a/criu/files.c b/criu/files.c
index 2c3389e3f..2d70e1753 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -459,6 +459,9 @@ static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
 	if (note_file_lock(pid, fd, lfd, &p))
 		return -1;
 
+	if (correct_file_leases(pid, fd, lfd))
+		return -1;
+
 	p.fd_ctl = ctl; /* Some dump_opts require this to talk to parasite */
 
 	if (S_ISSOCK(p.stat.st_mode))
diff --git a/criu/include/file-lock.h b/criu/include/file-lock.h
index 7280e0b55..b83c9b944 100644
--- a/criu/include/file-lock.h
+++ b/criu/include/file-lock.h
@@ -68,6 +68,7 @@ extern struct collect_image_info file_locks_cinfo;
 
 struct pid;
 struct fd_parms;
+extern int correct_file_leases(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);
 
-- 
2.11.1



More information about the CRIU mailing list