Commit 883126a4 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

inotify: Use embedded structures as a reference

We need it for protobuf transition.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 5f303989
...@@ -36,12 +36,12 @@ ...@@ -36,12 +36,12 @@
struct inotify_wd_info { struct inotify_wd_info {
struct list_head list; struct list_head list;
struct inotify_wd_entry iwe; struct inotify_wd_entry *iwe;
}; };
struct inotify_file_info { struct inotify_file_info {
struct list_head list; struct list_head list;
struct inotify_file_entry ife; struct inotify_file_entry *ife;
struct list_head marks; struct list_head marks;
struct file_desc d; struct file_desc d;
}; };
...@@ -284,21 +284,21 @@ static int open_inotify_fd(struct file_desc *d) ...@@ -284,21 +284,21 @@ static int open_inotify_fd(struct file_desc *d)
info = container_of(d, struct inotify_file_info, d); info = container_of(d, struct inotify_file_info, d);
tmp = inotify_init1(info->ife.flags); tmp = inotify_init1(info->ife->flags);
if (tmp < 0) { if (tmp < 0) {
pr_perror("Can't create inotify for 0x%08x", info->ife.id); pr_perror("Can't create inotify for 0x%08x", info->ife->id);
return -1; return -1;
} }
list_for_each_entry(wd_info, &info->marks, list) { list_for_each_entry(wd_info, &info->marks, list) {
pr_info("\tRestore inotify for 0x%08x\n", wd_info->iwe.id); pr_info("\tRestore inotify for 0x%08x\n", wd_info->iwe->id);
if (restore_one_inotify(tmp, &wd_info->iwe)) { if (restore_one_inotify(tmp, wd_info->iwe)) {
close_safe(&tmp); close_safe(&tmp);
break; break;
} }
} }
if (restore_fown(tmp, &info->ife.fown)) if (restore_fown(tmp, &info->ife->fown))
close_safe(&tmp); close_safe(&tmp);
return tmp; return tmp;
...@@ -314,7 +314,7 @@ static int collect_mark(struct inotify_wd_info *mark) ...@@ -314,7 +314,7 @@ static int collect_mark(struct inotify_wd_info *mark)
struct inotify_file_info *p; struct inotify_file_info *p;
list_for_each_entry(p, &info_head, list) { list_for_each_entry(p, &info_head, list) {
if (p->ife.id == mark->iwe.id) { if (p->ife->id == mark->iwe->id) {
list_add(&mark->list, &p->marks); list_add(&mark->list, &p->marks);
return 0; return 0;
} }
...@@ -334,25 +334,28 @@ int collect_inotify(void) ...@@ -334,25 +334,28 @@ int collect_inotify(void)
return -1; return -1;
while (1) { while (1) {
struct inotify_file_entry ife; info = xmalloc(sizeof(*info));
if (!info)
return -1;
ret = read_img_eof(image_fd, &ife); info->ife = xmalloc(sizeof(*info->ife));
if (!info->ife)
return -1;
ret = read_img_eof(image_fd, info->ife);
if (ret < 0) if (ret < 0)
goto err; goto err;
else if (!ret) else if (!ret)
break; break;
info = xmalloc(sizeof(*info));
if (!info)
return -1;
info->ife = ife;
INIT_LIST_HEAD(&info->list); INIT_LIST_HEAD(&info->list);
INIT_LIST_HEAD(&info->marks); INIT_LIST_HEAD(&info->marks);
list_add(&info->list, &info_head); list_add(&info->list, &info_head);
} }
ret = -1;
image_wd = open_image_ro(CR_FD_INOTIFY_WD); image_wd = open_image_ro(CR_FD_INOTIFY_WD);
if (image_wd < 0) if (image_wd < 0)
goto err; goto err;
...@@ -361,7 +364,11 @@ int collect_inotify(void) ...@@ -361,7 +364,11 @@ int collect_inotify(void)
mark = xmalloc(sizeof(*mark)); mark = xmalloc(sizeof(*mark));
if (!mark) if (!mark)
goto err; goto err;
ret = read_img_eof(image_wd, &mark->iwe); mark->iwe = xmalloc(sizeof(*mark->iwe));
if (!mark->iwe)
goto err;
ret = read_img_eof(image_wd, mark->iwe);
if (ret < 0) if (ret < 0)
goto err; goto err;
else if (!ret) else if (!ret)
...@@ -369,14 +376,14 @@ int collect_inotify(void) ...@@ -369,14 +376,14 @@ int collect_inotify(void)
if (collect_mark(mark)) { if (collect_mark(mark)) {
ret = -1; ret = -1;
pr_err("Can't find inotify with id 0x%08x\n", mark->iwe.id); pr_err("Can't find inotify with id 0x%08x\n", mark->iwe->id);
goto err; goto err;
} }
} }
list_for_each_entry(info, &info_head, list) { list_for_each_entry(info, &info_head, list) {
pr_info("Collected inotify: id 0x%08x flags 0x%08x\n", info->ife.id, info->ife.flags); pr_info("Collected inotify: id 0x%08x flags 0x%08x\n", info->ife->id, info->ife->flags);
file_desc_add(&info->d, info->ife.id, &desc_ops); file_desc_add(&info->d, info->ife->id, &desc_ops);
} }
ret = 0; ret = 0;
err: err:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment