[PATCH 4/7] files-reg: Add a few helpers to access ghost files remaps from inotify

Cyrill Gorcunov gorcunov at openvz.org
Fri Nov 30 10:00:52 EST 2012


The remap_put will be needed to defer unlinking of ghost files
if they are referred from inotify system.

The lookup_remap is needed to figure out if the watch
target the inotify has present in ghost files list.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 files-reg.c         | 27 +++++++++++++++++++++++++++
 include/files-reg.h |  3 +++
 2 files changed, 30 insertions(+)

diff --git a/files-reg.c b/files-reg.c
index 5acc823..d498571 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -220,6 +220,33 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st)
 	return 0;
 }
 
+void remap_put(struct file_remap *remap)
+{
+	mutex_lock(ghost_file_mutex);
+	if (--remap->users == 0) {
+		pr_info("Unlink the ghost %s\n", remap->path);
+		unlink(remap->path);
+	}
+	mutex_unlock(ghost_file_mutex);
+}
+
+struct file_remap *lookup_remap(u32 dev, u32 ino)
+{
+	struct ghost_file *gf;
+
+	mutex_lock(ghost_file_mutex);
+	list_for_each_entry(gf, &ghost_files, list) {
+		if (gf->dev == dev && gf->ino == ino) {
+			gf->remap.users++;
+			mutex_unlock(ghost_file_mutex);
+			return &gf->remap;
+		}
+	}
+	mutex_unlock(ghost_file_mutex);
+
+	return NULL;
+}
+
 static int dump_ghost_remap(char *path, const struct stat *st, int lfd, u32 id)
 {
 	struct ghost_file *gf;
diff --git a/include/files-reg.h b/include/files-reg.h
index e81e181..77eca6c 100644
--- a/include/files-reg.h
+++ b/include/files-reg.h
@@ -51,4 +51,7 @@ extern int prepare_shared_reg_files(void);
 extern int dump_reg_file(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset);
 extern int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p);
 
+extern struct file_remap *lookup_remap(u32 dev, u32 ino);
+extern void remap_put(struct file_remap *remap);
+
 #endif /* FILES_REG_H__ */
-- 
1.8.0.1


--qFgkTsE6LiHkLPZw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="0006-inotify-Use-ghost-files-if-the-watchee-is-a-deleted-.patch"



More information about the CRIU mailing list