linux-lts-quantal-3.5.0/kernel/replay.c
/* Reads in a list of memory regions that will be used in a replay */
Reads in a list of memory regions that will be used in a replay
Reads in a list of memory regions that will be used in a replay
int read_mmap_log (struct record_group* precg)
{
	int fd;
	int rc = 0;
	char filename[MAX_LOGDIR_STRLEN+20];
	struct file* file;
	mm_segment_t old_fs;
	loff_t pos = 0;
	struct stat64 st;
	int num_entries = 0;
	int i = 0;
	struct reserved_mapping* pmapping;
	old_fs = get_fs();
	set_fs(KERNEL_DS);
	sprintf (filename, "%s/mlog", precg->rg_logdir);
	MPRINT ("Pid %d Opening mlog %s\n", current->pid, filename);
	fd = sys_open(filename, O_RDONLY, 0644);
	if (fd < 0) {
		printk("read_mmap_log: cannot open log file %s\n", filename);
		return -EINVAL;
	}
	file = fget(fd);
	rc = sys_stat64(filename, &st);
	if (rc < 0) {
		printk("read_mmap_log: cannot stat file %s, %d\n", filename, rc);
		return -EINVAL;
	}
	num_entries = st.st_size / (sizeof(struct reserved_mapping));
	for (i = 0; i < num_entries; i++) {
		pmapping = KMALLOC (sizeof(struct reserved_mapping), GFP_KERNEL);
		if (pmapping == NULL) {
			printk ("read_mmap_log: Cannot allocate new reserve mapping\n");
			return -ENOMEM;
		}
		rc = vfs_read(file, (char *) pmapping, sizeof(struct reserved_mapping), &pos);
		if (rc < 0) {
			printk("Pid %d problem reading in a reserved mapping, rc %d\n", current->pid, rc);
			KFREE (pmapping);
			return rc;
		}
		if (rc != sizeof(struct reserved_mapping)) {
			printk("Pid %d read reserved_mapping expected %d, got %d\n", current->pid, sizeof(struct reserved_mapping), rc);
			KFREE(pmapping);
			return rc;	
		}
		ds_list_insert (precg->rg_reserved_mem_list, pmapping);
	}
	fput(file);
	rc = sys_close (fd);
	if (rc < 0) printk ("read_log_data: file close failed with rc %d\n", rc);
	set_fs (old_fs);
	return rc;
}
int read_mmap_log ( struct record_group * precg ) { int fd ; int rc = 0 ; char filename [ MAX_LOGDIR_STRLEN + 20 ] ; struct file * file ; mm_segment_t old_fs ; loff_t pos = 0 ; struct stat64 st ; int num_entries = 0 ; int i = 0 ; struct reserved_mapping * pmapping ; old_fs = get_fs ( ) ; set_fs ( KERNEL_DS ) ; sprintf ( filename , " " , precg -> rg_logdir ) ; MPRINT ( " \n " , current -> pid , filename ) ; fd = sys_open ( filename , O_RDONLY , 0644 ) ; if ( fd < 0 ) { printk ( " \n " , filename ) ; return - EINVAL ; } file = fget ( fd ) ; rc = sys_stat64 ( filename , & st ) ; if ( rc < 0 ) { printk ( " \n " , filename , rc ) ; return - EINVAL ; } num_entries = st . st_size / ( sizeof ( struct reserved_mapping ) ) ; for ( i = 0 ; i < num_entries ; i ++ ) { pmapping = KMALLOC ( sizeof ( struct reserved_mapping ) , GFP_KERNEL ) ; if ( pmapping == NULL ) { printk ( " \n " ) ; return - ENOMEM ; } rc = vfs_read ( file , ( char * ) pmapping , sizeof ( struct reserved_mapping ) , & pos ) ; if ( rc < 0 ) { printk ( " \n " , current -> pid , rc ) ; KFREE ( pmapping ) ; return rc ; } if ( rc != sizeof ( struct reserved_mapping ) ) { printk ( " \n " , current -> pid , sizeof ( struct reserved_mapping ) , rc ) ; KFREE ( pmapping ) ; return rc ; } ds_list_insert ( precg -> rg_reserved_mem_list , pmapping ) ; } fput ( file ) ; rc = sys_close ( fd ) ; if ( rc < 0 ) printk ( " \n " , rc ) ; set_fs ( old_fs ) ; return rc ; }
Reads in a list of memory regions that will be used in a replay
Reads in a list of memory regions that will be used in a replay
// stat the file, see how many pmaps we expect // Read the mappings from file and put them in the record thread structure