refactoring /proc

This commit is contained in:
Tomoki Shirasawa
2016-02-10 08:11:02 +09:00
parent c0cc6ac6db
commit a866192db7
10 changed files with 793 additions and 784 deletions

View File

@@ -72,9 +72,6 @@ int (*mcctrl_sys_mount)(char *dev_name,char *dir_name, char *type, unsigned long
//static DECLARE_WAIT_QUEUE_HEAD(wq_prepare);
//extern struct mcctrl_channel *channels;
int mcctrl_ikc_set_recv_cpu(ihk_os_t os, int cpu);
extern int procfs_create_entry(void *os, int ref, int osnum, int pid, char *name,
int mode, void *opaque);
extern void procfs_delete_entry(void *os, int osnum, char *fname);
static long mcexec_prepare_image(ihk_os_t os,
struct program_load_desc * __user udesc)
@@ -290,12 +287,15 @@ static void release_handler(ihk_os_t os, void *param)
{
struct handlerinfo *info = param;
struct ikc_scd_packet isp;
int os_ind = ihk_host_os_get_index(os);
memset(&isp, '\0', sizeof isp);
isp.msg = SCD_MSG_CLEANUP_PROCESS;
isp.pid = info->pid;
mcctrl_ikc_send(os, 0, &isp);
if(os_ind >= 0)
delete_pid_entry(os_ind, info->pid);
kfree(param);
}
@@ -861,7 +861,7 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
struct mckernel_exec_file *mcef_iter;
int retval;
int os_ind = ihk_host_os_get_index(os);
char *proc_name, *pathbuf, *fullpath;
char *pathbuf, *fullpath;
if (os_ind < 0) {
return EINVAL;
@@ -872,12 +872,6 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
return ENOMEM;
}
proc_name = kmalloc(PATH_MAX, GFP_TEMPORARY);
if (!proc_name) {
retval = ENOMEM;
goto out_error_free_path;
}
file = open_exec(filename);
retval = PTR_ERR(file);
if (IS_ERR(file)) {
@@ -896,8 +890,6 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
goto out_put_file;
}
snprintf(proc_name, 1024, "mcos%d/%d/exe", os_ind, current->tgid);
spin_lock_irq(&mckernel_exec_file_lock);
/* Find previous file (if exists) and drop it */
list_for_each_entry(mcef_iter, &mckernel_exec_files, list) {
@@ -906,9 +898,6 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
fput(mcef_iter->fp);
list_del(&mcef_iter->list);
kfree(mcef_iter);
/* Drop old /proc/self/exe */
procfs_delete_entry(os, os_ind, proc_name);
dprintk("%d open_exec dropped previous executable \n", (int)current->tgid);
break;
}
}
@@ -920,15 +909,12 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
list_add_tail(&mcef->list, &mckernel_exec_files);
/* Create /proc/self/exe entry */
if (procfs_create_entry(os, 0, os_ind, current->tgid, proc_name,
S_IFLNK, fullpath) != 0) {
printk("ERROR: could not create a procfs entry for %s.\n", proc_name);
}
add_pid_entry(os_ind, current->tgid);
proc_exe_link(os_ind, current->tgid, fullpath);
spin_unlock(&mckernel_exec_file_lock);
dprintk("%d open_exec and holding file: %s\n", (int)current->tgid, filename);
kfree(proc_name);
kfree(pathbuf);
return 0;
@@ -937,9 +923,6 @@ out_put_file:
fput(file);
out_error_free:
kfree(proc_name);
out_error_free_path:
kfree(pathbuf);
return -retval;
}
@@ -950,7 +933,6 @@ int mcexec_close_exec(ihk_os_t os)
struct mckernel_exec_file *mcef = NULL;
int found = 0;
int os_ind = ihk_host_os_get_index(os);
char proc_name[1024];
if (os_ind < 0) {
return EINVAL;
@@ -969,14 +951,6 @@ int mcexec_close_exec(ihk_os_t os)
}
}
/* Remove /proc/self/exe and /proc/self directory
* TODO: instead of removing directory explicitly, detect in procfs_delete_entry()
* when a directory becomes empty and remove it automatically */
snprintf(proc_name, 1024, "mcos%d/%d/exe", os_ind, current->tgid);
procfs_delete_entry(os, os_ind, proc_name);
snprintf(proc_name, 1024, "mcos%d/%d", os_ind, current->tgid);
procfs_delete_entry(os, os_ind, proc_name);
spin_unlock(&mckernel_exec_file_lock);
return (found ? 0 : EINVAL);