[CRIU] [PATCH] bfd: Don't flush read-only images
Pavel Emelyanov
xemul at parallels.com
Wed Oct 29 04:44:03 PDT 2014
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
bfd.c | 11 +++--------
image.c | 2 +-
include/bfd.h | 3 ++-
proc_parse.c | 6 +++---
4 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/bfd.c b/bfd.c
index 04f5789..0f8aedc 100644
--- a/bfd.c
+++ b/bfd.c
@@ -86,13 +86,14 @@ static void buf_put(struct xbuf *xb)
xb->data = NULL;
}
-int bfdopen(struct bfd *f)
+int bfdopen(struct bfd *f, int mode)
{
if (buf_get(&f->b)) {
close(f->fd);
return -1;
}
+ f->mode = mode;
return 0;
}
@@ -107,13 +108,7 @@ int bfd_flush_images(void)
void bclose(struct bfd *f)
{
if (bfd_buffered(f)) {
- /*
- * FIXME -- when we bread from images we don't
- * need to flush. This call doesn't fail simply
- * becase we read _all_ data from them and the
- * b->sz would be 0 by the time we close them.
- */
- if (bflush(f) < 0) {
+ if ((f->mode != O_RDONLY) && bflush(f) < 0) {
/*
* This is to propagate error up. It's
* hardly possible by returning and
diff --git a/image.c b/image.c
index f0cf3e4..36f726d 100644
--- a/image.c
+++ b/image.c
@@ -235,7 +235,7 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...)
img->_x.fd = ret;
if (oflags & O_NOBUF)
bfd_setraw(&img->_x);
- else if (bfdopen(&img->_x))
+ else if (bfdopen(&img->_x, flags))
goto err;
if (imgset_template[type].magic == RAW_IMAGE_MAGIC)
diff --git a/include/bfd.h b/include/bfd.h
index 55e2e9d..cd2f4ad 100644
--- a/include/bfd.h
+++ b/include/bfd.h
@@ -13,6 +13,7 @@ struct xbuf {
struct bfd {
int fd;
+ int mode;
struct xbuf b;
};
@@ -26,7 +27,7 @@ static inline void bfd_setraw(struct bfd *b)
b->b.mem = NULL;
}
-int bfdopen(struct bfd *f);
+int bfdopen(struct bfd *f, int mode);
void bclose(struct bfd *f);
char *breadline(struct bfd *f);
int bwrite(struct bfd *f, const void *buf, int sz);
diff --git a/proc_parse.c b/proc_parse.c
index 0e7838f..bd7c5ff 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -313,7 +313,7 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_file
if (f.fd < 0)
goto err_n;
- if (bfdopen(&f))
+ if (bfdopen(&f, O_RDONLY))
goto err_n;
if (use_map_files) {
@@ -1158,7 +1158,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
return -1;
}
- if (bfdopen(&f))
+ if (bfdopen(&f, O_RDONLY))
return -1;
while (1) {
@@ -1613,7 +1613,7 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
return -1;
}
- if (bfdopen(&f))
+ if (bfdopen(&f, O_RDONLY))
return -1;
while (1) {
--
1.8.4.2
More information about the CRIU
mailing list