/* * Sends a data-product to an LDM using the LDM-5 messages COMINGSOON and * BLOCKDATA. * * Arguments: * proxy Pointer to the LDM proxy data-structure. * info Pointer to the data-product's metadata. * datap Pointer to the data-product's data. * Returns: * 0 Success. * LP_UNWANTED Data-product was unwanted. * LP_TIMEDOUT The RPC call timed-out. "log_start()" called. * LP_RPC_ERROR RPC error. "log_start()" called. * LP_LDM_ERROR LDM error. "log_start()" called. */ static LdmProxyStatus my_csbd_5( LdmProxy* const proxy, product* const product) { CLIENT* const clnt = proxy->clnt; LdmProxyStatus status = 0; /* success */ ldm_replyt reply; prod_info* const info = &product->info; memset(&reply, 0, sizeof(ldm_replyt)); status = my_comingsoon_5(proxy, info, DBUFMAX, &reply); if (0 == status) { if (reply.code != OK) { if (reply.code == DONT_SEND) { status = LP_UNWANTED; } else { LOG_START2("send_5: %s: %s", info->ident, s_ldm_errt(reply.code)); status = LP_LDM_ERROR; } } else { size_t unsent = info->sz; char* data = product->data; datapkt pkt; pkt.signaturep = &info->signature; pkt.pktnum = 0; while (unsent > 0) { size_t nsend = DBUFMAX < unsent ? DBUFMAX : unsent; pkt.data.dbuf_len = (u_int)nsend; pkt.data.dbuf_val = data; status = my_blkdata_5(proxy, &pkt, &reply); if (0 != status) { getStatus(proxy, "BLOCKDATA_5", info); break; } else if (reply.code != OK) { LOG_START1("Unexpected reply from LDM: %s", s_ldm_errt(reply.code)); status = LP_LDM_ERROR; break; } pkt.pktnum++; data += nsend; unsent -= nsend; } } /* reply.code == OK */ } /* OK COMINGSOON */ return status; }
/* * Send a product from file-descriptor to clnt using LDM-5 protocol. */ static void send_product_5(CLIENT *clnt, int fd, prod_info *infop) { static ldm_replyt reply; enum clnt_stat rpc_stat; datapkt pkt; ssize_t unsent; ssize_t nread; char buf[DBUFMAX]; rpc_stat = my_comingsoon_5(clnt, infop, DBUFMAX, &reply); if(rpc_stat != RPC_SUCCESS) { uerror("send_product_5: %s %s", infop->ident, clnt_sperrno(rpc_stat)); return; } /* else */ if(reply.code != OK) { if(reply.code == DONT_SEND) uinfo("send_product_5: %s: %s", infop->ident, s_ldm_errt(reply.code)); else uerror("send_product_5: %s: %s", infop->ident, s_ldm_errt(reply.code)); return; } pkt.signaturep = &infop->signature; pkt.pktnum = 0; for(unsent = (ssize_t)infop->sz; unsent > 0; unsent -= nread ) { nread = read(fd, buf, DBUFMAX); if(nread <= 0) { serror("read: %s (seqno %d)", infop->ident, infop->seqno); break; } /* else */ pkt.data.dbuf_len = (u_int)nread; pkt.data.dbuf_val = buf; rpc_stat = my_blkdata_5(clnt, &pkt, &reply); if(rpc_stat != RPC_SUCCESS) break; if(reply.code != OK) break; pkt.pktnum++; } }
/* * Send a product to an LDM using the LDM-5 message HEREIS. * * Arguments: * proxy Pointer to the LDM proxy data-structure. * info Pointer to the data-product's metadata. * datap Pointer to the data-product's data. * Returns: * 0 Success. * LP_UNWANTED Data-product was unwanted. * LP_TIMEDOUT The RPC call timed-out. "log_start()" called. * LP_RPC_ERROR RPC error. "log_start()" called. * LP_LDM_ERROR LDM error. "log_start()" called. */ static LdmProxyStatus my_hereis_5( LdmProxy* const proxy, product* const product) { CLIENT* const clnt = proxy->clnt; LdmProxyStatus status = 0; /* success */ ldm_replyt reply; enum clnt_stat rpc_stat; memset(&reply, 0, sizeof(ldm_replyt)); rpc_stat = clnt_call(clnt, HEREIS, xdr_product, (caddr_t)product, xdr_ldm_replyt, (caddr_t)&reply, proxy->rpcTimeout); if (rpc_stat != RPC_SUCCESS) { status = getStatus(proxy, "HEREIS_5", &product->info); } else if (reply.code != OK) { if (reply.code == DONT_SEND) { status = LP_UNWANTED; } else { LOG_START1("Unexpected reply from LDM: %s", s_ldm_errt(reply.code)); status = LP_LDM_ERROR; } } return status; }
/* * Sends a data-product to an LDM using the LDM-6 COMINGSOON and BLOCKDATA * messages. * * Arguments: * proxy Pointer to the LDM proxy data-structure. * product Pointer to the data-product to be sent. * Return: * 0 Success. * LP_UNWANTED Data-product was unwanted. * LP_TIMEDOUT The RPC call timed-out. "log_start()" called. * LP_RPC_ERROR RPC error. "log_start()" called. * LP_LDM_ERROR LDM error. "log_start()" called. */ static LdmProxyStatus my_csbd_6( LdmProxy* const proxy, product* const product) { LdmProxyStatus status = 0; /* success */ CLIENT* const clnt = proxy->clnt; prod_info* const info = &product->info; const unsigned size = info->sz; comingsoon_reply_t* reply; comingsoon_args soonArg; udebug("Sending file via COMINGSOON_6/BLKDATA_6"); soonArg.infop = info; soonArg.pktsz = size; reply = comingsoon_6(&soonArg, clnt); if (NULL == reply) { status = getStatus(proxy, "COMINGSOON_6", &product->info); } else { if (DONT_SEND == *reply) { status = LP_UNWANTED; } else if (0 != *reply) { LOG_START1("Unexpected reply from LDM: %s", s_ldm_errt(*reply)); status = LP_LDM_ERROR; } else { datapkt packet; packet.signaturep = (signaturet*)&info->signature; packet.pktnum = 0; packet.data.dbuf_len = size; packet.data.dbuf_val = product->data; if (NULL == blkdata_6(&packet, clnt)) status = getStatus(proxy, "BLKDATA_6", &product->info); } } return status; }
/** * Notifies the LDM of the class of data-products that will be sent via LDM-5 * protocols. * * Arguments: * proxy Pointer to the LDM proxy data-structure. * offer Pointer to the data-product class structure which will * be offered to the LDM. * want Pointer to a pointer to a data-product class structure. * "*want" will be set the data-product class structure * that the LDM wants. The client should call * "free_prod_class(*want)" when the product-class is no * longer needed. * Returns: * 0 Success. "*clsspp" might be modified. * LP_TIMEDOUT The RPC call timed-out. "log_start()" called. * LP_RPC_ERROR RPC error. "log_start()" called. * LP_LDM_ERROR LDM error. "log_start()" called. */ static LdmProxyStatus my_hiya_5( LdmProxy* const proxy, prod_class_t* const offer, prod_class_t** const want) { static ldm_replyt reply; enum clnt_stat rpc_stat; CLIENT* const clnt = proxy->clnt; memset(&reply, 0, sizeof(ldm_replyt)); rpc_stat = clnt_call(clnt, HIYA, xdr_prod_class, (caddr_t)offer, xdr_ldm_replyt, (caddr_t)&reply, proxy->rpcTimeout); if (rpc_stat != RPC_SUCCESS) { return getStatus(proxy, "HIYA_5", NULL); } switch (reply.code) { case OK: *want = (prod_class_t*)PQ_CLASS_ALL; break; case SHUTTING_DOWN: LOG_START1("%s is shutting down", proxy->host); return LP_LDM_ERROR; case DONT_SEND: case RESTART: case REDIRECT: /* TODO */ default: LOG_START2("%s: Unexpected reply from LDM: %s", proxy->host, s_ldm_errt(reply.code)); return LP_LDM_ERROR; case RECLASS: *want = reply.ldm_replyt_u.newclssp; clss_regcomp(*want); /* N.B. we use the downstream patterns */ /* Use of "buf" added to prevent SIGSEGV on 64-bit RHEL 6 */ (void)s_prod_class(buf, sizeof(buf)-1, *want); unotice("%s: reclass: %s", proxy->host, buf); break; } return 0; }
static int my_hiya_5(CLIENT *clnt, prod_class_t **clsspp) { static ldm_replyt reply; enum clnt_stat rpc_stat; memset(&reply, 0, sizeof(ldm_replyt)); rpc_stat = clnt_call(clnt, HIYA, xdr_prod_class, (caddr_t)*clsspp, xdr_ldm_replyt, (caddr_t)&reply, timeo); if(rpc_stat != RPC_SUCCESS) { uerror("hiya %s: %s", remote, clnt_sperrno(rpc_stat)); return ECONNABORTED; /* Perhaps could be more descriptive */ } switch (reply.code) { case OK: break; case SHUTTING_DOWN: uerror("%s is shutting down", remote); return ECONNABORTED; case DONT_SEND: case RESTART: case REDIRECT: /* TODO */ default: uerror("%s: unexpected reply type %s", remote, s_ldm_errt(reply.code)); return ECONNABORTED; case RECLASS: *clsspp = reply.ldm_replyt_u.newclssp; clss_regcomp(*clsspp); /* N.B. we use the downstream patterns */ unotice("%s: reclass: %s", remote, s_prod_class(NULL, 0, *clsspp)); break; } return 0; }