Commit 4141296e authored by Kinsbursky Stanislav's avatar Kinsbursky Stanislav Committed by Cyrill Gorcunov

IPC: dump semaphores set

Signed-off-by: 's avatarStanislav Kinsbursky <skinsbursky@parallels.com>
Acked-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 90340f75
......@@ -128,6 +128,12 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
.fmt = FMT_FNAME_IPCNS_MSG,
.magic = IPCNS_MSG_MAGIC,
},
/* IPC namespace semaphores sets */
[CR_FD_IPCNS_SEM] = {
.fmt = FMT_FNAME_IPCNS_SEM,
.magic = IPCNS_SEM_MAGIC,
},
};
static struct cr_fdset *alloc_cr_fdset(void)
......
......@@ -40,6 +40,7 @@ enum {
CR_FD_IPCNS_VAR,
CR_FD_IPCNS_SHM,
CR_FD_IPCNS_MSG,
CR_FD_IPCNS_SEM,
CR_FD_MAX
};
......@@ -84,6 +85,7 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
#define FMT_FNAME_IPCNS_VAR "ipcns-var-%d.img"
#define FMT_FNAME_IPCNS_SHM "ipcns-shm-%d.img"
#define FMT_FNAME_IPCNS_MSG "ipcns-msg-%d.img"
#define FMT_FNAME_IPCNS_SEM "ipcns-sem-%d.img"
extern int get_image_path(char *path, int size, const char *fmt, int pid);
......@@ -117,6 +119,7 @@ struct cr_fdset {
CR_FD_DESC_USE(CR_FD_UTSNS) |\
CR_FD_DESC_USE(CR_FD_IPCNS_VAR) |\
CR_FD_DESC_USE(CR_FD_IPCNS_MSG) |\
CR_FD_DESC_USE(CR_FD_IPCNS_SEM) |\
CR_FD_DESC_USE(CR_FD_IPCNS_SHM) )
#define CR_FD_DESC_NONE (0)
......
......@@ -24,6 +24,7 @@
#define IPCNS_VAR_MAGIC 0x53115007 /* Samara */
#define IPCNS_SHM_MAGIC 0x46283044 /* Odessa */
#define IPCNS_MSG_MAGIC 0x55453737 /* Moscow */
#define IPCNS_SEM_MAGIC 0x59573019 /* St. Petersburg */
#define PIPEFS_MAGIC 0x50495045
......@@ -156,6 +157,12 @@ struct ipc_msg_entry {
u8 pad[4];
} __packed;
struct ipc_sem_entry {
struct ipc_desc_entry desc;
u16 nsems;
u8 pad[6];
} __packed;
#define VMA_AREA_NONE (0 << 0)
#define VMA_AREA_REGULAR (1 << 0) /* Dumpable area */
#define VMA_AREA_STACK (1 << 1)
......
......@@ -67,6 +67,101 @@ static void fill_ipc_desc(int id, struct ipc_desc_entry *desc,
desc->mode = ipcp->mode;
}
static void print_ipc_sem_array(int nr, u16 *values)
{
while(nr--)
pr_info(" %-5d", values[nr]);
pr_info("\n");
}
static void print_ipc_sem_entry(const struct ipc_sem_entry *sem)
{
print_ipc_desc_entry(&sem->desc);
pr_info ("nsems: %-10d\n", sem->nsems);
}
static int dump_ipc_sem_set(int fd, const struct ipc_sem_entry *entry)
{
int ret, size;
u16 *values;
size = sizeof(u16) * entry->nsems;
values = xmalloc(size);
if (values == NULL) {
pr_err("Failed to allocate memory for semaphore set values\n");
ret = -ENOMEM;
goto out;
}
ret = semctl(entry->desc.id, 0, GETALL, values);
if (ret < 0) {
pr_perror("Failed to get semaphore set values");
ret = -errno;
goto out;
}
print_ipc_sem_array(entry->nsems, values);
ret = write_img_buf(fd, values, round_up(size, sizeof(u64)));
if (ret < 0) {
pr_err("Failed to write IPC message data\n");
goto out;
}
out:
xfree(values);
return ret;
}
static int dump_ipc_sem_desc(int fd, int id, const struct semid_ds *ds)
{
struct ipc_sem_entry sem;
int ret;
fill_ipc_desc(id, &sem.desc, &ds->sem_perm);
sem.nsems = ds->sem_nsems;
print_ipc_sem_entry(&sem);
ret = write_img(fd, &sem);
if (ret < 0) {
pr_err("Failed to write IPC semaphores set\n");
return ret;
}
return dump_ipc_sem_set(fd, &sem);
}
static int dump_ipc_sem(int fd)
{
int i, maxid;
struct seminfo info;
int err, slot;
maxid = semctl(0, 0, SEM_INFO, &info);
if (maxid < 0) {
pr_perror("semctl failed");
return -errno;
}
pr_info("IPC semaphore sets: %d\n", info.semusz);
for (i = 0, slot = 0; i <= maxid; i++) {
struct semid_ds ds;
int id, ret;
id = semctl(i, 0, SEM_STAT, &ds);
if (id < 0) {
if (errno == EINVAL)
continue;
pr_perror("Failed to get stats for IPC semaphore set");
break;
}
ret = dump_ipc_sem_desc(fd, id, &ds);
if (!ret)
slot++;
}
if (slot != info.semusz) {
pr_err("Failed to collect %d (only %d succeeded)\n", info.semusz, slot);
return -EFAULT;
}
return info.semusz;
}
static void print_ipc_msg(int nr, const struct ipc_msg *msg)
{
pr_info(" %-5d: type: %-20ld size: %-10d\n",
......@@ -206,23 +301,6 @@ static int ipc_sysctl_req(struct ipc_var_entry *e, int op)
return sysctl_op(req, op);
}
static int dump_ipc_sem(void *data)
{
int ret;
struct seminfo info;
ret = semctl(0, 0, SEM_INFO, &info);
if (ret < 0)
pr_perror("semctl failed");
if (ret) {
pr_err("IPC semaphores migration is not supported yet\n");
return -EINVAL;
}
return 0;
}
/*
* TODO: Function below should be later improved to locate and dump only dirty
* pages via updated sys_mincore().
......@@ -335,7 +413,7 @@ static int dump_ipc_data(const struct cr_fdset *fdset)
ret = dump_ipc_msg(fdset->fds[CR_FD_IPCNS_MSG]);
if (ret < 0)
return ret;
ret = dump_ipc_sem(0);
ret = dump_ipc_sem(fdset->fds[CR_FD_IPCNS_SEM]);
if (ret < 0)
return ret;
return 0;
......
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