Whamcloud - gitweb
LU-5051 hsm: do not reallocate hsm receive buffer 99/10299/4
authorFrank Zago <fzago@cray.com>
Thu, 22 May 2014 18:27:56 +0000 (13:27 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 30 May 2014 04:19:01 +0000 (04:19 +0000)
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>
lustre/include/lustre/lustreapi.h
lustre/utils/lhsmtool_posix.c
lustre/utils/liblustreapi_hsm.c

index bc4abda..ce17f58 100644 (file)
@@ -336,7 +336,6 @@ extern int llapi_hsm_copytool_register(struct hsm_copytool_private **priv,
 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,
index 8c8ac00..2e82fbc 100644 (file)
@@ -1815,8 +1815,6 @@ static int ct_run(void)
                        hai = hai_next(hai);
                }
 
                        hai = hai_next(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;
        }
index 47fe2ec..2ca1756 100644 (file)
@@ -66,6 +66,7 @@
 struct hsm_copytool_private {
        int                      magic;
        char                    *mnt;
 struct hsm_copytool_private {
        int                      magic;
        char                    *mnt;
+       struct kuc_hdr          *kuch;
        int                      mnt_fd;
        int                      open_by_fid_fd;
        lustre_kernelcomm        kuc;
        int                      mnt_fd;
        int                      open_by_fid_fd;
        lustre_kernelcomm        kuc;
@@ -673,6 +674,12 @@ int llapi_hsm_copytool_register(struct hsm_copytool_private **priv,
                goto out_err;
        }
 
                goto out_err;
        }
 
+       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;
@@ -743,8 +750,9 @@ out_err:
        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);
 
        free(ct);
 
 
        free(ct);
 
@@ -779,6 +787,7 @@ int llapi_hsm_copytool_unregister(struct hsm_copytool_private **priv)
        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);
+       free(ct->kuch);
        free(ct);
        *priv = NULL;
 
        free(ct);
        *priv = NULL;
 
@@ -791,6 +800,8 @@ int llapi_hsm_copytool_unregister(struct hsm_copytool_private **priv)
  * \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)
@@ -805,21 +816,19 @@ int llapi_hsm_copytool_recv(struct hsm_copytool_private *ct,
        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;
+       kuch = ct->kuch;
 
        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)
-               goto out_free;
+               goto out_err;
 
        /* 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;
-               goto out_free;
+               goto out_err;
        }
 
        if (kuch->kuc_transport != KUC_TRANSPORT_HSM ||
        }
 
        if (kuch->kuc_transport != KUC_TRANSPORT_HSM ||
@@ -828,14 +837,14 @@ int llapi_hsm_copytool_recv(struct hsm_copytool_private *ct,
                                  "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;
-               goto out_free;
+               goto out_err;
        }
 
        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;
-               goto out_free;
+               goto out_err;
        }
 
        /* Our message is a hsm_action_list. Use pointer math to skip
        }
 
        /* Our message is a hsm_action_list. Use pointer math to skip
@@ -854,27 +863,19 @@ int llapi_hsm_copytool_recv(struct hsm_copytool_private *ct,
                                  hal->hal_archive_id, ct->archives);
                rc = -EAGAIN;
 
                                  hal->hal_archive_id, ct->archives);
                rc = -EAGAIN;
 
-               goto out_free;
+               goto out_err;
        }
 
        *halh = hal;
        *msgsize = kuch->kuc_msglen - sizeof(*kuch);
        return 0;
 
        }
 
        *halh = hal;
        *msgsize = kuch->kuc_msglen - sizeof(*kuch);
        return 0;
 
-out_free:
+out_err:
        *halh = NULL;
        *msgsize = 0;
        *halh = NULL;
        *msgsize = 0;
-       free(kuch);
        return rc;
 }
 
        return rc;
 }
 
-/** 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.