4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 /* Copyright 2014, 2015 Cray Inc, all rights reserved. */
24 /* Some portions are extracted from llapi_layout_test.c */
26 /* The purpose of this test is to check some HSM functions. HSM must
27 * be enabled before running it:
28 * echo enabled > /proc/fs/lustre/mdt/lustre-MDT0000/hsm_control
31 /* All tests return 0 on success and non zero on error. The program will
32 * exit as soon a non zero error is returned. */
42 #include <lustre/lustreapi.h>
44 static char fsmountdir[PATH_MAX]; /* Lustre mountpoint */
45 static char *lustre_dir; /* Test directory inside Lustre */
47 #define ERROR(fmt, ...) \
48 fprintf(stderr, "%s: %s:%d: %s: " fmt "\n", \
49 program_invocation_short_name, __FILE__, __LINE__, \
50 __func__, ## __VA_ARGS__);
52 #define DIE(fmt, ...) \
54 ERROR(fmt, ## __VA_ARGS__); \
58 #define ASSERTF(cond, fmt, ...) \
61 DIE("assertion '%s' failed: "fmt, \
62 #cond, ## __VA_ARGS__); \
65 #define PERFORM(testfn) \
67 fprintf(stderr, "Starting test " #testfn " at %llu\n", \
68 (unsigned long long)time(NULL)); \
70 fprintf(stderr, "Finishing test " #testfn " at %llu\n", \
71 (unsigned long long)time(NULL)); \
74 /* Register and unregister 2000 times. Ensures there is no fd leak
75 * since there is usually 1024 fd per process. */
80 struct hsm_copytool_private *ctdata;
82 for (i = 0; i < 2000; i++) {
83 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
86 "llapi_hsm_copytool_register failed: %s, loop=%d",
89 rc = llapi_hsm_copytool_unregister(&ctdata);
91 "llapi_hsm_copytool_unregister failed: %s, loop=%d",
102 struct hsm_copytool_private *ctdata1;
103 struct hsm_copytool_private *ctdata2;
105 rc = llapi_hsm_copytool_register(&ctdata1, fsmountdir, 0, NULL, 0);
106 ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
109 rc = llapi_hsm_copytool_register(&ctdata2, fsmountdir, 0, NULL, 0);
110 ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
113 rc = llapi_hsm_copytool_unregister(&ctdata2);
114 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
117 rc = llapi_hsm_copytool_unregister(&ctdata1);
118 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
124 /* Bad parameters to llapi_hsm_copytool_register(). */
128 struct hsm_copytool_private *ctdata;
131 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 1, NULL, 0);
132 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
135 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 33, NULL, 0);
136 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
139 memset(archives, 1, sizeof(archives));
140 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 34, archives, 0);
141 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
145 /* BUG? Should that fail or not? */
146 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, -1, NULL, 0);
147 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
151 memset(archives, -1, sizeof(archives));
152 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 1, archives, 0);
153 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
156 rc = llapi_hsm_copytool_register(&ctdata, "/tmp", 0, NULL, 0);
157 ASSERTF(rc == -ENOENT, "llapi_hsm_copytool_register error: %s",
163 /* Bad parameters to llapi_hsm_copytool_unregister(). */
168 rc = llapi_hsm_copytool_unregister(NULL);
169 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_unregister error: %s",
175 /* Test llapi_hsm_copytool_recv in non blocking mode */
180 struct hsm_copytool_private *ctdata;
181 struct hsm_action_list *hal;
184 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
185 0, NULL, O_NONBLOCK);
186 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
189 /* Hopefully there is nothing lingering */
190 for (i = 0; i < 1000; i++) {
191 rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
192 ASSERTF(rc == -EWOULDBLOCK, "llapi_hsm_copytool_recv error: %s",
196 rc = llapi_hsm_copytool_unregister(&ctdata);
197 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
203 /* Test llapi_hsm_copytool_recv with bogus parameters */
206 struct hsm_copytool_private *ctdata;
207 struct hsm_action_list *hal;
211 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 0, NULL, 0);
212 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
215 rc = llapi_hsm_copytool_recv(NULL, &hal, &msgsize);
216 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_recv error: %s",
219 rc = llapi_hsm_copytool_recv(ctdata, NULL, &msgsize);
220 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_recv error: %s",
223 rc = llapi_hsm_copytool_recv(ctdata, &hal, NULL);
224 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_recv error: %s",
227 rc = llapi_hsm_copytool_recv(ctdata, NULL, NULL);
228 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_recv error: %s",
231 rc = llapi_hsm_copytool_unregister(&ctdata);
232 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
238 /* Test polling (without actual traffic) */
242 struct hsm_copytool_private *ctdata;
243 struct hsm_action_list *hal;
246 struct pollfd fds[1];
248 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
249 0, NULL, O_NONBLOCK);
250 ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
253 fd = llapi_hsm_copytool_get_fd(ctdata);
254 ASSERTF(fd >= 0, "llapi_hsm_copytool_get_fd failed: %s",
257 /* Ensure it's read-only */
258 rc = write(fd, &rc, 1);
259 ASSERTF(rc == -1 && errno == EBADF, "write error: %d, %s",
260 rc, strerror(errno));
262 rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
263 ASSERTF(rc == -EWOULDBLOCK, "llapi_hsm_copytool_recv error: %s",
267 fds[0].events = POLLIN;
268 rc = poll(fds, 1, 10);
269 ASSERTF(rc == 0, "poll failed: %d, %s",
270 rc, strerror(errno)); /* no event */
272 rc = llapi_hsm_copytool_unregister(&ctdata);
273 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
279 /* Create the testfile of a given length. It returns a valid file
281 static char testfile[PATH_MAX];
282 static int create_testfile(size_t length)
287 rc = snprintf(testfile, sizeof(testfile), "%s/hsm_check_test",
289 ASSERTF((rc > 0 && rc < sizeof(testfile)), "invalid name for testfile");
291 /* Remove old test file, if any. */
294 /* Use truncate so we can create a file (almost) as big as we
295 * want, while taking 0 bytes of data. */
296 fd = creat(testfile, S_IRWXU);
297 ASSERTF(fd >= 0, "create failed for '%s': %s",
298 testfile, strerror(errno));
300 rc = ftruncate(fd, length);
301 ASSERTF(rc == 0, "ftruncate failed for '%s': %s",
302 testfile, strerror(errno));
307 /* Test llapi_hsm_state_get. */
310 struct hsm_user_state hus;
314 fd = create_testfile(100);
316 /* With fd variant */
317 rc = llapi_hsm_state_get_fd(fd, &hus);
318 ASSERTF(rc == 0, "llapi_hsm_state_get_fd failed: %s", strerror(-rc));
319 ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states);
321 rc = llapi_hsm_state_get_fd(fd, NULL);
322 ASSERTF(rc == -EFAULT, "llapi_hsm_state_get_fd error: %s",
326 ASSERTF(rc == 0, "close failed: %s", strerror(errno));
329 rc = llapi_hsm_state_get(testfile, &hus);
330 ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc));
331 ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states);
333 rc = llapi_hsm_state_get(testfile, NULL);
334 ASSERTF(rc == -EFAULT, "llapi_hsm_state_get error: %s",
337 memset(&hus, 0xaa, sizeof(hus));
338 rc = llapi_hsm_state_get(testfile, &hus);
339 ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc));
340 ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states);
341 ASSERTF(hus.hus_archive_id == 0, "archive_id=%u", hus.hus_archive_id);
342 ASSERTF(hus.hus_in_progress_state == 0, "hus_in_progress_state=%u",
343 hus.hus_in_progress_state);
344 ASSERTF(hus.hus_in_progress_action == 0, "hus_in_progress_action=%u",
345 hus.hus_in_progress_action);
348 /* Test llapi_hsm_state_set. */
354 struct hsm_user_state hus;
356 fd = create_testfile(100);
358 rc = llapi_hsm_state_set_fd(fd, 0, 0, 0);
359 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
362 for (i = 0; i <= 32; i++) {
363 rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, i);
364 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s",
367 rc = llapi_hsm_state_get_fd(fd, &hus);
368 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s",
370 ASSERTF(hus.hus_states == HS_EXISTS, "state=%u",
372 ASSERTF(hus.hus_archive_id == i, "archive_id=%u, i=%d",
373 hus.hus_archive_id, i);
376 /* Bugs following. This should not succeed. Builds the following file:
378 * $ ../utils/lfs hsm_state /mnt/lustre/hsm_check_test
380 * /mnt/lustre/hsm_check_test: (0x8008007d) released exists
381 * archived never_release never_archive lost_from_hsm,
385 /* Invalid archive numbers */
386 rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, 33);
387 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
389 rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, 151);
390 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
392 rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, -1789);
393 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
395 /* Setable + Unsettable flags */
396 rc = llapi_hsm_state_set_fd(fd, HS_DIRTY, 0, 0);
397 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
399 rc = llapi_hsm_state_set_fd(fd, 0, HS_DIRTY, 0);
400 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
402 rc = llapi_hsm_state_set_fd(fd, HS_ARCHIVED, 0, 0);
403 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
405 rc = llapi_hsm_state_set_fd(fd, HS_RELEASED, 0, 0);
406 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
408 rc = llapi_hsm_state_set_fd(fd, HS_NORELEASE, 0, 0);
409 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
411 rc = llapi_hsm_state_set_fd(fd, HS_NOARCHIVE, 0, 0);
412 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
414 rc = llapi_hsm_state_set_fd(fd, HS_LOST, 0, 0);
415 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
417 /* Bogus flags for good measure. */
418 rc = llapi_hsm_state_set_fd(fd, 0x00080000, 0, 0);
419 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
421 rc = llapi_hsm_state_set_fd(fd, 0x80000000, 0, 0);
422 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
427 /* Test llapi_hsm_current_action */
432 struct hsm_current_action hca;
434 /* No fd equivalent, so close it. */
435 fd = create_testfile(100);
438 rc = llapi_hsm_current_action(testfile, &hca);
439 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s", strerror(-rc));
440 ASSERTF(hca.hca_state, "hca_state=%u", hca.hca_state);
441 ASSERTF(hca.hca_action, "hca_state=%u", hca.hca_action);
443 rc = llapi_hsm_current_action(testfile, NULL);
444 ASSERTF(rc == -EFAULT, "llapi_hsm_current_action failed: %s",
448 /* Helper to simulate archiving a file. No actual data movement
450 void helper_archiving(void (*progress)
451 (struct hsm_copyaction_private *hcp, size_t length),
456 struct hsm_copytool_private *ctdata;
457 struct hsm_user_request *hur;
458 struct hsm_action_list *hal;
459 struct hsm_action_item *hai;
461 struct hsm_copyaction_private *hcp;
462 struct hsm_user_state hus;
464 fd = create_testfile(length);
466 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
468 ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
471 /* Create and send the archive request. */
472 hur = llapi_hsm_user_request_alloc(1, 0);
473 ASSERTF(hur != NULL, "llapi_hsm_user_request_alloc returned NULL");
475 hur->hur_request.hr_action = HUA_ARCHIVE;
476 hur->hur_request.hr_archive_id = 1;
477 hur->hur_request.hr_flags = 0;
478 hur->hur_request.hr_itemcount = 1;
479 hur->hur_request.hr_data_len = 0;
480 hur->hur_user_item[0].hui_extent.length = -1;
482 rc = llapi_fd2fid(fd, &hur->hur_user_item[0].hui_fid);
483 ASSERTF(rc == 0, "llapi_fd2fid failed: %s", strerror(-rc));
487 rc = llapi_hsm_request(testfile, hur);
488 ASSERTF(rc == 0, "llapi_hsm_request failed: %s", strerror(-rc));
492 /* Read the request */
493 rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
494 ASSERTF(rc == 0, "llapi_hsm_copytool_recv failed: %s", strerror(-rc));
495 ASSERTF(hal->hal_count == 1, "hal_count=%d", hal->hal_count);
497 hai = hai_first(hal);
498 ASSERTF(hai != NULL, "hai_first returned NULL");
499 ASSERTF(hai->hai_action == HSMA_ARCHIVE,
500 "hai_action=%d", hai->hai_action);
502 /* "Begin" archiving */
504 rc = llapi_hsm_action_begin(&hcp, ctdata, hai, -1, 0, false);
505 ASSERTF(rc == 0, "llapi_hsm_action_begin failed: %s", strerror(-rc));
506 ASSERTF(hcp != NULL, "hcp is NULL");
509 progress(hcp, length);
512 rc = llapi_hsm_action_end(&hcp, &hai->hai_extent, 0, 0);
513 ASSERTF(rc == 0, "llapi_hsm_action_end failed: %s", strerror(-rc));
514 ASSERTF(hcp == NULL, "hcp is NULL");
516 /* Close HSM client */
517 rc = llapi_hsm_copytool_unregister(&ctdata);
518 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
522 rc = llapi_hsm_state_get(testfile, &hus);
523 ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc));
524 ASSERTF(hus.hus_states == (HS_EXISTS | HS_ARCHIVED),
525 "state=%u", hus.hus_states);
528 /* Simple archive. No progress. */
531 const size_t length = 100;
533 helper_archiving(NULL, length);
536 /* Archive, with a report every byte. */
537 static void test101_progress(struct hsm_copyaction_private *hcp, size_t length)
541 struct hsm_extent he;
542 struct hsm_current_action hca;
544 /* Report progress. 1 byte at a time :) */
545 for (i = 0; i < length; i++) {
548 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
549 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
553 rc = llapi_hsm_current_action(testfile, &hca);
554 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
556 ASSERTF(hca.hca_state == HPS_RUNNING,
557 "hca_state=%u", hca.hca_state);
558 ASSERTF(hca.hca_action == HUA_ARCHIVE,
559 "hca_state=%u", hca.hca_action);
560 ASSERTF(hca.hca_location.length == length,
561 "length=%llu", (unsigned long long)hca.hca_location.length);
566 const size_t length = 1000;
568 helper_archiving(test101_progress, length);
571 /* Archive, with a report every byte, backwards. */
572 static void test102_progress(struct hsm_copyaction_private *hcp, size_t length)
576 struct hsm_extent he;
577 struct hsm_current_action hca;
579 /* Report progress. 1 byte at a time :) */
580 for (i = length-1; i >= 0; i--) {
583 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
584 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
588 rc = llapi_hsm_current_action(testfile, &hca);
589 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
591 ASSERTF(hca.hca_state == HPS_RUNNING,
592 "hca_state=%u", hca.hca_state);
593 ASSERTF(hca.hca_action == HUA_ARCHIVE,
594 "hca_state=%u", hca.hca_action);
595 ASSERTF(hca.hca_location.length == length,
596 "length=%llu", (unsigned long long)hca.hca_location.length);
601 const size_t length = 1000;
603 helper_archiving(test102_progress, length);
606 /* Archive, with a single report. */
607 static void test103_progress(struct hsm_copyaction_private *hcp, size_t length)
610 struct hsm_extent he;
611 struct hsm_current_action hca;
615 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
616 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
619 rc = llapi_hsm_current_action(testfile, &hca);
620 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
622 ASSERTF(hca.hca_state == HPS_RUNNING,
623 "hca_state=%u", hca.hca_state);
624 ASSERTF(hca.hca_action == HUA_ARCHIVE,
625 "hca_state=%u", hca.hca_action);
626 ASSERTF(hca.hca_location.length == length,
627 "length=%llu", (unsigned long long)hca.hca_location.length);
632 const size_t length = 1000;
634 helper_archiving(test103_progress, length);
637 /* Archive, with 2 reports. */
638 static void test104_progress(struct hsm_copyaction_private *hcp, size_t length)
641 struct hsm_extent he;
642 struct hsm_current_action hca;
645 he.length = length/2;
646 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
647 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
650 he.offset = length/2;
651 he.length = length/2;
652 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
653 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
656 rc = llapi_hsm_current_action(testfile, &hca);
657 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
659 ASSERTF(hca.hca_state == HPS_RUNNING,
660 "hca_state=%u", hca.hca_state);
661 ASSERTF(hca.hca_action == HUA_ARCHIVE,
662 "hca_state=%u", hca.hca_action);
663 ASSERTF(hca.hca_location.length == length,
664 "length=%llu", (unsigned long long)hca.hca_location.length);
669 const size_t length = 1000;
671 helper_archiving(test104_progress, length);
674 /* Archive, with 1 bogus report. */
675 static void test105_progress(struct hsm_copyaction_private *hcp, size_t length)
678 struct hsm_extent he;
679 struct hsm_current_action hca;
681 he.offset = 2*length;
682 he.length = 10*length;
683 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
684 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
687 rc = llapi_hsm_current_action(testfile, &hca);
688 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
690 ASSERTF(hca.hca_state == HPS_RUNNING,
691 "hca_state=%u", hca.hca_state);
692 ASSERTF(hca.hca_action == HUA_ARCHIVE,
693 "hca_state=%u", hca.hca_action);
695 /* BUG - offset should be 2*length, or length should
697 ASSERTF(hca.hca_location.length == 10*length,
698 "length=%llu", (unsigned long long)hca.hca_location.length);
703 const size_t length = 1000;
705 helper_archiving(test105_progress, length);
708 /* Archive, with 1 empty report. */
709 static void test106_progress(struct hsm_copyaction_private *hcp, size_t length)
712 struct hsm_extent he;
713 struct hsm_current_action hca;
717 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
718 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
721 rc = llapi_hsm_current_action(testfile, &hca);
722 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
724 ASSERTF(hca.hca_state == HPS_RUNNING,
725 "hca_state=%u", hca.hca_state);
726 ASSERTF(hca.hca_action == HUA_ARCHIVE,
727 "hca_state=%u", hca.hca_action);
728 ASSERTF(hca.hca_location.length == 0,
729 "length=%llu", (unsigned long long)hca.hca_location.length);
734 const size_t length = 1000;
736 helper_archiving(test106_progress, length);
739 /* Archive, with 1 bogus report. */
740 static void test107_progress(struct hsm_copyaction_private *hcp, size_t length)
743 struct hsm_extent he;
744 struct hsm_current_action hca;
748 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
749 ASSERTF(rc == -EINVAL, "llapi_hsm_action_progress error: %s",
752 rc = llapi_hsm_current_action(testfile, &hca);
753 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
755 ASSERTF(hca.hca_state == HPS_RUNNING,
756 "hca_state=%u", hca.hca_state);
757 ASSERTF(hca.hca_action == HUA_ARCHIVE,
758 "hca_state=%u", hca.hca_action);
759 ASSERTF(hca.hca_location.length == 0,
760 "length=%llu", (unsigned long long)hca.hca_location.length);
765 const size_t length = 1000;
767 helper_archiving(test107_progress, length);
770 /* Archive, with same report, many times. */
771 static void test108_progress(struct hsm_copyaction_private *hcp, size_t length)
774 struct hsm_extent he;
776 struct hsm_current_action hca;
778 for (i = 0; i < 1000; i++) {
781 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
782 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
786 rc = llapi_hsm_current_action(testfile, &hca);
787 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
789 ASSERTF(hca.hca_state == HPS_RUNNING,
790 "hca_state=%u", hca.hca_state);
791 ASSERTF(hca.hca_action == HUA_ARCHIVE,
792 "hca_state=%u", hca.hca_action);
793 ASSERTF(hca.hca_location.length == length,
794 "length=%llu", (unsigned long long)hca.hca_location.length);
799 const size_t length = 1000;
801 helper_archiving(test108_progress, length);
804 /* Archive, 1 report, with large number. */
805 static void test109_progress(struct hsm_copyaction_private *hcp, size_t length)
808 struct hsm_extent he;
809 struct hsm_current_action hca;
812 he.length = 0xffffffffffffffffULL;
813 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
814 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
817 rc = llapi_hsm_current_action(testfile, &hca);
818 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
820 ASSERTF(hca.hca_state == HPS_RUNNING,
821 "hca_state=%u", hca.hca_state);
822 ASSERTF(hca.hca_action == HUA_ARCHIVE,
823 "hca_state=%u", hca.hca_action);
824 ASSERTF(hca.hca_location.length == 0xffffffffffffffffULL,
825 "length=%llu", (unsigned long long)hca.hca_location.length);
830 const size_t length = 1000;
832 helper_archiving(test109_progress, length);
835 /* Archive, with 10 reports, checking progress. */
836 static void test110_progress(struct hsm_copyaction_private *hcp, size_t length)
840 struct hsm_extent he;
841 struct hsm_current_action hca;
843 for (i = 0; i < 10; i++) {
844 he.offset = i*length/10;
845 he.length = length/10;
846 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
847 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
850 rc = llapi_hsm_current_action(testfile, &hca);
851 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
853 ASSERTF(hca.hca_state == HPS_RUNNING,
854 "hca_state=%u", hca.hca_state);
855 ASSERTF(hca.hca_action == HUA_ARCHIVE,
856 "hca_state=%u", hca.hca_action);
857 ASSERTF(hca.hca_location.length == (i+1)*length/10,
859 i, (unsigned long long)hca.hca_location.length);
865 const size_t length = 1000;
867 helper_archiving(test110_progress, length);
870 /* Archive, with 10 reports in reverse order, checking progress. */
871 static void test111_progress(struct hsm_copyaction_private *hcp, size_t length)
875 struct hsm_extent he;
876 struct hsm_current_action hca;
878 for (i = 0; i < 10; i++) {
879 he.offset = (9-i)*length/10;
880 he.length = length/10;
881 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
882 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
885 rc = llapi_hsm_current_action(testfile, &hca);
886 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
888 ASSERTF(hca.hca_state == HPS_RUNNING,
889 "hca_state=%u", hca.hca_state);
890 ASSERTF(hca.hca_action == HUA_ARCHIVE,
891 "hca_state=%u", hca.hca_action);
892 ASSERTF(hca.hca_location.length == (i+1)*length/10,
894 i, (unsigned long long)hca.hca_location.length);
900 const size_t length = 1000;
902 helper_archiving(test111_progress, length);
905 /* Archive, with 10 reports, and duplicating them, checking
907 static void test112_progress(struct hsm_copyaction_private *hcp, size_t length)
911 struct hsm_extent he;
912 struct hsm_current_action hca;
914 for (i = 0; i < 10; i++) {
915 he.offset = i*length/10;
916 he.length = length/10;
917 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
918 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
921 rc = llapi_hsm_current_action(testfile, &hca);
922 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
924 ASSERTF(hca.hca_state == HPS_RUNNING,
925 "hca_state=%u", hca.hca_state);
926 ASSERTF(hca.hca_action == HUA_ARCHIVE,
927 "hca_state=%u", hca.hca_action);
928 ASSERTF(hca.hca_location.length == (i+1)*length/10,
930 i, (unsigned long long)hca.hca_location.length);
933 for (i = 0; i < 10; i++) {
934 he.offset = i*length/10;
935 he.length = length/10;
936 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
937 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
940 rc = llapi_hsm_current_action(testfile, &hca);
941 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
943 ASSERTF(hca.hca_state == HPS_RUNNING,
944 "hca_state=%u", hca.hca_state);
945 ASSERTF(hca.hca_action == HUA_ARCHIVE,
946 "hca_state=%u", hca.hca_action);
947 ASSERTF(hca.hca_location.length == length,
949 i, (unsigned long long)hca.hca_location.length);
955 const size_t length = 1000;
957 helper_archiving(test112_progress, length);
960 static void usage(char *prog)
962 fprintf(stderr, "Usage: %s [-d lustre_dir]\n", prog);
966 static void process_args(int argc, char *argv[])
970 while ((c = getopt(argc, argv, "d:")) != -1) {
977 fprintf(stderr, "Unknown option '%c'\n", optopt);
984 int main(int argc, char *argv[])
989 process_args(argc, argv);
990 if (lustre_dir == NULL)
991 lustre_dir = "/mnt/lustre";
993 rc = llapi_search_mounts(lustre_dir, 0, fsmountdir, fsname);
995 fprintf(stderr, "Error: %s: not a Lustre filesystem\n",
1000 /* Play nice with Lustre test scripts. Non-line buffered output
1001 * stream under I/O redirection may appear incorrectly. */
1002 setvbuf(stdout, NULL, _IOLBF, 0);
1028 return EXIT_SUCCESS;