From 5cae819d8c52bfbba6e5708e227a1e83e47d90f9 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 9 Apr 2013 11:13:51 +0400 Subject: [PATCH] img: Get rid of open_image_ro helper O_RSTR flag should be used instead for regular open_image Signed-off-by: Pavel Emelyanov --- cr-restore.c | 22 +++++++++++----------- cr-show.c | 10 +++++----- file-lock.c | 2 +- files-reg.c | 4 ++-- files.c | 6 +++--- image.c | 2 +- include/crtools.h | 1 - ipc_ns.c | 8 ++++---- mount.c | 4 ++-- net.c | 4 ++-- pipes.c | 2 +- protobuf.c | 2 +- pstree.c | 4 ++-- shmem.c | 6 +++--- sk-queue.c | 4 ++-- sk-tcp.c | 2 +- uts_ns.c | 2 +- 17 files changed, 42 insertions(+), 43 deletions(-) diff --git a/cr-restore.c b/cr-restore.c index 48b441b29..9f02f34d3 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -276,9 +276,9 @@ static int restore_priv_vma_content(pid_t pid) vma = list_first_entry(&rst_vmas.h, struct vma_area, list); - fd = open_image_ro(CR_FD_PAGEMAP, (long)pid); + fd = open_image(CR_FD_PAGEMAP, O_RSTR, (long)pid); if (fd < 0) { - fd_pg = open_image_ro(CR_FD_PAGES_OLD, pid); + fd_pg = open_image(CR_FD_PAGES_OLD, O_RSTR, pid); if (fd_pg < 0) return -1; } else { @@ -428,7 +428,7 @@ static int read_vmas(int pid) list_replace_init(&rst_vmas.h, &old); /* Skip errors, because a zombie doesn't have an image of vmas */ - fd = open_image_ro(CR_FD_VMAS, pid); + fd = open_image(CR_FD_VMAS, O_RSTR, pid); if (fd < 0) { if (errno != ENOENT) ret = fd; @@ -571,7 +571,7 @@ static int prepare_sigactions(int pid) int sig; int ret = -1; - fd_sigact = open_image_ro(CR_FD_SIGACT, pid); + fd_sigact = open_image(CR_FD_SIGACT, O_RSTR, pid); if (fd_sigact < 0) return -1; @@ -859,7 +859,7 @@ static inline int fork_with_pid(struct pstree_item *item) pid_t pid = item->pid.virt; if (item->state != TASK_HELPER) { - fd = open_image_ro(CR_FD_CORE, pid); + fd = open_image(CR_FD_CORE, O_RSTR, pid); if (fd < 0) return -1; @@ -1434,7 +1434,7 @@ static int prepare_itimers(int pid, struct task_restore_core_args *args) int fd, ret = -1; ItimerEntry *ie; - fd = open_image_ro(CR_FD_ITIMERS, pid); + fd = open_image(CR_FD_ITIMERS, O_RSTR, pid); if (fd < 0) return fd; @@ -1477,7 +1477,7 @@ static int prepare_creds(int pid, struct task_restore_core_args *args) int fd, ret; CredsEntry *ce; - fd = open_image_ro(CR_FD_CREDS, pid); + fd = open_image(CR_FD_CREDS, O_RSTR, pid); if (fd < 0) return fd; @@ -1550,7 +1550,7 @@ static int prepare_mm(pid_t pid, struct task_restore_core_args *args) int fd, exe_fd, i, ret = -1; MmEntry *mm; - fd = open_image_ro(CR_FD_MM, pid); + fd = open_image(CR_FD_MM, O_RSTR, pid); if (fd < 0) return -1; @@ -1673,7 +1673,7 @@ static int prepare_rlimits(int pid, struct task_restore_core_args *ta) ta->nr_rlim = 0; - fd = open_image_ro(CR_FD_RLIMIT, pid); + fd = open_image(CR_FD_RLIMIT, O_RSTR, pid); if (fd < 0) { if (errno == ENOENT) { pr_info("Skip rlimits for %d\n", pid); @@ -1719,7 +1719,7 @@ static int open_signal_image(int type, pid_t pid, siginfo_t **ptr, { int fd, ret, n; - fd = open_image_ro(type, pid); + fd = open_image(type, O_RSTR, pid); if (fd < 0) return -1; @@ -1993,7 +1993,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core) task_args->t = thread_args + i; tcore = core; } else { - fd_core = open_image_ro(CR_FD_CORE, thread_args[i].pid); + fd_core = open_image(CR_FD_CORE, O_RSTR, thread_args[i].pid); if (fd_core < 0) { pr_err("Can't open core data for thread %d\n", thread_args[i].pid); diff --git a/cr-show.c b/cr-show.c index 2fc2ba150..14af3cfee 100644 --- a/cr-show.c +++ b/cr-show.c @@ -460,7 +460,7 @@ static int cr_show_pstree_item(struct cr_options *opts, struct pstree_item *item if (item->threads[i].virt == item->pid.virt) continue; - fd_th = open_image_ro(CR_FD_CORE, item->threads[i].virt); + fd_th = open_image(CR_FD_CORE, O_SHOW, item->threads[i].virt); if (fd_th < 0) goto outc; @@ -484,7 +484,7 @@ static int cr_show_pstree_item(struct cr_options *opts, struct pstree_item *item } if (pb_read_one(fdset_fd(cr_fdset, CR_FD_IDS), &ids, PB_IDS) > 0) { - i = open_image_ro(CR_FD_FDINFO, ids->files_id); + i = open_image(CR_FD_FDINFO, O_SHOW, ids->files_id); if (i >= 0) { pr_msg("* "); pr_msg(fdset_template[CR_FD_FDINFO].fmt, ids->files_id); @@ -511,7 +511,7 @@ static int cr_show_pid(struct cr_options *opts, int pid) int fd, ret; struct pstree_item item; - fd = open_image_ro(CR_FD_PSTREE); + fd = open_image(CR_FD_PSTREE, O_SHOW); if (fd < 0) return -1; @@ -541,13 +541,13 @@ static int cr_show_all(struct cr_options *opts) struct pstree_item *item = NULL, *tmp; int ret = -1, fd, pid; - fd = open_image_ro(CR_FD_PSTREE); + fd = open_image(CR_FD_PSTREE, O_SHOW); if (fd < 0) goto out; show_collect_pstree(fd, 1); close(fd); - fd = open_image_ro(CR_FD_SK_QUEUES); + fd = open_image(CR_FD_SK_QUEUES, O_SHOW); if (fd < 0) goto out; diff --git a/file-lock.c b/file-lock.c index c6f4d427d..af2d885be 100644 --- a/file-lock.c +++ b/file-lock.c @@ -222,7 +222,7 @@ static int restore_file_locks(int pid) int fd, ret = -1; FileLockEntry *fle; - fd = open_image_ro(CR_FD_FILE_LOCKS, pid); + fd = open_image(CR_FD_FILE_LOCKS, O_RSTR, pid); if (fd < 0) { if (errno == ENOENT) return 0; diff --git a/files-reg.c b/files-reg.c index 8aff9e75a..b52fe36d1 100644 --- a/files-reg.c +++ b/files-reg.c @@ -73,7 +73,7 @@ static int open_remap_ghost(struct reg_file_info *rfi, if (!gf->remap.path) goto err; - ifd = open_image_ro(CR_FD_GHOST_FILE, rfe->remap_id); + ifd = open_image(CR_FD_GHOST_FILE, O_RSTR, rfe->remap_id); if (ifd < 0) goto err; @@ -169,7 +169,7 @@ static int collect_remaps(void) { int fd, ret = 0; - fd = open_image_ro(CR_FD_REMAP_FPATH); + fd = open_image(CR_FD_REMAP_FPATH, O_RSTR); if (fd < 0) return -1; diff --git a/files.c b/files.c index 465797489..4d7c19eb7 100644 --- a/files.c +++ b/files.c @@ -435,7 +435,7 @@ int prepare_fd_pid(struct pstree_item *item) INIT_LIST_HEAD(&rst_info->tty_slaves); if (!fdinfo_per_id) { - fdinfo_fd = open_image_ro(CR_FD_FDINFO, pid); + fdinfo_fd = open_image(CR_FD_FDINFO, O_RSTR, pid); if (fdinfo_fd < 0) { if (errno == ENOENT) return 0; @@ -448,7 +448,7 @@ int prepare_fd_pid(struct pstree_item *item) if (item->rst->fdt && item->rst->fdt->pid != item->pid.virt) return 0; - fdinfo_fd = open_image_ro(CR_FD_FDINFO, item->ids->files_id); + fdinfo_fd = open_image(CR_FD_FDINFO, O_RSTR, item->ids->files_id); if (fdinfo_fd < 0) return -1; } @@ -817,7 +817,7 @@ int prepare_fs(int pid) int ifd, cwd, ret = -1; FsEntry *fe; - ifd = open_image_ro(CR_FD_FS, pid); + ifd = open_image(CR_FD_FS, O_RSTR, pid); if (ifd < 0) return -1; diff --git a/image.c b/image.c index faa90ffc7..2f01fe248 100644 --- a/image.c +++ b/image.c @@ -25,7 +25,7 @@ int check_img_inventory(void) int fd, ret = -1; InventoryEntry *he; - fd = open_image_ro(CR_FD_INVENTORY); + fd = open_image(CR_FD_INVENTORY, O_RSTR); if (fd < 0) return -1; diff --git a/include/crtools.h b/include/crtools.h index 51a548d6c..6cd4cde94 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -189,7 +189,6 @@ extern int open_image_dir(void); extern void close_image_dir(void); int open_image(int type, unsigned long flags, ...); -#define open_image_ro(type, ...) open_image(type, O_RDONLY, ##__VA_ARGS__) int open_pages_image(unsigned long flags, int pm_fd); void up_page_ids_base(void); diff --git a/ipc_ns.c b/ipc_ns.c index ded8c8764..c7993cacd 100644 --- a/ipc_ns.c +++ b/ipc_ns.c @@ -600,7 +600,7 @@ static int prepare_ipc_sem(int pid) int fd, ret; pr_info("Restoring IPC semaphores sets\n"); - fd = open_image_ro(CR_FD_IPCNS_SEM, pid); + fd = open_image(CR_FD_IPCNS_SEM, O_RSTR, pid); if (fd < 0) return -1; @@ -733,7 +733,7 @@ static int prepare_ipc_msg(int pid) int fd, ret; pr_info("Restoring IPC message queues\n"); - fd = open_image_ro(CR_FD_IPCNS_MSG, pid); + fd = open_image(CR_FD_IPCNS_MSG, O_RSTR, pid); if (fd < 0) return -1; @@ -843,7 +843,7 @@ static int prepare_ipc_shm(int pid) int fd, ret; pr_info("Restoring IPC shared memory\n"); - fd = open_image_ro(CR_FD_IPCNS_SHM, pid); + fd = open_image(CR_FD_IPCNS_SHM, O_RSTR, pid); if (fd < 0) return -1; @@ -881,7 +881,7 @@ static int prepare_ipc_var(int pid) IpcVarEntry *var; pr_info("Restoring IPC variables\n"); - fd = open_image_ro(CR_FD_IPCNS_VAR, pid); + fd = open_image(CR_FD_IPCNS_VAR, O_RSTR, pid); if (fd < 0) return -1; diff --git a/mount.c b/mount.c index 97a31e4f2..89104bc77 100644 --- a/mount.c +++ b/mount.c @@ -296,7 +296,7 @@ static int tmpfs_restore(struct mount_info *pm) int ret; int fd_img; - fd_img = open_image_ro(CR_FD_TMPFS, pm->mnt_id); + fd_img = open_image(CR_FD_TMPFS, O_RSTR, pm->mnt_id); if (fd_img < 0) return -1; @@ -641,7 +641,7 @@ static int populate_mnt_ns(int ns_pid) pr_info("Populating mount namespace\n"); - img = open_image_ro(CR_FD_MOUNTPOINTS, ns_pid); + img = open_image(CR_FD_MOUNTPOINTS, O_RSTR, ns_pid); if (img < 0) return -1; diff --git a/net.c b/net.c index 444f78ed8..53c8ab74c 100644 --- a/net.c +++ b/net.c @@ -256,7 +256,7 @@ static int restore_links(int pid) int fd, nlsk, ret; NetDeviceEntry *nde; - fd = open_image_ro(CR_FD_NETDEV, pid); + fd = open_image(CR_FD_NETDEV, O_RSTR, pid); if (fd < 0) return -1; @@ -318,7 +318,7 @@ static int restore_ip_dump(int type, int pid, char *cmd) { int fd, ret; - ret = fd = open_image_ro(type, pid); + ret = fd = open_image(type, O_RSTR, pid); if (fd >= 0) { ret = run_ip_tool(cmd, "restore", fd, -1); close(fd); diff --git a/pipes.c b/pipes.c index 7b2765fdd..b69fa61ec 100644 --- a/pipes.c +++ b/pipes.c @@ -74,7 +74,7 @@ int collect_pipe_data(int img_type, struct pipe_data_rst **hash) int fd, ret; struct pipe_data_rst *r = NULL; - fd = open_image_ro(img_type); + fd = open_image(img_type, O_RSTR); if (fd < 0) return -1; diff --git a/protobuf.c b/protobuf.c index 7868e410a..3470efbfe 100644 --- a/protobuf.c +++ b/protobuf.c @@ -684,7 +684,7 @@ static int __collect_image(int fd_t, int obj_t, unsigned size, { int fd, ret; - fd = open_image_ro(fd_t); + fd = open_image(fd_t, O_RSTR); if (fd < 0) return -1; diff --git a/pstree.c b/pstree.c index 9eebbfb6e..cb089dcb7 100644 --- a/pstree.c +++ b/pstree.c @@ -190,7 +190,7 @@ static int read_pstree_image(void) pr_info("Reading image tree\n"); - ps_fd = open_image_ro(CR_FD_PSTREE); + ps_fd = open_image(CR_FD_PSTREE, O_RSTR); if (ps_fd < 0) return ps_fd; @@ -268,7 +268,7 @@ static int read_pstree_image(void) pstree_entry__free_unpacked(e, NULL); - fd = open_image_ro(CR_FD_IDS, pi->pid.virt); + fd = open_image(CR_FD_IDS, O_RSTR, pi->pid.virt); if (fd < 0) { if (errno == ENOENT) continue; diff --git a/shmem.c b/shmem.c index a91b9cc62..a80905055 100644 --- a/shmem.c +++ b/shmem.c @@ -83,7 +83,7 @@ int prepare_shmem_pid(int pid) int fd, ret = -1; VmaEntry *vi; - fd = open_image_ro(CR_FD_VMAS, pid); + fd = open_image(CR_FD_VMAS, O_RSTR, pid); if (fd < 0) { if (errno == ENOENT) return 0; @@ -138,9 +138,9 @@ static int restore_shmem_content(void *addr, struct shmem_info *si) { int fd, fd_pg, ret = 0; - fd = open_image_ro(CR_FD_SHMEM_PAGEMAP, si->shmid); + fd = open_image(CR_FD_SHMEM_PAGEMAP, O_RSTR, si->shmid); if (fd < 0) { - fd_pg = open_image_ro(CR_FD_SHM_PAGES_OLD, si->shmid); + fd_pg = open_image(CR_FD_SHM_PAGES_OLD, O_RSTR, si->shmid); if (fd_pg < 0) goto err_unmap; } else { diff --git a/sk-queue.c b/sk-queue.c index 4f9a743c9..2856b1e3f 100644 --- a/sk-queue.c +++ b/sk-queue.c @@ -38,7 +38,7 @@ int read_sk_queues(void) pr_info("Trying to read socket queues image\n"); - fd = open_image_ro(CR_FD_SK_QUEUES); + fd = open_image(CR_FD_SK_QUEUES, O_RSTR); if (fd < 0) return -1; @@ -192,7 +192,7 @@ int restore_sk_queue(int fd, unsigned int peer_id) if (restore_prepare_socket(fd)) return -1; - img_fd = open_image_ro(CR_FD_SK_QUEUES); + img_fd = open_image(CR_FD_SK_QUEUES, O_RSTR); if (img_fd < 0) return -1; diff --git a/sk-tcp.c b/sk-tcp.c index 7c762d51c..e23d6b0b9 100644 --- a/sk-tcp.c +++ b/sk-tcp.c @@ -512,7 +512,7 @@ static int restore_tcp_conn_state(int sk, struct inet_sk_info *ii) pr_info("Restoring TCP connection id %x ino %x\n", ii->ie->id, ii->ie->ino); - ifd = open_image_ro(CR_FD_TCP_STREAM, ii->ie->ino); + ifd = open_image(CR_FD_TCP_STREAM, O_RSTR, ii->ie->ino); if (ifd < 0) goto err; diff --git a/uts_ns.c b/uts_ns.c index 7e2fff1fb..9e1104bc2 100644 --- a/uts_ns.c +++ b/uts_ns.c @@ -45,7 +45,7 @@ int prepare_utsns(int pid) { }, }; - fd = open_image_ro(CR_FD_UTSNS, pid); + fd = open_image(CR_FD_UTSNS, O_RSTR, pid); if (fd < 0) return -1;