/** Application callBack: THis the callback that is activated upon the recption of a disk operation from a remote client: There is 2 kinds of requests that are supported by this function: READ and WRITE @param socket_ctx_p: pointer to the af unix socket @param socketId: reference of the socket (not used) @retval : TRUE-> xmit ready event expected @retval : FALSE-> xmit ready event not expected */ void rozofs_storcli_req_rcv_cbk(void *userRef,uint32_t socket_ctx_idx, void *recv_buf) { uint32_t *com_hdr_p; rozofs_rpc_call_hdr_t hdr; int errcode = EINVAL; com_hdr_p = (uint32_t*) ruc_buf_getPayload(recv_buf); com_hdr_p +=1; /* skip the size of the rpc message */ memcpy(&hdr,com_hdr_p,sizeof(rozofs_rpc_call_hdr_t)); scv_call_hdr_ntoh(&hdr); /* ** get the opcode requested and dispatch the processing accordling to that opcode */ switch (hdr.proc) { case STORCLI_READ: rozofs_storcli_read_req_init(socket_ctx_idx,recv_buf,rozofs_storcli_remote_rsp_cbk,0,STORCLI_DO_QUEUE); return; case STORCLI_WRITE: rozofs_storcli_write_req_init(socket_ctx_idx,recv_buf,rozofs_storcli_remote_rsp_cbk); return; default: /* ** Put code here to format a reply with an error message */ rozofs_storcli_reply_error_with_recv_buf(socket_ctx_idx,recv_buf,NULL,rozofs_storcli_remote_rsp_cbk,errcode); return; } return; }
/** * Internal Read procedure That procedure is used when it is required to read the last block before performing the truncate @param working_ctx_p: pointer to the root transaction @retval 0 on success retval < 0 on error (see errno for error details) */ int rozofs_storcli_internal_read_before_truncate_req(rozofs_storcli_ctx_t *working_ctx_p) { storcli_truncate_arg_t *storcli_truncate_rq_p; void *xmit_buf = NULL; storcli_read_arg_t storcli_read_args; storcli_read_arg_t *request = &storcli_read_args; struct rpc_msg call_msg; int bufsize; uint32_t *header_size_p; XDR xdrs; uint8_t *arg_p; storcli_truncate_rq_p = (storcli_truncate_arg_t*)&working_ctx_p->storcli_truncate_arg; /* ** allocated a buffer from sending the request */ xmit_buf = ruc_buf_getBuffer(ROZOFS_STORCLI_NORTH_SMALL_POOL); if (xmit_buf == NULL) { severe(" out of small buffer on north interface "); errno = ENOMEM; goto failure; } /* ** build the RPC message */ request->sid = 0; /* not significant */ request->layout = storcli_truncate_rq_p->layout; request->cid = storcli_truncate_rq_p->cid; request->spare = 0; /* not significant */ memcpy(request->dist_set, storcli_truncate_rq_p->dist_set, ROZOFS_SAFE_MAX*sizeof (uint8_t)); memcpy(request->fid, storcli_truncate_rq_p->fid, sizeof (sp_uuid_t)); request->proj_id = 0; /* not significant */ request->bid = storcli_truncate_rq_p->bid; request->nb_proj = 1; /* ** get the pointer to the payload of the buffer */ header_size_p = (uint32_t*) ruc_buf_getPayload(xmit_buf); arg_p = (uint8_t*)(header_size_p+1); /* ** create the xdr_mem structure for encoding the message */ bufsize = (int)ruc_buf_getMaxPayloadLen(xmit_buf); xdrmem_create(&xdrs,(char*)arg_p,bufsize,XDR_ENCODE); /* ** fill in the rpc header */ call_msg.rm_direction = CALL; /* ** allocate a xid for the transaction */ call_msg.rm_xid = rozofs_tx_get_transaction_id(); call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; /* XXX: prog and vers have been long historically :-( */ call_msg.rm_call.cb_prog = (uint32_t)STORCLI_PROGRAM; call_msg.rm_call.cb_vers = (uint32_t)STORCLI_VERSION; if (! xdr_callhdr(&xdrs, &call_msg)) { /* ** THIS MUST NOT HAPPEN */ errno = EFAULT; severe(" rpc header encode error "); goto failure; } /* ** insert the procedure number, NULL credential and verifier */ uint32_t opcode = STORCLI_READ; uint32_t null_val = 0; XDR_PUTINT32(&xdrs, (int32_t *)&opcode); XDR_PUTINT32(&xdrs, (int32_t *)&null_val); XDR_PUTINT32(&xdrs, (int32_t *)&null_val); XDR_PUTINT32(&xdrs, (int32_t *)&null_val); XDR_PUTINT32(&xdrs, (int32_t *)&null_val); /* ** ok now call the procedure to encode the message */ if (xdr_storcli_read_arg_t(&xdrs,request) == FALSE) { severe(" internal read request encoding error "); errno = EFAULT; goto failure; } /* ** Now get the current length and fill the header of the message */ int position = XDR_GETPOS(&xdrs); /* ** update the length of the message : must be in network order */ *header_size_p = htonl(0x80000000 | position); /* ** set the payload length in the xmit buffer */ int total_len = sizeof(*header_size_p)+ position; ruc_buf_setPayloadLen(xmit_buf,total_len); /* ** Submit the pseudo request */ rozofs_storcli_read_req_init(0,xmit_buf,rozofs_storcli_internal_read_before_truncate_rsp_cbk,(void*)working_ctx_p,STORCLI_DO_NOT_QUEUE); return 0; failure: if (xmit_buf != NULL) ruc_buf_freeBuffer(xmit_buf); return -1; }