Instead of allocating 1MB for every call to
llapi_hsm_copytool_recv, allocate that buffer once in
llapi_hsm_copytool_register. The application must not call
llapi_hsm_copytool_recv until it has cleared the data from
the previous call, which lhsmtool_posix already does. This
also make llapi_hsm_action_list_free unnecessary.
Signed-off-by: Patrick Farrell <paf@cray.com>
Signed-off-by: Frank Zago <fzago@cray.com>
Change-Id: Ie9e15a5cb4e3ba6d3fe23d40ee2bb47330280abf
Reviewed-on: http://review.whamcloud.com/10299
Tested-by: Jenkins
Reviewed-by: Faccini Bruno <bruno.faccini@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
extern int llapi_hsm_copytool_unregister(struct hsm_copytool_private **priv);
extern int llapi_hsm_copytool_recv(struct hsm_copytool_private *priv,
struct hsm_action_list **hal, int *msgsize);
extern int llapi_hsm_copytool_unregister(struct hsm_copytool_private **priv);
extern int llapi_hsm_copytool_recv(struct hsm_copytool_private *priv,
struct hsm_action_list **hal, int *msgsize);
-extern void llapi_hsm_action_list_free(struct hsm_action_list **hal);
extern int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp,
const struct hsm_copytool_private *ct,
const struct hsm_action_item *hai,
extern int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp,
const struct hsm_copytool_private *ct,
const struct hsm_action_item *hai,
- llapi_hsm_action_list_free(&hal);
-
if (opt.o_abort_on_error && err_major)
break;
}
if (opt.o_abort_on_error && err_major)
break;
}
struct hsm_copytool_private {
int magic;
char *mnt;
struct hsm_copytool_private {
int magic;
char *mnt;
int mnt_fd;
int open_by_fid_fd;
lustre_kernelcomm kuc;
int mnt_fd;
int open_by_fid_fd;
lustre_kernelcomm kuc;
+ ct->kuch = malloc(HAL_MAXSIZE + sizeof(*ct->kuch));
+ if (ct->kuch == NULL) {
+ rc = -ENOMEM;
+ goto out_err;
+ }
+
ct->mnt_fd = open(ct->mnt, O_RDONLY);
if (ct->mnt_fd < 0) {
rc = -errno;
ct->mnt_fd = open(ct->mnt, O_RDONLY);
if (ct->mnt_fd < 0) {
rc = -errno;
if (!(ct->open_by_fid_fd < 0))
close(ct->open_by_fid_fd);
if (!(ct->open_by_fid_fd < 0))
close(ct->open_by_fid_fd);
- if (ct->mnt != NULL)
- free(ct->mnt);
+ free(ct->mnt);
+
+ free(ct->kuch);
close(ct->open_by_fid_fd);
close(ct->mnt_fd);
free(ct->mnt);
close(ct->open_by_fid_fd);
close(ct->mnt_fd);
free(ct->mnt);
* \param msgsize Number of bytes in the message, will be set here
* \return 0 valid message received; halh and msgsize are set
* <0 error code
* \param msgsize Number of bytes in the message, will be set here
* \return 0 valid message received; halh and msgsize are set
* <0 error code
+ * Note: The application must not call llapi_hsm_copytool_recv until it has
+ * cleared the data in ct->kuch from the previous call.
*/
int llapi_hsm_copytool_recv(struct hsm_copytool_private *ct,
struct hsm_action_list **halh, int *msgsize)
*/
int llapi_hsm_copytool_recv(struct hsm_copytool_private *ct,
struct hsm_action_list **halh, int *msgsize)
if (halh == NULL || msgsize == NULL)
return -EINVAL;
if (halh == NULL || msgsize == NULL)
return -EINVAL;
- kuch = malloc(HAL_MAXSIZE + sizeof(*kuch));
- if (kuch == NULL)
- return -ENOMEM;
rc = libcfs_ukuc_msg_get(&ct->kuc, (char *)kuch,
HAL_MAXSIZE + sizeof(*kuch),
KUC_TRANSPORT_HSM);
if (rc < 0)
rc = libcfs_ukuc_msg_get(&ct->kuc, (char *)kuch,
HAL_MAXSIZE + sizeof(*kuch),
KUC_TRANSPORT_HSM);
if (rc < 0)
/* Handle generic messages */
if (kuch->kuc_transport == KUC_TRANSPORT_GENERIC &&
kuch->kuc_msgtype == KUC_MSG_SHUTDOWN) {
rc = -ESHUTDOWN;
/* Handle generic messages */
if (kuch->kuc_transport == KUC_TRANSPORT_GENERIC &&
kuch->kuc_msgtype == KUC_MSG_SHUTDOWN) {
rc = -ESHUTDOWN;
}
if (kuch->kuc_transport != KUC_TRANSPORT_HSM ||
}
if (kuch->kuc_transport != KUC_TRANSPORT_HSM ||
"Unknown HSM message type %d:%d\n",
kuch->kuc_transport, kuch->kuc_msgtype);
rc = -EPROTO;
"Unknown HSM message type %d:%d\n",
kuch->kuc_transport, kuch->kuc_msgtype);
rc = -EPROTO;
}
if (kuch->kuc_msglen < sizeof(*kuch) + sizeof(*hal)) {
llapi_err_noerrno(LLAPI_MSG_ERROR, "Short HSM message %d",
kuch->kuc_msglen);
rc = -EPROTO;
}
if (kuch->kuc_msglen < sizeof(*kuch) + sizeof(*hal)) {
llapi_err_noerrno(LLAPI_MSG_ERROR, "Short HSM message %d",
kuch->kuc_msglen);
rc = -EPROTO;
}
/* Our message is a hsm_action_list. Use pointer math to skip
}
/* Our message is a hsm_action_list. Use pointer math to skip
hal->hal_archive_id, ct->archives);
rc = -EAGAIN;
hal->hal_archive_id, ct->archives);
rc = -EAGAIN;
}
*halh = hal;
*msgsize = kuch->kuc_msglen - sizeof(*kuch);
return 0;
}
*halh = hal;
*msgsize = kuch->kuc_msglen - sizeof(*kuch);
return 0;
*halh = NULL;
*msgsize = 0;
*halh = NULL;
*msgsize = 0;
-/** Release the action list when done with it. */
-void llapi_hsm_action_list_free(struct hsm_action_list **hal)
-{
- /* Reuse the llapi_changelog_free function */
- llapi_changelog_free((struct changelog_ext_rec **)hal);
-}
-
/** Get parent path from mount point and fid.
*
* \param mnt Filesystem root path.
/** Get parent path from mount point and fid.
*
* \param mnt Filesystem root path.