/* Test llapi_hsm_state_get. */ void test50(void) { struct hsm_user_state hus; int rc; int fd; fd = create_testfile(100); /* With fd variant */ rc = llapi_hsm_state_get_fd(fd, &hus); ASSERTF(rc == 0, "llapi_hsm_state_get_fd failed: %s", strerror(-rc)); ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states); rc = llapi_hsm_state_get_fd(fd, NULL); ASSERTF(rc == -EFAULT, "llapi_hsm_state_get_fd error: %s", strerror(-rc)); rc = close(fd); ASSERTF(rc == 0, "close failed: %s", strerror(errno)); /* Without fd */ rc = llapi_hsm_state_get(testfile, &hus); ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc)); ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states); rc = llapi_hsm_state_get(testfile, NULL); ASSERTF(rc == -EFAULT, "llapi_hsm_state_get error: %s", strerror(-rc)); memset(&hus, 0xaa, sizeof(hus)); rc = llapi_hsm_state_get(testfile, &hus); ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc)); ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states); ASSERTF(hus.hus_archive_id == 0, "archive_id=%u", hus.hus_archive_id); ASSERTF(hus.hus_in_progress_state == 0, "hus_in_progress_state=%u", hus.hus_in_progress_state); ASSERTF(hus.hus_in_progress_action == 0, "hus_in_progress_action=%u", hus.hus_in_progress_action); }
/** get Lustre status and convert it to internal Robinhood status */ int LustreHSM_GetStatus( const char *path, file_status_t * p_status, int *no_release, int *no_archive ) { int rc; struct hsm_user_state file_status; /* initialize outputs */ *p_status = STATUS_NEW; *no_release = FALSE; *no_archive = FALSE; /* get status */ rc = llapi_hsm_state_get( path, &file_status ); if ( (rc !=0) && (rc != -ENOENT) && (rc != -ESTALE) ) DisplayLog( LVL_DEBUG, "HSMFlags", "llapi_hsm_state_get(%s)=%d", path, rc ); if (rc != 0) return rc; /* user flags */ if ( file_status.hus_states & HS_NORELEASE ) *no_release = TRUE; if ( file_status.hus_states & HS_NOARCHIVE ) *no_archive = TRUE; /* clear them */ file_status.hus_states &= ~ (HS_NORELEASE|HS_NOARCHIVE); /* pending actions */ if ( file_status.hus_in_progress_action == HUA_ARCHIVE ) { *p_status = STATUS_ARCHIVE_RUNNING; return 0; } else if ( file_status.hus_in_progress_action == HUA_RESTORE ) { *p_status = STATUS_RESTORE_RUNNING; return 0; } else if ( file_status.hus_in_progress_action == HUA_RELEASE ) { DisplayLog( LVL_DEBUG, "HSMFlags", "Entry %s is being released", path ); } else if ( file_status.hus_in_progress_action == HUA_REMOVE ) { DisplayLog( LVL_DEBUG, "HSMFlags", "Entry %s is being removed", path ); } /* status flags */ if ( ( file_status.hus_states & HSM_FLAGS_MASK ) == 0 ) { *p_status = STATUS_NEW; } else if ( file_status.hus_states & HS_DIRTY ) { *p_status = STATUS_MODIFIED; } else if ( file_status.hus_states & HS_ARCHIVED ) { /* "and not dirty" is ensured by the previous test */ if ( file_status.hus_states & HS_RELEASED ) { /* file is archived in HSM, and released from Lustre */ *p_status = STATUS_RELEASED; } else { /* file is up-to-date in HSM, and not released in Lustre */ *p_status = STATUS_SYNCHRO; } } else if ( file_status.hus_states & HS_EXISTS ) { /* new file, not yet archived successfully */ *p_status = STATUS_MODIFIED; } else { /* In this case: file has non null status and !HS_DIRTY and !HS_ARCHIVED * and !HS_EXISTS. * Maybe is it HS_RELEASED without being HS_ARCHIVED (empty file?) * or maybe is it LOST??? */ DisplayLog( LVL_MAJOR, "HSMFlags", "Entry %s has inconsistent or" " unknown HSM flags %#X", path, file_status.hus_states ); return EINVAL; } /** @TODO what if special LOST flag is set??? */ return 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); }