int owl_dsi_init(void) { int data_width; debug("OWL dsi: dsi init\n"); allocate_buf(&dsi_addr, 100, 32); #ifdef CONFIG_OF_CONTROL if (fdtdec_get_dsi_par(&dsi_par)) { printf("OWL dsi: fdt No dsi par\n"); return -1; } #else if (platform_get_lcd_par(&dsi_par)) { printf("OWL dsi: No dsi par\n"); return -1; } #endif if (owl_pwm_backlight_init(&dsi_par.pwm_bl_data)) { printf("OWL dsi: backlight not found\n"); return -1; } data_width = get_dsi_data_width(&dsi_par); owl_display_register(DSI_DISPLAYER,"dsi",&dsi_ops, dsi_par.mode, data_width, 0); return 0; }
superblock* get_super_block(void) { byte* buf = allocate_buf(buf, BLKSIZE); int retval = read_block(SUPER_BLOCK, buf); if(retval != 0) { return NULL; } return (superblock*) buf; }
uint32_t get_free_block_index(void) { byte* buf = allocate_buf(buf, BLKSIZE); int retval = read_block(SUPER_BLOCK, buf); if(retval != 0) { return retval; } return ((superblock*) buf)->free_block_list; }
uint32_t get_root(void) { byte* buf = allocate_buf(buf, BLKSIZE); int retval = read_block(SUPER_BLOCK, buf); if(retval != 0) { return retval; } return ((superblock*) buf)->root_dir; }
static void initialize_function(expression * e) { int i; allocate_buf(e); e->data.func.argv = G_malloc((e->data.func.argc + 1) * sizeof(void *)); e->data.func.argv[0] = e->buf; for (i = 1; i <= e->data.func.argc; i++) { initialize(e->data.func.args[i]); e->data.func.argv[i] = e->data.func.args[i]->buf; } }
int test_large_transfer() { int rc; struct ctx my_ctx; struct ctx *p_ctx = &my_ctx; pthread_t thread; struct rwlargebuf rwbuf; __u64 chunk=2; // do io on last 2 chunks on a plun __u64 buf_size[] = { 0x1000, //4KB 0x4000, //16KB 0x10000, //64KB 0x40000, //256KB 0x800000, //8MB 0x1000000 }; //16MB int i; //Large trasnfer size is for PLUN not Vluns(4K only) as per Jim pid = getpid(); #ifdef _AIX rc = setRUnlimited(); CHECK_RC(rc, "setRUnlimited failed"); #endif rc = ctx_init(p_ctx); CHECK_RC(rc, "Context init failed"); pthread_create(&thread, NULL, ctx_rrq_rx, p_ctx); rc = create_resource(p_ctx,0,DK_UDF_ASSIGN_PATH,LUN_DIRECT); CHECK_RC(rc, "create LUN_DIRECT failed"); p_ctx->st_lba= p_ctx->last_lba +1 -(chunk*p_ctx->chunk_size); if (long_run_enable) p_ctx->st_lba=0; //let do IO on complete plun for (i=0;i< sizeof(buf_size)/sizeof(__u64);i++) { rc = allocate_buf(&rwbuf, buf_size[i]); CHECK_RC(rc, "memory allocation failed"); printf("%d: do large io size=0X%"PRIX64"\n",pid, buf_size[i]); rc = do_large_io(p_ctx, &rwbuf, buf_size[i]); deallocate_buf(&rwbuf); if (rc) break; //get out from here } pthread_cancel(thread); close_res(p_ctx); ctx_close(p_ctx); return rc; }
int test_large_trnsfr_boundary() { int rc; struct ctx my_ctx; struct ctx *p_ctx = &my_ctx; pthread_t thread; struct rwlargebuf rwbuf; __u64 buf_size = 0x1000000; //16MB __u64 chunk = 10; pid = getpid(); #ifdef _AIX system("ulimit -d unlimited"); system("ulimit -s unlimited"); system("ulimit -m unlimited"); #endif rc = ctx_init(p_ctx); CHECK_RC(rc, "Context init failed"); pthread_create(&thread, NULL, ctx_rrq_rx, p_ctx); //do RW last cmd with crossed LBA boundary //i.e. last_lba size is 0x100; //do send rw with 0x10 & cross limit of 0x100 rc = create_resource(p_ctx, 0, DK_UDF_ASSIGN_PATH, LUN_DIRECT); CHECK_RC(rc, "create LUN_DIRECT failed"); rc = allocate_buf(&rwbuf, buf_size); CHECK_RC(rc, "memory allocation failed"); //to make sure last cmd rw beyond boundary p_ctx->st_lba = p_ctx->last_lba - (chunk * p_ctx->chunk_size); p_ctx->st_lba = p_ctx->st_lba +20 ; rc = do_large_io(p_ctx, &rwbuf, buf_size); deallocate_buf(&rwbuf); pthread_cancel(thread); close_res(p_ctx); ctx_close(p_ctx); return rc; }
static void initialize_map(expression * e) { allocate_buf(e); e->data.map.idx = open_map(e->data.map.name, e->data.map.mod, e->data.map.row, e->data.map.col); }
static void initialize_constant(expression * e) { allocate_buf(e); }
int test_ctx_reset() { int rc; struct ctx myctx; struct ctx *p_ctx= &myctx; pthread_t thread; __u64 buf_size = 0x2000000; //32MB __u64 chunk = 10; __u64 stride = 0x1000; struct rwlargebuf rwbuf; int i; pid=getpid(); rc = ctx_init(p_ctx); CHECK_RC(rc, "ctx_init failed"); pthread_create(&thread, NULL, ctx_rrq_rx, p_ctx); rc = create_resource(p_ctx,chunk*p_ctx->chunk_size,DK_UVF_ASSIGN_PATH,LUN_VIRTUAL); CHECK_RC(rc, "create LUN_VIRTUAL failed"); //do bad EA if (1) { debug("%d: ........place bad EA....\n", pid); fill_send_write(p_ctx, 0, pid, stride); for (i = 0; i < NUM_CMDS; i++) { p_ctx->cmd[i].rcb.data_ea = (__u64)0x1234; } bad_address = true; send_cmd(p_ctx); rc = wait_resp(p_ctx); sleep(1); //normal IO bad_address = false; debug("%d: .........after bad EA, do normal IO....\n", pid); rc = do_io(p_ctx, stride); CHECK_RC(rc,"Normal IO failed after bad EA"); //do bad RCB debug("%d: .........place bad RCB....\n", pid); bad_address = true; place_bad_addresses(p_ctx, 1); sleep(2); //normal IO debug("%d: ......after bad RCB, do normal IO....\n", pid); bad_address = false; rc = do_io(p_ctx, stride); CHECK_RC(rc,"Normal IO failed after bad RCB"); #ifdef _AIX rc = setRUnlimited(); CHECK_RC(rc,"setRUnlimited() failed"); #endif } //do large _transfer debug("%d: Do large transfer ....\n", pid); rc = allocate_buf(&rwbuf, buf_size); CHECK_RC(rc, "memory allocation failed"); rc = do_large_io(p_ctx, &rwbuf, buf_size); deallocate_buf(&rwbuf); buf_size = 0x100000; //4k rc = allocate_buf(&rwbuf, buf_size); CHECK_RC(rc, "memory allocation failed"); //normal io debug("%d: after large transfer,do normal IO ....\n", pid); rc = do_io(p_ctx, 0x10000); //rc = do_large_io(p_ctx, &rwbuf, buf_size); CHECK_RC(rc,"Normal IO failed after large transfer"); pthread_cancel(thread); close_res(p_ctx); ctx_close(p_ctx); return rc; }
/// Listener loop. void* FDHTTPServer::listener_loop() { int ret = 0; char* current_data_buf = NULL; int connection_socket = -1; int recv_ret = -1; FDHTTPConnectionPtr current_connection = NULL; struct linger so_linger; so_linger.l_onoff = 1; so_linger.l_linger = 5; pthread_attr_t attr; pthread_t connection_thread; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); is_running_ = true; listener_fd_set_[0].fd = unix_domain_socket_fd_; listener_fd_set_[0].events = POLLIN; while(is_running_) { ret = poll(listener_fd_set_, 1, LISTENER_TIMEOUT); #ifdef DEBUG_HTTP_SERVER fprintf(stdout,"listener poll ...............\n"); #endif if(ret == -1) { if(EINTR == errno) continue; fprintf(stderr,"listener poll error: %s\n", strerror(errno)); break; } if(ret == 0) { // timeout #ifdef DEBUG_HTTP_SERVER fprintf(stdout,"listen timeout.\n"); #endif continue; } if(listener_fd_set_[0].revents & POLLIN) { if(current_data_buf == NULL) { current_data_buf = allocate_buf(); } memset(current_data_buf, 0, max_buffer_size_); // Receive the network socket and data from Unix domain socket. recv_ret = get_fd(unix_domain_socket_fd_, &connection_socket, (void*)current_data_buf, max_buffer_size_-1); if(recv_ret <= 0) { break; } // Avoid the child process references the file descriptor and do not close it. fcntl(connection_socket, F_SETFD, FD_CLOEXEC | fcntl(connection_socket, F_GETFD)); // Set linger ret = setsockopt(connection_socket, SOL_SOCKET, SO_LINGER, (void*) &so_linger, sizeof(so_linger)); if(ret == -1) { fprintf(stderr,"setsockopt (linger) error: %s\n", strerror(errno)); } if(connection_socket <= 0) { continue; } current_data_buf[recv_ret] = '\0'; assert(current_connection == NULL); // Create connection. current_connection = new FDHTTPConnection(http_request_handler_, std::bind(&FDHTTPServer::connection_exit_callback, this, std::placeholders::_1)); current_connection->Init(connection_socket, current_data_buf, max_buffer_size_, recv_ret); if(!is_running_) { close(connection_socket); connection_socket = -1; break; } // Use map to record the connection and data buffer. pthread_mutex_lock(&map_mutex_); assert(con_buf_map_.find(current_connection) == con_buf_map_.end()); con_buf_map_[current_connection] = current_data_buf; pthread_mutex_unlock(&map_mutex_); // Start connection. int rc = pthread_create(&connection_thread, &attr, &FDHTTPServer::start_connection_helper, current_connection); if(rc) { fprintf(stderr,"ERROR: return code from pthread_create() for connection is %d\n", rc); pthread_mutex_lock(&map_mutex_); con_buf_map_.erase(current_connection); pthread_mutex_unlock(&map_mutex_); delete current_connection; current_connection = NULL; close(connection_socket); connection_socket = -1; } current_data_buf = NULL; current_connection = NULL; connection_socket = -1; } } // Reclaim current_data_buf, current_connection etc if(current_connection) { current_connection->Stop(); delete current_connection; current_connection = NULL; } if(current_data_buf) { delete current_data_buf; current_data_buf = NULL; } if(connection_socket > 0) { close(connection_socket); } connection_socket = -1; pthread_attr_destroy(&attr); is_running_ = false; pthread_exit(NULL); }
int sfs_readdir(int fd, char *mem_pointer) { inode directory = get_null_inode(); locations index_block = NULL; uint32_t inode_location = 0; uint32_t i = 0; uint32_t num_locations = 0; int count = 0; byte* buf = NULL; if(fd >= 0 && fd < NUMOFL) { /* Validate the file descriptor */ if(validate_fd(fd) < 0) { /* * file descriptor not found in swoft */ print_error(INVALID_FILE_DESCRIPTOR); return -1; } /* * Retrieve the contents of the directory's index block. Use the Inode * to retrieve the names of the contents. Store the values into * mem_pointer. */ directory = get_swoft_inode(fd); /* If the inode is not a directory return an error */ if(directory.type != 1) { /* * Invalid file type error */ print_error(INVALID_FILE_TYPE); return -1; } /* * Iterate through the index block * when the directory is empty */ index_block = iterate_index(directory.location, NULL); if(index_block == NULL) { /* * Invalid index block */ print_error(INDEX_ALLOCATION_ERROR); return -1; } num_locations = count_files_in_dir(directory.location); if(num_locations < 0) { /* * Invalid index block */ print_error(INDEX_ALLOCATION_ERROR); return -1; } if(num_locations == 0) { /* * Empty Directory Read */ print_error(DIRECTORY_EMPTY); return 0; } int cur_index = get_index_entry(*get_inode(directory.location)); if(num_locations == cur_index) { reset_index_entry(); return 0; } char* name = get_name(index_block[cur_index]); strcpy(mem_pointer, name); /* Update the directory inode date last accessed and write the inode back to disk */ directory.date_last_accessed = time(NULL); /* Get the inode location */ inode_location = get_inode_loc(fd); buf = allocate_buf(buf, BLKSIZE); buf = (byte *) copy_to_buf((byte *) &directory, (byte *) buf, sizeof(inode), BLKSIZE); if(write_block(inode_location, buf) < 0) { free(buf); print_error(DISK_WRITE_ERROR); return -1; } free(buf); /* * return value > 0 for a successful read dir * return value = 0 if there is no contents in dir * return value < 0 for a unsuccessful read dir */ print_error(SUCCESS); return 1; } print_error(UNKNOWN); return -1; }