linux-lts-quantal-3.5.0/kernel/replay.c
// only can be called after init_log_write
only can be called after init_log_write
only can be called after init_log_write
struct file* init_clog_write (struct record_thread* prect, loff_t* ppos, int* pfd)
{
	char filename[MAX_LOGDIR_STRLEN+20];
	struct stat64 st;
	mm_segment_t old_fs;
	int rc;
	sprintf (filename, "%s/klog.id.%d.clog", prect->rp_group->rg_logdir, prect->rp_record_pid);
	old_fs = get_fs();
	set_fs(KERNEL_DS);
	if (prect->rp_klog_opened) {
		rc = sys_stat64(filename, &st);
		if (rc < 0) {
			printk ("Stat of file %s failed\n", filename);
			return NULL;
		}
		*ppos = st.st_size;
		*pfd = sys_open(filename, O_WRONLY|O_APPEND, 0644);
		MPRINT ("Reopened log file %s, pos = %ld\n", filename, (long) *ppos);
	} else {
		printk ("Pid %d open clog file %s, the uncompressed log is not opened yet.\n", prect->rp_record_pid, filename);
	}
	set_fs(old_fs);
	if (*pfd < 0) {
		printk ("Cannot open clog file %s, rc = %d\n", filename, *pfd);
		return NULL;
	}
	return (fget(*pfd));
}
struct file * init_clog_write ( struct record_thread * prect , loff_t * ppos , int * pfd ) { char filename [ MAX_LOGDIR_STRLEN + 20 ] ; struct stat64 st ; mm_segment_t old_fs ; int rc ; sprintf ( filename , " " , prect -> rp_group -> rg_logdir , prect -> rp_record_pid ) ; old_fs = get_fs ( ) ; set_fs ( KERNEL_DS ) ; if ( prect -> rp_klog_opened ) { rc = sys_stat64 ( filename , & st ) ; if ( rc < 0 ) { printk ( " \n " , filename ) ; return NULL ; } * ppos = st . st_size ; * pfd = sys_open ( filename , O_WRONLY | O_APPEND , 0644 ) ; MPRINT ( " \n " , filename , ( long ) * ppos ) ; } else { printk ( " \n " , prect -> rp_record_pid , filename ) ; } set_fs ( old_fs ) ; if ( * pfd < 0 ) { printk ( " \n " , filename , * pfd ) ; return NULL ; } return ( fget ( * pfd ) ) ; }
only can be called after init_log_write
only can be called after init_log_write