void edit_typeset_rep::get_data (new_data& data) { data->style= get_style (); data->init = get_init (); data->fin = get_fin (); data->att = get_att (); }
int dc_close2(int fd) { int res = 0; struct vsp_node *node; int32_t size; #ifdef DC_CALL_TRACE showTraceBack(); #endif /* nothing wrong ... yet */ dc_errno = DEOK; node = delete_vsp_node(fd); if (node == NULL) { /* we have not such file descriptor, so lets give a try to system */ return system_close(fd); } dc_real_fsync( node ); if(node->unsafeWrite) { size = htonl(-1); /* send end of data */ writen(node->dataFd, (char *) &size, sizeof(size), NULL); /* FIXME: error detection missing */ if (get_fin(node) < 0) { dc_debug(DC_ERROR, "dc_close: mover did not FIN the data blocks."); res = -1; } } close_data_socket(node->dataFd); deleteQueue(node->queueID); m_unlock(&node->mux); node_destroy(node); return res; }
off64_t dc_real_lseek(struct vsp_node *node, off64_t offset, int whence) { int64_t off; int32_t lseekmsg[5]; int32_t size; int tmp; int use_ahead = 0; ConfirmationBlock result; if( (node->ahead != NULL) && ( node->ahead->buffer != NULL) && node->ahead->used) { use_ahead = 1; } if( whence == SEEK_SET ) { /* if already at requested position, do nothing */ result.lseek = dc_real_lseek( node, 0, SEEK_CUR ); if ( result.lseek == offset ) { dc_debug(DC_IO, "[%d] SEEK_SET to the current position, skipping", node->dataFd); return offset; } } if( (whence == SEEK_CUR) && (offset == 0) ) { /* position request, do nothing.... */ if( use_ahead && node->ahead->used) { switch( node->whence ) { /* node->ahead->base already contains seek information */ case SEEK_SET: off = node->seek + node->ahead->cur; break; case SEEK_CUR: off = node->ahead->base + node->ahead->cur; break; default: off = node->ahead->base + node->ahead->cur; } }else{ switch( node->whence ) { case SEEK_SET: off = node->seek; break; case SEEK_CUR: off = node->pos + node->seek; break; default: off = node->pos; } } return off; } if( use_ahead ) { dc_real_fsync(node); } /* funish unsafe write operation if node->unsafeWrite flag > 1 : transaction in progress */ if(node->unsafeWrite > 1) { size = htonl(-1); /* send end of data */ writen(node->dataFd, (char *) &size, sizeof(size), NULL); /* FIXME: error detection missing */ if (get_fin(node) < 0) { dc_debug(DC_ERROR, "dc_lseek: mover did not FIN the data block."); dc_errno = DEUOF; return -1; } node->unsafeWrite = 1; } /* to be fast in seek+read, do not realy seeks now. Do it only read calls as SEEK_AND_READ command */ switch (whence) { case SEEK_SET: /* TODO: what happens, if user will requests offset out of file size ?*/ if( use_ahead && ( (off64_t)(node->ahead->base + node->ahead->used) > offset) && (offset >= (off64_t)node->ahead->base) ) { node->ahead->cur = offset - node->ahead->base; dc_debug(DC_IO, "[%d] SEEK_SET inside Read-ahead buffer. Expected position %ld", node->dataFd, node->ahead->base + node->ahead->cur); node->whence = -1; return offset; } if( use_ahead ) { node->ahead->used = 0; node->ahead->cur = 0; node->ahead->base = 0; } node->seek = offset; node->whence = SEEK_SET; dc_debug(DC_IO, "[%d] Expected seek offset: %ld.", node->dataFd, node->seek); return offset; case SEEK_CUR: if(node->whence == -1) { if( use_ahead && (node->ahead->cur + offset >= 0) && (node->ahead->cur + offset <= node->ahead->used ) ) { node->ahead->cur += offset; dc_debug(DC_IO, "[%d] SEEK_CUR inside Read-ahead buffer. Expected position %ld", node->dataFd, node->ahead->base + node->ahead->cur); result.lseek = node->ahead->base + node->ahead->cur; return (off64_t)result.lseek; } } if(use_ahead) { node->seek = offset + node->ahead->cur - node->ahead->used; node->ahead->used = 0; }else{ node->seek += offset; } if(node->whence != SEEK_SET ) { node->whence = SEEK_CUR; result.lseek = node->pos + node->seek; }else{ /* SEEK_SET */ result.lseek = node->seek; } dc_debug(DC_IO, "[%d] SEEK_CUR offset: %ld expected position %ld.", node->dataFd, node->seek, node->pos + node->seek); return (off64_t)result.lseek; case SEEK_END: /* we have to replay sone thing on SEEK_END, so lets make real seek*/ lseekmsg[0] = htonl(16); lseekmsg[1] = htonl(IOCMD_SEEK); lseekmsg[4] = htonl(IOCMD_SEEK_END); break; default: dc_debug(DC_ERROR, "dc_lseek: illegal value of whence parameter [%d].", whence); dc_debug(DC_ERROR, " Valid values are %d ( SEEK_SET), %d (SEEK_CUR), %d (SEEK_END)", SEEK_SET, SEEK_CUR, SEEK_END); errno = EINVAL; return -1; } off = htonll(offset); memcpy( (char *) &lseekmsg[2],(char *) &off, sizeof(off)); tmp = sendDataMessage(node, (char *) lseekmsg, sizeof(lseekmsg), ASCII_NULL, &result); if (tmp != COMM_SENT) { dc_debug(DC_ERROR, "sendDataMessage failed."); return -1; } node->pos = (off64_t)result.lseek; if( node->ahead != NULL ) { node->ahead->cur = 0; node->ahead->used = 0; node->ahead->isDirty = 0; node->ahead->base = 0; } node->whence = -1; return (off64_t)result.lseek; }
int dc_close(int fd) { int res = 0; int tmp; int32_t size; int32_t closemsg[6]; int msglen; struct vsp_node *node; #ifdef DC_CALL_TRACE showTraceBack(); #endif /* nothing wrong ... yet */ dc_errno = DEOK; node = delete_vsp_node(fd); if (node == NULL) { /* we have not such file descriptor, so lets give a try to system */ dc_debug(DC_INFO, "Using system native close for [%d].", fd); return system_close(fd); } if ( node->lcb != NULL ) { dc_lcb_clean( node ); } dc_real_fsync( node ); if(node->unsafeWrite > 1) { size = htonl(-1); /* send end of data */ writen(node->dataFd, (char *) &size, sizeof(size), NULL); /* FIXME: error detection missing */ if (get_fin(node) < 0) { dc_debug(DC_ERROR, "dc_close: mover did not FIN the data blocks."); res = -1; } } if(node->reference == 0 ) { if( (node->sum != NULL) && ( node->sum->isOk == 1 ) ) { closemsg[0] = htonl(20); closemsg[2] = htonl(12); closemsg[3] = htonl(DCAP_DATA_SUM); closemsg[4] = htonl(node->sum->type); closemsg[5] = htonl(node->sum->sum); msglen = 6; dc_debug(DC_INFO, "File checksum is: %u", node->sum->sum); }else{ closemsg[0] = htonl(4); msglen = 2; } closemsg[1] = htonl(IOCMD_CLOSE); /* actual command */ dc_debug(DC_IO, "Sending CLOSE for fd:%d ID:%d.", node->dataFd, node->queueID); check_timeout_envar(); dcap_set_alarm(closeTimeOut > 0 ? closeTimeOut : DCAP_IO_TIMEOUT/4); tmp = sendDataMessage(node, (char *) closemsg, msglen*sizeof(int32_t), ASCII_OK, NULL); /* FIXME: error detection missing */ if( tmp < 0 ) { dc_debug(DC_ERROR, "sendDataMessage failed."); /* ignore close errors if file was open for read */ if(node->flags & O_WRONLY) { res = -1; } if(isIOFailed) { isIOFailed = 0; /* command line dwon */ if(!ping_pong(node)) { /* remove file descriptor from the list of control lines in use */ lockMember(); deleteMemberByValue(node->fd); unlockMember(); pollDelete(node->fd); close_control_socket(node->fd, node->tunnel); } } } dcap_set_alarm(0); deleteQueue(node->queueID); } /* * Even if there is still a reference to the dcap session, * we have to close local socket descriptor. */ close_data_socket(node->dataFd); node_destroy(node); return res; }
ssize_t dc_real_write( struct vsp_node *node, const void *buff, size_t buflen) { int32_t writemsg[5]; int tmp; int32_t datamsg[2]; int32_t size; int64_t offt; int msglen; size_t len; size_t dataLen; int use_io_buf = 0; size_t wr_buffer = 0; if( (node->ahead == NULL) && ( getenv("DCACHE_WRBUFFER") != NULL ) ) { dc_debug(DC_INFO, "Switching on write buffer."); if(getenv("DCACHE_WA_BUFFER") != NULL) { wr_buffer = atoi( getenv("DCACHE_WA_BUFFER") ); } dc_setNodeBufferSize(node, wr_buffer == 0 ? IO_BUFFER_SIZE : wr_buffer); } if( (node->ahead != NULL) && ( node->ahead->buffer != NULL) ) { use_io_buf = 1; } if( use_io_buf ) { if( ! node->ahead->isDirty ) { if( node->ahead->used ) { switch( node->whence ){ case SEEK_SET: break; case SEEK_CUR: break; default: node->whence = SEEK_CUR; node->seek = -(node->ahead->used - node->ahead->cur); break; } } /* keep current position, including seeks */ node->ahead->base = dc_real_lseek(node, (off64_t)0, SEEK_CUR); node->ahead->isDirty = 1; node->ahead->cur = 0; node->ahead->used = 0; } len = node->ahead->size - node->ahead->cur; if( buflen && ( len > buflen ) ) { memcpy( node->ahead->buffer +node->ahead->cur , buff, buflen ); dc_debug( DC_IO, "[%d] Filling %ld bytes into IO buffer. Available %ld", node->dataFd, buflen, len - buflen); node->ahead->cur += buflen; if( node->ahead->cur > node->ahead->used ) { node->ahead->used = node->ahead->cur; } return buflen; } if( !buflen ) { dc_debug(DC_IO, "[%d] Flushing %d bytes of IO buffer.", node->dataFd, node->ahead->cur); } } /* node->unsafeWrite == 0 : regular write operation node->unsafeWrite == 1 : unsafeWrite, IO request not sended yet node->unsafeWrite >1 : unsafeWrite, IO request sended */ /* do following part allways for regular write and once of unsafe write */ if(!node->unsafeWrite || (node->unsafeWrite == 1 ) ){ if(node->whence == -1) { writemsg[0] = htonl(4); writemsg[1] = htonl(IOCMD_WRITE); msglen = 2; dc_debug(DC_IO,"[%d] Sending IOCMD_WRITE.", node->dataFd); }else{ /* in case of seeks and write, there is no way to keep track of check summ */ if( node->sum != NULL ) { node->sum->isOk = 0 ; } writemsg[0] = htonl(16); writemsg[1] = htonl(IOCMD_SEEK_WRITE); offt = htonll(node->seek); memcpy( (char *) &writemsg[2],(char *) &offt, sizeof(offt)); if(node->whence == SEEK_SET) { writemsg[4] = htonl(IOCMD_SEEK_SET); }else{ writemsg[4] = htonl(IOCMD_SEEK_CURRENT); } dc_debug(DC_IO,"[%d] Sending IOCMD_SEEK_WRITE.", node->dataFd); msglen = 5; } tmp = sendDataMessage(node, (char *) writemsg, msglen*sizeof(int32_t), ASCII_NULL, NULL); if (tmp != COMM_SENT) { m_unlock(&node->mux); dc_debug(DC_ERROR, "sendDataMessage failed."); return -1; } datamsg[0] = htonl(4); datamsg[1] = htonl(IOCMD_DATA); tmp = writen(node->dataFd, (char *) datamsg, sizeof(datamsg), NULL); /* do this part only once if unsafeWrite requaried */ if(node->unsafeWrite) { node->unsafeWrite = 2; } } dataLen = buflen; if( use_io_buf ) dataLen += node->ahead->cur; size = htonl(dataLen); writen(node->dataFd, (char *) &size, sizeof(size), NULL); /* send data size */ if( use_io_buf ) { writen(node->dataFd, (const char *)node->ahead->buffer, node->ahead->cur, NULL); /* send data */ } writen(node->dataFd, (const char *)buff, buflen, NULL); /* send data */ /* update the ckecksum */ if( (node->sum != NULL ) && (node->sum->isOk == 1) ) { if( use_io_buf ) { update_checkSum(node->sum, (unsigned char *)node->ahead->buffer, node->ahead->cur); } /* * we do not need to calculate checksum if buff == NULL ( flush operation ) * if we do so, then check sum well be reseted to default value; */ if( buff != NULL ) { update_checkSum(node->sum, (unsigned char *)buff, buflen); } } if(!node->unsafeWrite) { size = htonl(-1); /* send end of data */ writen(node->dataFd, (char *) &size, sizeof(size), NULL); /* FIXME: error detection missing */ if (get_fin(node) < 0) { dc_debug(DC_ERROR, "dc_write: mover did not FIN the data block."); return -1; } } if( node->whence == SEEK_SET ) { node->pos = dataLen + node->seek; } else { /* SEEK_CUR */ node->pos += (node->seek + dataLen); } node->seek = 0; node->whence = -1; if( use_io_buf ) { node->ahead->cur = 0; node->ahead->used = 0; node->ahead->base = 0; node->ahead->isDirty = 0; } #ifndef WIN32 dc_debug(DC_IO, "[%d] Expected position: %lld @ %ld bytes written.", node->dataFd, (long long int)node->pos, dataLen); #else dc_debug(DC_IO, "[%d] Expected position: %lld @ %ld bytes written.", node->dataFd, (long int)node->pos, dataLen); #endif return buflen; }