Exemplo n.º 1
0
/** Trigger a HSM action */
int LustreHSM_Action( enum hsm_user_action action, const entry_id_t * p_id,
                      const char * hints, unsigned int archive_id )
{
    struct hsm_user_request * req;
    int data_len = 0;
    int rc;
    char * mpath;

    if ( hints != NULL )
        data_len = strlen(hints)+1;

    req = llapi_hsm_user_request_alloc(1, data_len);

    if (!req)
    {
        rc = -errno;
        DisplayLog( LVL_CRIT, "HSMAction", "Cannot create HSM request: %s",
            strerror(-rc) );
        return rc;
    }

    req->hur_request.hr_action = action;
    req->hur_request.hr_archive_id = archive_id;

    req->hur_user_item[0].hui_fid = *p_id;
    req->hur_user_item[0].hui_extent.offset = 0 ;
    /* XXX for now, always transfer entire file */
    req->hur_user_item[0].hui_extent.length = -1LL;

    req->hur_request.hr_itemcount = 1;

    if ( hints != NULL )
    {
        req->hur_request.hr_data_len = data_len;
        memcpy(hur_data(req), hints, data_len);
    }
    else
    {
        req->hur_request.hr_data_len = 0;
    }

    /* make tmp copy as llapi_hsm_request arg is not const */
    mpath = strdup(get_mount_point(NULL));
    rc = llapi_hsm_request(mpath, req);
    free(mpath);
    free(req);

    if (rc)
        DisplayLog( LVL_CRIT, "HSMAction", "ERROR performing HSM request(%s,"
                    " root=%s, fid="DFID"): %s",
                    hsm_user_action2name(action), mpath, PFID(p_id),
                    strerror(-rc) );
    return rc;

}
Exemplo n.º 2
0
/* Helper to simulate archiving a file. No actual data movement
 * happens. */
void helper_archiving(void (*progress)
		      (struct hsm_copyaction_private *hcp, size_t length),
		      const size_t length)
{
	int rc;
	int fd;
	struct hsm_copytool_private *ctdata;
	struct hsm_user_request	*hur;
	struct hsm_action_list	*hal;
	struct hsm_action_item	*hai;
	int			 msgsize;
	struct hsm_copyaction_private *hcp;
	struct hsm_user_state hus;

	fd = create_testfile(length);

	rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
					 0, NULL, 0);
	ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
		strerror(-rc));

	/* Create and send the archive request. */
	hur = llapi_hsm_user_request_alloc(1, 0);
	ASSERTF(hur != NULL, "llapi_hsm_user_request_alloc returned NULL");

	hur->hur_request.hr_action = HUA_ARCHIVE;
	hur->hur_request.hr_archive_id = 1;
	hur->hur_request.hr_flags = 0;
	hur->hur_request.hr_itemcount = 1;
	hur->hur_request.hr_data_len = 0;
	hur->hur_user_item[0].hui_extent.offset = 0;
	hur->hur_user_item[0].hui_extent.length = -1;

	rc = llapi_fd2fid(fd, &hur->hur_user_item[0].hui_fid);
	ASSERTF(rc == 0, "llapi_fd2fid failed: %s", strerror(-rc));

	close(fd);

	rc = llapi_hsm_request(testfile, hur);
	ASSERTF(rc == 0, "llapi_hsm_request failed: %s", strerror(-rc));

	free(hur);

	/* Read the request */
	rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
	ASSERTF(rc == 0, "llapi_hsm_copytool_recv failed: %s", strerror(-rc));
	ASSERTF(hal->hal_count == 1, "hal_count=%d", hal->hal_count);

	hai = hai_first(hal);
	ASSERTF(hai != NULL, "hai_first returned NULL");
	ASSERTF(hai->hai_action == HSMA_ARCHIVE,
		"hai_action=%d", hai->hai_action);

	/* "Begin" archiving */
	hcp = NULL;
	rc = llapi_hsm_action_begin(&hcp, ctdata, hai, -1, 0, false);
	ASSERTF(rc == 0, "llapi_hsm_action_begin failed: %s", strerror(-rc));
	ASSERTF(hcp != NULL, "hcp is NULL");

	if (progress)
		progress(hcp, length);

	/* Done archiving */
	rc = llapi_hsm_action_end(&hcp, &hai->hai_extent, 0, 0);
	ASSERTF(rc == 0, "llapi_hsm_action_end failed: %s", strerror(-rc));
	ASSERTF(hcp == NULL, "hcp is NULL");

	/* Close HSM client */
	rc = llapi_hsm_copytool_unregister(&ctdata);
	ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
		strerror(-rc));

	/* Final check */
	rc = llapi_hsm_state_get(testfile, &hus);
	ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc));
	ASSERTF(hus.hus_states == (HS_EXISTS | HS_ARCHIVED),
		"state=%u", hus.hus_states);
}