void ef_driver_save_fd(void) { int rc = 0; ef_driver_handle fd; enum oo_device_type dev_type; for( dev_type = 0; dev_type < OO_MAX_DEV; dev_type++ ) { if( ! fd_is_saved[dev_type] ) { rc = ef_onload_driver_open(&fd, dev_type, 1); if( rc == 0 ) { saved_fd[dev_type] = fd; fd_is_saved[dev_type] = 1; LOG_NV(ci_log("%s: Saved fd %d %s for cloning", __func__, (int)fd, oo_device_name[dev_type])); if( oo_st_rdev[dev_type] <= 0 ) { struct stat st; fstat(fd, &st); oo_st_rdev[dev_type] = st.st_rdev; } } else { ci_log("%s: failed to open %s - rc=%d", __func__, oo_device_name[dev_type], rc); } } } }
void citp_log_fn_drv(const char* msg) { if( citp.log_fd < 0 ) { if( ef_onload_driver_open(&citp.log_fd, OO_STACK_DEV, 1) ) return; if( citp_fdtable.table ) citp_fdtable.table[citp.log_fd].fdip=fdi_to_fdip(&citp_the_reserved_fd); /* just to be sure: */ ci_sys_fcntl(citp.log_fd, F_SETFD, FD_CLOEXEC); } my_syscall3(ioctl, citp.log_fd, OO_IOC_PRINTK, (long) msg); }
/* SIG_DFL simulator for signals like SIGINT, SIGTERM: it is postponed * properly to safe shared stacks. */ static void citp_signal_terminate(int signum, siginfo_t *info, void *context) { int fd; int rc; /* get any Onload fd to call ioctl */ rc = ef_onload_driver_open(&fd, OO_STACK_DEV, 1); /* Die now: * _exit sets incorrect status in waitpid(), so we should try to exit via * signal. Use _exit() if there is no other way. */ if( rc == 0 ) oo_resource_op(fd, OO_IOC_DIE_SIGNAL, &signum); else _exit(128 + signum); }
dev_t oo_onloadfs_dev_t(void) { static ci_uint32 onloadfs_dev_t = 0; if( onloadfs_dev_t == 0 ) { int fd; if( ef_onload_driver_open(&fd, OO_STACK_DEV, 1) != 0 ) { fprintf(stderr, "%s: Failed to open /dev/onload\n", __FUNCTION__); return 0; } if( ci_sys_ioctl(fd, OO_IOC_GET_ONLOADFS_DEV, &onloadfs_dev_t) != 0 ) { LOG_E(ci_log("%s: Failed to find onloadfs dev_t", __FUNCTION__)); } ci_sys_close(fd); } return onloadfs_dev_t; }
void citp_oo_get_cpu_khz(ci_uint32* cpu_khz) { ef_driver_handle fd; /* set up a constant value for the case everything goes wrong */ *cpu_khz = 1000; if( ef_onload_driver_open(&fd, OO_STACK_DEV, 1) != 0 ) { fprintf(stderr, "%s: Failed to open /dev/onload\n", __FUNCTION__); ci_get_cpu_khz(cpu_khz); return; } if( ci_sys_ioctl(fd, OO_IOC_GET_CPU_KHZ, cpu_khz) != 0 ) { Log_E(log("%s: Failed to query cpu_khz", __FUNCTION__)); ci_get_cpu_khz(cpu_khz); } ef_onload_driver_close(fd); }