/* * getdirentries should return -1 and set errno to EINVAL when the size * specified as an argument is too small to contain at least one entry * (see bugzilla ticket 12229) */ int t56(char *name) { int fd; size_t nbytes; off_t basep = 0; long rc = 0; cfs_dirent_t dir; ENTER("getdirentries should fail if nbytes is too small"); /* Set count to be very small. The result should be EINVAL */ nbytes = 8; /* open the directory and call getdirentries */ fd = t_opendir(lustre_path); rc = getdirentries(fd, (char *)&dir, nbytes, &basep); if (rc != -1) { printf("Test failed: getdirentries returned %lld\n", (long long)rc); t_close(fd); return -1; } if (errno != EINVAL) { printf("Test failed: getdirentries returned %lld but errno is " "set to %d (should be EINVAL)\n", (long long)rc, errno); t_close(fd); return -1; } t_close(fd); LEAVE(); }
/* * Autor: Bartosz Fr¹ckowiak * wwww: http://www.batas2.boo.pl/ */ int main(int argc, char *argv[]) { int fd = -1, sd = -1; int port = -1; struct t_call *call; if(argc != 2){ printf("Sposob uruchomienia: %s <port>\n", argv[0]); exit(1); }else{ port = atoi(argv[1]); } fd = local_work(port, &call); while (1) { if (t_listen(fd, call) < 0) error("serwer->t_listen", fd); if ((sd = accept_client(fd, call)) != -1) serwer_work(sd); } if (t_close(fd) < 0) error("serwer->t_close", fd, sd); if (t_close(sd) < 0) error("serwer->serwer_wrok->t_close", fd, sd); }
value xti_cots_connect (value device, value addr) { CAMLparam2(device,addr); int fd; char *dev; struct t_call sndcall; char abuf[ABUFLEN]; int k; dev = String_val(device); if ((fd = t_open(dev, O_RDWR, (struct t_info *) NULL)) == -1) { xti_error(-1, "t_open"); } if (t_bind(fd, (struct t_bind *) NULL, (struct t_bind *) NULL) == -1) { xti_error(fd, "t_bind"); } sndcall.opt.buf = NULL; sndcall.opt.len = 0; sndcall.opt.maxlen = 0; sndcall.udata.buf = NULL; sndcall.udata.len = 0; sndcall.udata.maxlen = 0; sndcall.addr.buf = abuf; sndcall.addr.len = 0; sndcall.addr.maxlen = ABUFLEN; sndcall.sequence = 0; if (string_length(addr) > sndcall.addr.maxlen) { t_close(fd); invalid_argument("cots_connect: address too long"); }; sndcall.addr.len = string_length(addr); for (k=0; k<string_length(addr); k++) { sndcall.addr.buf[k] = Byte(addr,k); }; if (t_connect( fd, &sndcall, (struct t_call *) NULL) == -1 ) { xti_error(fd, "t_connect"); } if (ioctl(fd, I_PUSH, "tirdwr") == -1) { int e = errno; t_close(fd); unix_error(e, "ioctl(I_PUSH)", Nothing); } CAMLreturn(Val_int(fd)); }
static XtransConnInfo TRANS(TLIOpenCOTSClient)(Xtransport *thistrans, char *protocol, char *host, char *port) { XtransConnInfo ciptr; int i; prmsg(2,"TLIOpenCOTSClient(%s,%s,%s)\n", protocol, host, port ); if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 ) { prmsg(1,"TLIOpenCOTSClient: Unable to determine device for %s\n", thistrans->TransName); return NULL; } if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL ) { prmsg(1,"TLIOpenCOTSClient: Unable to open device for %s\n", thistrans->TransName); return NULL; } if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 ) { prmsg(1, "TLIOpenCOTSClient: ...TLITLIBindLocal() failed: %d\n", errno); t_close(ciptr->fd); free(ciptr); return NULL; } if( TRANS(TLIGetAddr)(ciptr) < 0 ) { prmsg(1, "TLIOpenCOTSClient: ...TLIGetAddr() failed: %d\n", errno); t_close(ciptr->fd); free(ciptr); return NULL; } /* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */ ciptr->index = i; return ciptr; }
int op_write(const int extra_flag) { // open int ret = TFS_ERROR; int fd = 0; if (extra_flag == T_LARGE) { // 打开一个tfs文件写,为了断点续传,必须传入一个key参数,来标识此次大文件的写。 // 一次写失败后,再次传入相同的key写,tfsclient会根据key找到前一次已经写完成的 // 部分进行重用。 // 为了确保key的唯一性,当前tfsclient接受的key必须是本地文件系统上存在的一个文件路径, // 该key文件的内容无所谓. fd = t_open(NULL, ".jpg", T_WRITE|extra_flag, key_file); } else { fd = t_open(NULL, ".jpg", T_WRITE|extra_flag, NULL); } if (fd <= 0) { printf("get fd for write fail, ret: %d \n", fd); return ret; } // lseek then write and pwrite not supported now // write int64_t len = 0; char buf[OP_SIZE]; if ((len = t_write(fd, buf, OP_SIZE)) != OP_SIZE) { printf("write data to tfs fail, ret: %" PRI64_PREFIX "d\n", len); // write fail, just close fd t_close(fd, NULL, 0); return ret; } // write success, close fd and get tfs file name if ((ret = t_close(fd, tfs_name, TFS_FILE_LEN)) != TFS_SUCCESS) { printf("close tfs file fail, ret: %d\n", ret); return ret; } return ret; }
/* **************************************************************** * Abre a conexão (parte do servidor) * **************************************************************** */ int tcp_open (int port) { int fd; T_BIND req; INADDR req_addr; if ((fd = t_open (tcpdevname, O_RDWR, (T_INFO *)NULL)) < 0) return (-1); /* * Preenche a estrutura T_BIND */ FILL_INADDR (req_addr, 0, port); FILL_NETBUF (req.addr, &req_addr, sizeof (req_addr)); req.qlen = MAX_LISTEN_QLEN; if (t_bind (fd, &req, (T_BIND *)NULL) < 0) goto bad; if (set_param (fd) < 0) goto bad; listen_port = port; return (fd); bad: t_close (fd); return (-1); } /* end tcp_open */
bool c_XMLReader::t_open(const String& uri, const String& encoding /*= null_string*/, int64_t options /*= 0*/) { if (m_ptr) { t_close(); } if (uri.empty()) { raise_warning("Empty string supplied as input"); return false; } String valid_file = _xmlreader_get_valid_file_path(uri.c_str()); xmlTextReaderPtr reader = NULL; if (!valid_file.empty()) { reader = xmlReaderForFile(valid_file.data(), encoding.data(), options); } if (reader == NULL) { raise_warning("Unable to open source data"); return false; } m_ptr = reader; return true; }
/* **************************************************************** * Inicia um cliente * **************************************************************** */ int tcp_connect (int port, const char *name) { int fd; T_BIND bind; T_CALL call; INADDR bind_addr, addr; IPADDR remote_ip_addr; if ((fd = t_open (tcpdevname, O_RDWR, (T_INFO *)NULL)) < 0) return (-1); /* * Associa um endereço local. */ FILL_INADDR (bind_addr, 0, 0); FILL_NETBUF (bind.addr, &bind_addr, sizeof (bind_addr)); bind.qlen = 0; /* Não vamos dar "t_listen" nesta conexão */ if (t_bind (fd, &bind, (T_BIND *)NULL) < 0) goto bad; if (set_param (fd) < 0) goto bad; /* * Converte o nome da estação remota em um endereço IP. */ if (name != NOSTR && name[0] != '\0') { remote_ip_addr = t_node_to_addr (fd, name, NULL); if (remote_ip_addr == -1) goto bad; } else { remote_ip_addr = LOCAL_IP_ADDR; } /* * Preenche a estrutura T_CALL: só o membro addr é relevante. */ FILL_INADDR (addr, remote_ip_addr, port); FILL_NETBUF (call.addr, &addr, sizeof (addr)); FILL_NETBUF (call.opt, NULL, 0); FILL_NETBUF (call.udata, NULL, 0); /* * Tenta estabeler a conexão com a estação remota. */ if (t_connect (fd, &call, (T_CALL *)NULL) < 0) goto bad; return (fd); bad: t_close (fd); return (-1); } /* end tcp_connect */
int t13(char *name) { char dir[MAX_PATH_LENGTH] = ""; char path[1024]; char buf[1024]; const int nfiles = 20; char *prefix = "test13_filename_prefix_"; int fd, i; ENTER("multiple entries directory readdir"); snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path); t_mkdir(dir); printf("Creating %d files...\n", nfiles); for (i = 0; i < nfiles; i++) { sprintf(path, "%s%s%05d", dir, prefix, i); t_touch(path); } fd = t_opendir(dir); t_ls(fd, buf, sizeof(buf)); t_close(fd); printf("Cleanup...\n"); for (i = 0; i < nfiles; i++) { sprintf(path, "%s%s%05d", dir, prefix, i); t_unlink(path); } t_rmdir(dir); LEAVE(); }
int t6b(char *name) { char path[MAX_PATH_LENGTH] = ""; char path2[MAX_PATH_LENGTH] = ""; char cwd[MAX_PATH_LENGTH] = ""; char *tmp; int fd; ENTER("symlink + chdir and open"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path); snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path); t_mkdir(path); t_symlink(path, path2); t_check_stat(path2, NULL); tmp = getcwd(cwd, MAX_PATH_LENGTH); if (tmp == NULL) { fprintf(stderr, "current path too long to fit in " "MAX_PATH_LENGTH?\n"); LEAVE(); } t_chdir(path2); t_chdir(cwd); t_rmdir(path); t_touch(path); fd = t_open(path2); t_close(fd); t_unlink(path2); t_unlink(path); LEAVE(); }
bool c_XMLReader::t_open(CStrRef uri, CStrRef encoding /*= null_string*/, int64 options /*= 0*/) { INSTANCE_METHOD_INJECTION_BUILTIN(XMLReader, XMLReader::open); if (m_ptr) { t_close(); } if (uri.empty()) { raise_warning("Empty string supplied as input"); return false; } String valid_file = _xmlreader_get_valid_file_path(uri.c_str()); xmlTextReaderPtr reader = NULL; if (!valid_file.empty()) { reader = xmlReaderForFile(valid_file.data(), encoding.data(), options); } if (reader == NULL) { raise_warning("Unable to open source data"); return false; } m_ptr = reader; return true; }
enum proto_accept_error proto_accept_connection(int listener_fd, int *read_fd, int *write_fd, const char **name) { int timeout = server_int_option("name_lookup_timeout", 5); int fd; struct sockaddr_in *addr = (struct sockaddr_in *) call->addr.buf; static Stream *s = 0; if (!s) s = new_stream(100); fd = t_open((void *) "/dev/tcp", O_RDWR, 0); if (fd < 0) { if (t_errno == TSYSERR && errno == EMFILE) return PA_FULL; else { log_ti_error("Opening endpoint for new connection"); return PA_OTHER; } } if (t_bind(fd, 0, 0) < 0) { log_ti_error("Binding endpoint for new connection"); t_close(fd); return PA_OTHER; } if (t_listen(listener_fd, call) < 0) { log_ti_error("Accepting new network connection"); t_close(fd); return PA_OTHER; } if (t_accept(listener_fd, fd, call) < 0) { log_ti_error("Accepting new network connection"); t_close(fd); return PA_OTHER; } if (!set_rw_able(fd)) { t_close(fd); return PA_OTHER; } *read_fd = *write_fd = fd; stream_printf(s, "%s, port %d", lookup_name_from_addr(addr, timeout), (int) ntohs(addr->sin_port)); *name = reset_stream(s); return PA_OKAY; }
void t1() { const int bufsize = 4096; char *path = "/mnt/lustre/rp_ost_t1_file"; char buf[bufsize]; int fd, i, j; ENTRY("open-write-close-open-failover-read (no ping involved)"); printf("create/open file...\n"); t_touch(path); fd = t_open(path); printf("write file...\n"); for (i = 0; i < 20; i++) { memset(buf, i, bufsize); if (write(fd, buf, bufsize) != bufsize) { perror("write error"); exit(-1); } } printf("close/reopen...\n"); t_close(fd); fd = t_open(path); lseek(fd, 0, SEEK_SET); printf("OST failover...\n"); replay_barrier(); mds_failover(); printf("read & verify...\n"); for (i = 0; i < 20; i++) { memset(buf, -1, bufsize); if (read(fd, buf, bufsize) != bufsize) { perror("read error after failover"); exit(-1); } for (j = 0; j < bufsize; j++) { if (buf[j] != i) { printf("verify error after failover\n"); exit(-1); } } } t_close(fd); t_unlink(path); LEAVE(); }
/* **************************************************************** * Aborta a conexão * **************************************************************** */ int tcp_abort (int fd) { if (t_snddis (fd, (T_CALL *)NULL) < 0) return (-1); return (t_close (fd)); } /* end tcp_abort */
void t_drop (int j) { if (debug_level > 2) log_querydrop (t[j].active); errno = error_pipe; t_close (j); }
static int TRANS(TLIClose)(XtransConnInfo ciptr) { prmsg(2, "TLIClose(%x->%d)\n", ciptr, ciptr->fd); t_unbind(ciptr->fd); return (t_close(ciptr->fd)); }
void xti_error(int fd, char *cmdname) { char error[100]; int n; snprintf(error, 100, "XTI error: %s", t_strerror(t_errno)); n = t_errno == TSYSERR ? errno : 0; if (fd >= 0) t_close(fd); unix_error(n, cmdname, copy_string(error)); }
/* protocol independent network fd close routine */ void close_net_fd(instance_t *inst, int fd) { debug_msg("Entering close_net_fd: inst: %s, fd: %d", inst->fmri, fd); if (inst->config->basic->istlx) { (void) t_close(fd); } else { (void) close(fd); } }
void t_new (void) { int i = 0, j = 0; struct tcpclient *x = NULL; for (j = 0; j < MAXTCP; ++j) if (!t[j].active) break; if (j >= MAXTCP) { j = 0; for (i = 1; i < MAXTCP; ++i) if (taia_less (&t[i].start, &t[j].start)) j = i; errno = error_timeout; if (t[j].state == 0) t_drop (j); else t_close (j); } x = t + j; taia_now (&x->start); x->tcp = socket_accept4 (tcp53, x->ip, &x->port); if (x->tcp == -1) return; if (x->port < 1024 && x->port != 53) { close (x->tcp); return; } if (!okclient (x->ip)) { close (x->tcp); return; } if (ndelay_on (x->tcp) == -1) { close(x->tcp); return; } /* Linux bug */ x->active = 1; ++tactive; x->state = 1; t_timeout (j); if (debug_level > 2) log_tcpopen (x->ip, x->port); }
static int TRANS(TLICloseForCloning)(XtransConnInfo ciptr) { /* * Don't unbind. */ prmsg(2, "TLICloseForCloning(%x->%d)\n", ciptr, ciptr->fd); return (t_close(ciptr->fd)); }
void t_respond(int j) { if (!t[j].active) return; log_querydone(&t[j].active,response_len); response_id(t[j].id); t[j].len = response_len + 2; t_free(j); t[j].buf = alloc(response_len + 2); if (!t[j].buf) { t_close(j); return; } uint16_pack_big(t[j].buf,response_len); byte_copy(t[j].buf + 2,response_len,response); t[j].pos = 0; t[j].state = -1; }
int t15(char *name) { char file[MAX_PATH_LENGTH] = ""; int fd; ENTER("open-stat-close"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path); t_touch(file); fd = t_open(file); t_check_stat(file, NULL); t_close(fd); t_unlink(file); LEAVE(); }
int t12(char *name) { char dir[MAX_PATH_LENGTH] = ""; char buf[1024*128]; int fd; ENTER("empty directory readdir"); snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path); t_mkdir(dir); fd = t_opendir(dir); t_ls(fd, buf, sizeof(buf)); t_close(fd); t_rmdir(dir); LEAVE(); }
/* **************************************************************** * Encerra a conexão * **************************************************************** */ int tcp_close (int fd) { if (t_getstate (fd) == T_DATAXFER) { if (t_sndrel (fd) < 0) return (-1); if (t_rcvrel (fd) < 0) return (-1); } return (t_close (fd)); } /* end tcp_close */
void t6() { char *path="/mnt/lustre/f6"; int fd; ENTRY("open |X| close"); replay_barrier(); t_create(path); fd = t_open(path); sleep(1); mds_failover(); t_check_stat(path, NULL); t_close(fd); t_unlink(path); LEAVE(); }
void t0() { const int bufsize = 4096; char *path = "/mnt/lustre/rp_ost_t0_file"; char buf[bufsize]; int fd, i, j, rc; ENTRY("open-failover-write-verification (no ping involved)"); printf("create/open file...\n"); t_touch(path); fd = t_open(path); printf("OST failover...\n"); replay_barrier(); mds_failover(); printf("write file...\n"); for (i = 0; i < 20; i++) { memset(buf, i, bufsize); if ((rc = write(fd, buf, bufsize)) != bufsize) { perror("write error after failover"); printf("i = %d, rc = %d\n", i, rc); exit(-1); } } /* verify */ printf("read & verify...\n"); lseek(fd, 0, SEEK_SET); for (i = 0; i < 20; i++) { memset(buf, -1, bufsize); if ((rc = read(fd, buf, bufsize)) != bufsize) { perror("read error rc"); printf("i = %d, rc = %d\n", i, rc); exit(-1); } for (j = 0; j < bufsize; j++) { if (buf[j] != i) { printf("verify error!\n"); exit(-1); } } } t_close(fd); t_unlink(path); LEAVE(); }
/* * Create the client des authentication object. Obsoleted by * authdes_seccreate(). */ AUTH * authdes_create(char *servername, uint_t window, struct sockaddr_in *syncaddr, des_block *ckey) { char *hostname = NULL; if (syncaddr) { /* * Change addr to hostname, because that is the way * new interface takes it. */ struct netconfig *nconf; struct netbuf nb_syncaddr; struct nd_hostservlist *hlist; AUTH *nauth; int fd; struct t_info tinfo; if ((nconf = __rpc_getconfip("udp")) == NULL && (nconf = __rpc_getconfip("tcp")) == NULL) goto fallback; /* Transform sockaddr_in to netbuf */ if ((fd = t_open(nconf->nc_device, O_RDWR, &tinfo)) == -1) { (void) freenetconfigent(nconf); goto fallback; } (void) t_close(fd); nb_syncaddr.maxlen = nb_syncaddr.len = __rpc_get_a_size(tinfo.addr); nb_syncaddr.buf = (char *)syncaddr; if (netdir_getbyaddr(nconf, &hlist, &nb_syncaddr)) { (void) freenetconfigent(nconf); goto fallback; } if (hlist && hlist->h_cnt > 0 && hlist->h_hostservs) hostname = hlist->h_hostservs->h_host; nauth = authdes_seccreate(servername, window, hostname, ckey); (void) netdir_free((char *)hlist, ND_HOSTSERVLIST); (void) freenetconfigent(nconf); return (nauth); } fallback: return (authdes_seccreate(servername, window, hostname, ckey)); }
/* * A common server create routine */ static SVCXPRT * svc_com_create(int fd, uint_t sendsize, uint_t recvsize, char *netid) { struct netconfig *nconf; SVCXPRT *svc; int madefd = FALSE; int port; int res; if ((nconf = __rpc_getconfip(netid)) == NULL) { (void) syslog(LOG_ERR, "Could not get %s transport", netid); return (NULL); } if (fd == RPC_ANYSOCK) { fd = t_open(nconf->nc_device, O_RDWR, NULL); if (fd == -1) { char errorstr[100]; __tli_sys_strerror(errorstr, sizeof (errorstr), t_errno, errno); (void) syslog(LOG_ERR, "svc%s_create: could not open connection : %s", netid, errorstr); (void) freenetconfigent(nconf); return (NULL); } madefd = TRUE; } res = __rpc_bindresvport(fd, NULL, &port, 8); svc = svc_tli_create(fd, nconf, NULL, sendsize, recvsize); (void) freenetconfigent(nconf); if (svc == NULL) { if (madefd) (void) t_close(fd); return (NULL); } if (res == -1) /* LINTED pointer cast */ port = (((struct sockaddr_in *)svc->xp_ltaddr.buf)->sin_port); svc->xp_port = ntohs(port); return (svc); }
int op_read(const int extra_flag) { // open int fd = t_open(tfs_name, ".jpg", T_READ|extra_flag, NULL); if (fd <= 0) { printf("get fd for read fail, ret: %d \n", fd); return TFS_ERROR; } // read int64_t len = 0; char buf[OP_SIZE]; if ((len = t_read(fd, buf, OP_SIZE/2)) < 0) { printf("read data fail, ret: %" PRI64_PREFIX "d\n", len); return TFS_ERROR; } // lseek then read t_lseek(fd, OP_SIZE/3, T_SEEK_CUR); // read if ((len = t_read(fd, buf, OP_SIZE/2)) < 0) { printf("lseek and read data fail, ret: %" PRI64_PREFIX "d\n", len); return TFS_ERROR; } // pread if ((len = t_pread(fd, buf, OP_SIZE/2, OP_SIZE/3)) < 0) { printf("pread data fail, ret: %" PRI64_PREFIX "d\n", len); return TFS_ERROR; } // close t_close(fd, NULL, 0); return TFS_SUCCESS; }
static void clnt_dg_destroy(CLIENT *cl) { /* LINTED pointer alignment */ struct cu_data *cu = (struct cu_data *)cl->cl_private; int cu_fd = cu->cu_fd; (void) rpc_fd_lock(dgtbl, cu_fd); if (cu->cu_closeit) (void) t_close(cu_fd); XDR_DESTROY(&(cu->cu_outxdrs)); cu->cu_tr_data->udata.buf = NULL; (void) t_free((char *)cu->cu_tr_data, T_UNITDATA); free(cu->cu_raddr.buf); free(cu); if (cl->cl_netid && cl->cl_netid[0]) free(cl->cl_netid); if (cl->cl_tp && cl->cl_tp[0]) free(cl->cl_tp); free(cl); rpc_fd_unlock(dgtbl, cu_fd); }