From: Ronnie Sahlberg Date: Sat, 10 Mar 2012 11:50:10 +0000 (+1100) Subject: NLM add helper functions to send async calls for the NLM functions X-Git-Tag: upstream/1.9.6^2~256 X-Git-Url: https://git.piment-noir.org/?p=deb_libnfs.git;a=commitdiff_plain;h=a171d4dada771d9ca79f8ff41fabe78da6d4f863 NLM add helper functions to send async calls for the NLM functions --- diff --git a/include/libnfs-raw.h b/include/libnfs-raw.h index c78bef7..6367320 100644 --- a/include/libnfs-raw.h +++ b/include/libnfs-raw.h @@ -860,3 +860,59 @@ int rpc_nlm4_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data); struct NLM4_TESTargs; int rpc_nlm4_test_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_TESTargs *args, void *private_data); +/* + * Call NLM/LOCK + * Call the LOCK procedure for the NLM protocol + * + * Function returns + * 0 : The call was initiated. The callback will be invoked when the call completes. + * <0 : An error occured when trying to set up the call. The callback will not be invoked. + * + * When the callback is invoked, status indicates the result: + * RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon. + * data is NLM4_LOCKres + * RPC_STATUS_ERROR : An error occured when trying to contact the nlm daemon. + * data is the error string. + * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete. + * data is NULL. + */ +struct NLM4_LOCKargs; +int rpc_nlm4_lock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_LOCKargs *args, void *private_data); + +/* + * Call NLM/CANCEL + * Call the CANCEL procedure for the NLM protocol + * + * Function returns + * 0 : The call was initiated. The callback will be invoked when the call completes. + * <0 : An error occured when trying to set up the call. The callback will not be invoked. + * + * When the callback is invoked, status indicates the result: + * RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon. + * data is NLM4_CANCres + * RPC_STATUS_ERROR : An error occured when trying to contact the nlm daemon. + * data is the error string. + * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete. + * data is NULL. + */ +struct NLM4_CANCargs; +int rpc_nlm4_cancel_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_CANCargs *args, void *private_data); + +/* + * Call NLM/UNLOCK + * Call the UNLOCK procedure for the NLM protocol + * + * Function returns + * 0 : The call was initiated. The callback will be invoked when the call completes. + * <0 : An error occured when trying to set up the call. The callback will not be invoked. + * + * When the callback is invoked, status indicates the result: + * RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon. + * data is NLM4_UNLOCKres + * RPC_STATUS_ERROR : An error occured when trying to contact the nlm daemon. + * data is the error string. + * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete. + * data is NULL. + */ +struct NLM4_UNLOCKargs; +int rpc_nlm4_unlock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_UNLOCKargs *args, void *private_data); diff --git a/nlm/nlm.c b/nlm/nlm.c index 4d0bee7..b8f5b31 100644 --- a/nlm/nlm.c +++ b/nlm/nlm.c @@ -72,6 +72,81 @@ int rpc_nlm4_test_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_TESTargs return 0; } +int rpc_nlm4_lock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_LOCKargs *args, void *private_data) +{ + struct rpc_pdu *pdu; + + pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_LOCK, cb, private_data, (xdrproc_t)xdr_NLM4_LOCKres, sizeof(NLM4_LOCKres)); + if (pdu == NULL) { + rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/lock call"); + return -1; + } + + if (xdr_NLM4_LOCKargs(&pdu->xdr, args) == 0) { + rpc_set_error(rpc, "XDR error: Failed to encode NLM4_LOCKargs"); + rpc_free_pdu(rpc, pdu); + return -2; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/lock call"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + return 0; +} + +int rpc_nlm4_cancel_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_CANCargs *args, void *private_data) +{ + struct rpc_pdu *pdu; + + pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_CANCEL, cb, private_data, (xdrproc_t)xdr_NLM4_CANCres, sizeof(NLM4_CANCres)); + if (pdu == NULL) { + rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/cancel call"); + return -1; + } + + if (xdr_NLM4_CANCargs(&pdu->xdr, args) == 0) { + rpc_set_error(rpc, "XDR error: Failed to encode NLM4_CANCargs"); + rpc_free_pdu(rpc, pdu); + return -2; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/cancel call"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + return 0; +} + +int rpc_nlm4_unlock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_UNLOCKargs *args, void *private_data) +{ + struct rpc_pdu *pdu; + + pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_UNLOCK, cb, private_data, (xdrproc_t)xdr_NLM4_UNLOCKres, sizeof(NLM4_UNLOCKres)); + if (pdu == NULL) { + rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/unlock call"); + return -1; + } + + if (xdr_NLM4_UNLOCKargs(&pdu->xdr, args) == 0) { + rpc_set_error(rpc, "XDR error: Failed to encode NLM4_UNLOCKargs"); + rpc_free_pdu(rpc, pdu); + return -2; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/unlock call"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + return 0; +} + char *nlmstat4_to_str(int st) { enum nlmstat4 stat = st;