[CRIU] [PATCH 2/4] files-reg: Rework strip_deleted helper
Cyrill Gorcunov
gorcunov at openvz.org
Mon Aug 17 13:09:47 PDT 2015
Make it handle both postfixes and return
non-zero code if stipping happened.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
files-reg.c | 34 ++++++++++++++++++++++++++--------
include/files-reg.h | 2 ++
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/files-reg.c b/files-reg.c
index 2812e7895bed..f3ba898f6dad 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -639,20 +639,38 @@ static inline bool nfs_silly_rename(char *rpath, const struct fd_parms *parms)
return (parms->fs_type == NFS_SUPER_MAGIC) && is_sillyrename_name(rpath);
}
-static void strip_deleted(struct fd_link *link)
+int strip_deleted(struct fd_link *link)
{
- const char postfix[] = " (deleted)";
- const size_t plen = strlen(postfix);
+ struct dcache_prepends {
+ const char *str;
+ size_t len;
+ } static const prepends[] = {
+ {
+ .str = " (deleted)",
+ .len = 10,
+ }, {
+ .str = "//deleted",
+ .len = 9,
+ }
+ };
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(prepends); i++) {
+ size_t at;
- if (link->len > plen) {
- size_t at = link->len - plen;
- if (!strcmp(&link->name[at], postfix)) {
+ if (link->len <= prepends[i].len)
+ continue;
+
+ at = link->len - prepends[i].len;
+ if (!strcmp(&link->name[at], prepends[i].str)) {
pr_debug("Stip %s' tag from '%s'\n",
- postfix, link->name);
+ prepends[i].str, link->name);
link->name[at] = '\0';
- link->len -= plen;
+ link->len -= prepends[i].len;
+ return 1;
}
}
+ return 0;
}
static int check_path_remap(struct fd_link *link, const struct fd_parms *parms,
diff --git a/include/files-reg.h b/include/files-reg.h
index 09cd90fe9b56..a9a8d4aae5a9 100644
--- a/include/files-reg.h
+++ b/include/files-reg.h
@@ -51,4 +51,6 @@ extern struct collect_image_info remap_cinfo;
extern void delete_link_remaps(void);
extern void free_link_remaps(void);
+extern int strip_deleted(struct fd_link *link);
+
#endif /* __CR_FILES_REG_H__ */
--
2.4.3
More information about the CRIU
mailing list