linux-lts-quantal-3.5.0/kernel/replay.c
/* Creates a new clock for a record group */
Creates a new clock for a record group
Creates a new clock for a record group
static int
create_shared_clock (struct record_group* prg)
{
	u_long uaddr;
	int fd, rc;
	mm_segment_t old_fs = get_fs();
	struct replay_paths_to_free* ptmp;
	set_fs(KERNEL_DS);
	mutex_lock(&paths_to_free_mutex);
	while (paths_to_free) {
		ptmp = paths_to_free;
		paths_to_free = ptmp->next;
		fd = sys_unlink (ptmp->path);
		KFREE (ptmp);
	}
	mutex_unlock(&paths_to_free_mutex);
	snprintf (prg->rg_shmpath, MAX_LOGDIR_STRLEN+1, "/dev/shm/uclock%d", current->pid);
	fd = sys_open (prg->rg_shmpath, O_CREAT | O_EXCL | O_RDWR | O_NOFOLLOW, 0644);
	if (fd < 0) {
		printk ("create_shared_clock: pid %d cannot open shared file %s, rc=%d\n", current->pid, prg->rg_shmpath, fd);
		goto out_oldfs;
	}
	rc = sys_ftruncate (fd, 4096);
	if (rc < 0) {
		printk ("create_shared_clock: pid %d cannot create new shm page, rc=%d\n", current->pid, rc);
		goto out_close;
	}	
	uaddr = sys_mmap_pgoff (0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	if (IS_ERR((void *) uaddr)) {
		printk ("create_shared_clock: pid %d cannot map shm page, rc=%ld\n", current->pid, PTR_ERR((void *) uaddr));
		goto out_close;
	}
	rc = get_user_pages (current, current->mm, uaddr, 1, 1, 0, &prg->rg_shared_page, NULL);
	if (rc != 1) {
		printk ("creare_shared_clock: pid %d cannot get shm page, rc=%d\n", current->pid, rc);
		goto out_unmap;
	}
	prg->rg_pkrecord_clock = (atomic_t *) kmap (prg->rg_shared_page);
	DPRINT ("record/replay clock is at %p\n", prg->rg_pkrecord_clock);
	rc = sys_munmap (uaddr, 4096);
	if (rc < 0) printk ("create_shared_clock: pid %d cannot munmap shared page, rc=%d\n", current->pid, rc);
	rc = sys_close(fd);
	if (rc < 0) printk ("create_shared_clock: pid %d cannot close shared file %s, rc=%d\n", current->pid, prg->rg_shmpath, rc);
	return 0;
out_unmap:
	sys_munmap (uaddr, 4096);
out_close:
	sys_close (fd);
	sys_unlink (prg->rg_shmpath);
out_oldfs:
	set_fs(old_fs);
	return -1;
}
static int create_shared_clock ( struct record_group * prg ) { u_long uaddr ; int fd , rc ; mm_segment_t old_fs = get_fs ( ) ; struct replay_paths_to_free * ptmp ; set_fs ( KERNEL_DS ) ; mutex_lock ( & paths_to_free_mutex ) ; while ( paths_to_free ) { ptmp = paths_to_free ; paths_to_free = ptmp -> next ; fd = sys_unlink ( ptmp -> path ) ; KFREE ( ptmp ) ; } mutex_unlock ( & paths_to_free_mutex ) ; snprintf ( prg -> rg_shmpath , MAX_LOGDIR_STRLEN + 1 , " " , current -> pid ) ; fd = sys_open ( prg -> rg_shmpath , O_CREAT | O_EXCL | O_RDWR | O_NOFOLLOW , 0644 ) ; if ( fd < 0 ) { printk ( " \n " , current -> pid , prg -> rg_shmpath , fd ) ; goto out_oldfs ; } rc = sys_ftruncate ( fd , 4096 ) ; if ( rc < 0 ) { printk ( " \n " , current -> pid , rc ) ; goto out_close ; } uaddr = sys_mmap_pgoff ( 0 , 4096 , PROT_READ | PROT_WRITE , MAP_SHARED , fd , 0 ) ; if ( IS_ERR ( ( void * ) uaddr ) ) { printk ( " \n " , current -> pid , PTR_ERR ( ( void * ) uaddr ) ) ; goto out_close ; } rc = get_user_pages ( current , current -> mm , uaddr , 1 , 1 , 0 , & prg -> rg_shared_page , NULL ) ; if ( rc != 1 ) { printk ( " \n " , current -> pid , rc ) ; goto out_unmap ; } prg -> rg_pkrecord_clock = ( atomic_t * ) kmap ( prg -> rg_shared_page ) ; DPRINT ( " \n " , prg -> rg_pkrecord_clock ) ; rc = sys_munmap ( uaddr , 4096 ) ; if ( rc < 0 ) printk ( " \n " , current -> pid , rc ) ; rc = sys_close ( fd ) ; if ( rc < 0 ) printk ( " \n " , current -> pid , prg -> rg_shmpath , rc ) ; return 0 ; out_unmap : sys_munmap ( uaddr , 4096 ) ; out_close : sys_close ( fd ) ; sys_unlink ( prg -> rg_shmpath ) ; out_oldfs : set_fs ( old_fs ) ; return -1 ; }
Creates a new clock for a record group
Creates a new clock for a record group