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
24 * Copyright 2014, 2015 Cray Inc, all rights reserved.
26 * Copyright (c) 2015, Intel Corporation.
28 /* Some portions are extracted from llapi_layout_test.c */
30 /* The purpose of this test is to check some HSM functions. HSM must
31 * be enabled before running it:
32 * lctl set_param mdt.$FSNAME-MDT0000.hsm_control=enabled
35 /* All tests return 0 on success and non zero on error. The program will
36 * exit as soon a non zero error is returned. */
46 #include <lustre/lustreapi.h>
48 static char fsmountdir[PATH_MAX]; /* Lustre mountpoint */
49 static char *lustre_dir; /* Test directory inside Lustre */
50 static bool is_bitmap;
52 #define ERROR(fmt, ...) \
53 fprintf(stderr, "%s: %s:%d: %s: " fmt "\n", \
54 program_invocation_short_name, __FILE__, __LINE__, \
55 __func__, ## __VA_ARGS__);
57 #define DIE(fmt, ...) \
59 ERROR(fmt, ## __VA_ARGS__); \
63 #define ASSERTF(cond, fmt, ...) \
66 DIE("assertion '%s' failed: "fmt, \
67 #cond, ## __VA_ARGS__); \
70 #define PERFORM(testfn) \
72 fprintf(stderr, "Starting test " #testfn " at %llu\n", \
73 (unsigned long long)time(NULL)); \
75 fprintf(stderr, "Finishing test " #testfn " at %llu\n", \
76 (unsigned long long)time(NULL)); \
79 /* Register and unregister 2000 times. Ensures there is no fd leak
80 * since there is usually 1024 fd per process. */
85 struct hsm_copytool_private *ctdata;
87 for (i = 0; i < 2000; i++) {
88 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
91 "llapi_hsm_copytool_register failed: %s, loop=%d",
94 rc = llapi_hsm_copytool_unregister(&ctdata);
96 "llapi_hsm_copytool_unregister failed: %s, loop=%d",
107 struct hsm_copytool_private *ctdata1;
108 struct hsm_copytool_private *ctdata2;
110 rc = llapi_hsm_copytool_register(&ctdata1, fsmountdir, 0, NULL, 0);
111 ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
114 rc = llapi_hsm_copytool_register(&ctdata2, fsmountdir, 0, NULL, 0);
115 ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
118 rc = llapi_hsm_copytool_unregister(&ctdata2);
119 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
122 rc = llapi_hsm_copytool_unregister(&ctdata1);
123 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
129 /* Bad parameters to llapi_hsm_copytool_register(). */
133 struct hsm_copytool_private *ctdata;
135 int count = sizeof(archives) / sizeof(*archives);
137 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 1, NULL, 0);
138 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
141 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, count, NULL, 0);
142 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
148 for (i = 0; i < count; i++)
150 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
152 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
157 /* BUG? Should that fail or not? */
158 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, -1, NULL, 0);
159 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
163 memset(archives, -1, sizeof(archives));
164 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 1, archives, 0);
165 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_register error: %s",
168 rc = llapi_hsm_copytool_register(&ctdata, "/tmp", 0, NULL, 0);
169 ASSERTF(rc == -ENOENT, "llapi_hsm_copytool_register error: %s",
175 /* Bad parameters to llapi_hsm_copytool_unregister(). */
180 rc = llapi_hsm_copytool_unregister(NULL);
181 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_unregister error: %s",
187 /* Test llapi_hsm_copytool_recv in non blocking mode */
192 struct hsm_copytool_private *ctdata;
193 struct hsm_action_list *hal;
196 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
197 0, NULL, O_NONBLOCK);
198 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
201 /* Hopefully there is nothing lingering */
202 for (i = 0; i < 1000; i++) {
203 rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
204 ASSERTF(rc == -EAGAIN, "llapi_hsm_copytool_recv error: %s",
208 rc = llapi_hsm_copytool_unregister(&ctdata);
209 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
215 /* Test llapi_hsm_copytool_recv with bogus parameters */
218 struct hsm_copytool_private *ctdata;
219 struct hsm_action_list *hal;
223 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 0, NULL, 0);
224 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
227 rc = llapi_hsm_copytool_recv(NULL, &hal, &msgsize);
228 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_recv error: %s",
231 rc = llapi_hsm_copytool_recv(ctdata, NULL, &msgsize);
232 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_recv error: %s",
235 rc = llapi_hsm_copytool_recv(ctdata, &hal, NULL);
236 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_recv error: %s",
239 rc = llapi_hsm_copytool_recv(ctdata, NULL, NULL);
240 ASSERTF(rc == -EINVAL, "llapi_hsm_copytool_recv error: %s",
243 rc = llapi_hsm_copytool_unregister(&ctdata);
244 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
250 /* Test polling (without actual traffic) */
254 struct hsm_copytool_private *ctdata;
255 struct hsm_action_list *hal;
258 struct pollfd fds[1];
260 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
261 0, NULL, O_NONBLOCK);
262 ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
265 fd = llapi_hsm_copytool_get_fd(ctdata);
266 ASSERTF(fd >= 0, "llapi_hsm_copytool_get_fd failed: %s",
269 /* Ensure it's read-only */
270 rc = write(fd, &rc, 1);
271 ASSERTF(rc == -1 && errno == EBADF, "write error: %d, %s",
272 rc, strerror(errno));
274 rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
275 ASSERTF(rc == -EAGAIN, "llapi_hsm_copytool_recv error: %s",
279 fds[0].events = POLLIN;
280 rc = poll(fds, 1, 10);
281 ASSERTF(rc == 0, "poll failed: %d, %s",
282 rc, strerror(errno)); /* no event */
284 rc = llapi_hsm_copytool_unregister(&ctdata);
285 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
291 /* Create the testfile of a given length. It returns a valid file
293 static char testfile[PATH_MAX];
294 static int create_testfile(size_t length)
299 rc = snprintf(testfile, sizeof(testfile), "%s/hsm_check_test",
301 ASSERTF((rc > 0 && rc < sizeof(testfile)), "invalid name for testfile");
303 /* Remove old test file, if any. */
306 /* Use truncate so we can create a file (almost) as big as we
307 * want, while taking 0 bytes of data. */
308 fd = creat(testfile, S_IRWXU);
309 ASSERTF(fd >= 0, "create failed for '%s': %s",
310 testfile, strerror(errno));
312 rc = ftruncate(fd, length);
313 ASSERTF(rc == 0, "ftruncate failed for '%s': %s",
314 testfile, strerror(errno));
319 /* Test llapi_hsm_state_get. */
322 struct hsm_user_state hus;
326 fd = create_testfile(100);
328 /* With fd variant */
329 rc = llapi_hsm_state_get_fd(fd, &hus);
330 ASSERTF(rc == 0, "llapi_hsm_state_get_fd failed: %s", strerror(-rc));
331 ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states);
333 rc = llapi_hsm_state_get_fd(fd, NULL);
334 ASSERTF(rc == -EFAULT, "llapi_hsm_state_get_fd error: %s",
338 ASSERTF(rc == 0, "close failed: %s", strerror(errno));
341 rc = llapi_hsm_state_get(testfile, &hus);
342 ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc));
343 ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states);
345 rc = llapi_hsm_state_get(testfile, NULL);
346 ASSERTF(rc == -EFAULT, "llapi_hsm_state_get error: %s",
349 memset(&hus, 0xaa, sizeof(hus));
350 rc = llapi_hsm_state_get(testfile, &hus);
351 ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc));
352 ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states);
353 ASSERTF(hus.hus_archive_id == 0, "archive_id=%u", hus.hus_archive_id);
354 ASSERTF(hus.hus_in_progress_state == 0, "hus_in_progress_state=%u",
355 hus.hus_in_progress_state);
356 ASSERTF(hus.hus_in_progress_action == 0, "hus_in_progress_action=%u",
357 hus.hus_in_progress_action);
360 /* Test llapi_hsm_state_set. */
367 struct hsm_user_state hus;
369 fd = create_testfile(100);
371 rc = llapi_hsm_state_set_fd(fd, 0, 0, 0);
372 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
379 for (i = 0; i <= test_count; i++) {
380 rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, i);
381 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s",
384 rc = llapi_hsm_state_get_fd(fd, &hus);
385 ASSERTF(rc == 0, "llapi_hsm_state_get_fd failed: %s",
387 ASSERTF(hus.hus_states == HS_EXISTS, "state=%u",
389 ASSERTF(hus.hus_archive_id == i, "archive_id=%u, i=%d",
390 hus.hus_archive_id, i);
394 /* Invalid archive numbers */
395 rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, 33);
396 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s",
399 rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, 151);
400 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s",
403 rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, -1789);
404 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s",
408 /* Settable flags, with respect of the HSM file state transition rules:
409 * DIRTY without EXISTS: no dirty if no archive was created
410 * DIRTY and RELEASED: a dirty file could not be released
411 * RELEASED without ARCHIVED: do not release a non-archived file
412 * LOST without ARCHIVED: cannot lost a non-archived file.
414 rc = llapi_hsm_state_set_fd(fd, HS_DIRTY, 0, 0);
415 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
417 rc = llapi_hsm_state_set_fd(fd, 0, HS_EXISTS, 0);
418 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
421 rc = llapi_hsm_state_set_fd(fd, 0, HS_DIRTY, 0);
422 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
424 rc = llapi_hsm_state_set_fd(fd, 0, HS_EXISTS, 0);
425 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
427 rc = llapi_hsm_state_set_fd(fd, HS_DIRTY, 0, 0);
428 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
431 rc = llapi_hsm_state_set_fd(fd, HS_RELEASED, 0, 0);
432 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
435 rc = llapi_hsm_state_set_fd(fd, HS_LOST, 0, 0);
436 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
439 rc = llapi_hsm_state_set_fd(fd, HS_ARCHIVED, 0, 0);
440 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
442 rc = llapi_hsm_state_set_fd(fd, HS_RELEASED, 0, 0);
443 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
445 rc = llapi_hsm_state_set_fd(fd, HS_LOST, 0, 0);
446 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
448 rc = llapi_hsm_state_set_fd(fd, HS_DIRTY|HS_EXISTS, 0, 0);
449 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
452 rc = llapi_hsm_state_set_fd(fd, 0, HS_RELEASED, 0);
453 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
455 rc = llapi_hsm_state_set_fd(fd, HS_DIRTY|HS_EXISTS, 0, 0);
456 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
458 rc = llapi_hsm_state_set_fd(fd, 0, HS_ARCHIVED, 0);
459 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s",
462 rc = llapi_hsm_state_set_fd(fd, 0, HS_LOST, 0);
463 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
465 rc = llapi_hsm_state_set_fd(fd, 0, HS_ARCHIVED, 0);
466 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
468 rc = llapi_hsm_state_set_fd(fd, HS_NORELEASE, 0, 0);
469 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
471 rc = llapi_hsm_state_set_fd(fd, 0, HS_NORELEASE, 0);
472 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
474 rc = llapi_hsm_state_set_fd(fd, HS_NOARCHIVE, 0, 0);
475 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
477 rc = llapi_hsm_state_set_fd(fd, 0, HS_NOARCHIVE, 0);
478 ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc));
480 /* Bogus flags for good measure. */
481 rc = llapi_hsm_state_set_fd(fd, 0x00080000, 0, 0);
482 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc));
484 rc = llapi_hsm_state_set_fd(fd, 0x80000000, 0, 0);
485 ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc));
490 /* Test llapi_hsm_current_action */
495 struct hsm_current_action hca;
497 /* No fd equivalent, so close it. */
498 fd = create_testfile(100);
501 rc = llapi_hsm_current_action(testfile, &hca);
502 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s", strerror(-rc));
503 ASSERTF(hca.hca_state, "hca_state=%u", hca.hca_state);
504 ASSERTF(hca.hca_action, "hca_state=%u", hca.hca_action);
506 rc = llapi_hsm_current_action(testfile, NULL);
507 ASSERTF(rc == -EFAULT, "llapi_hsm_current_action failed: %s",
511 /* Helper to simulate archiving a file. No actual data movement
513 void helper_archiving(void (*progress)
514 (struct hsm_copyaction_private *hcp, size_t length),
519 struct hsm_copytool_private *ctdata;
520 struct hsm_user_request *hur;
521 struct hsm_action_list *hal;
522 struct hsm_action_item *hai;
524 struct hsm_copyaction_private *hcp;
525 struct hsm_user_state hus;
527 fd = create_testfile(length);
529 rc = llapi_hsm_copytool_register(&ctdata, fsmountdir,
531 ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s",
534 /* Create and send the archive request. */
535 hur = llapi_hsm_user_request_alloc(1, 0);
536 ASSERTF(hur != NULL, "llapi_hsm_user_request_alloc returned NULL");
538 hur->hur_request.hr_action = HUA_ARCHIVE;
539 hur->hur_request.hr_archive_id = 1;
540 hur->hur_request.hr_flags = 0;
541 hur->hur_request.hr_itemcount = 1;
542 hur->hur_request.hr_data_len = 0;
543 hur->hur_user_item[0].hui_extent.offset = 0;
544 hur->hur_user_item[0].hui_extent.length = -1;
546 rc = llapi_fd2fid(fd, &hur->hur_user_item[0].hui_fid);
547 ASSERTF(rc == 0, "llapi_fd2fid failed: %s", strerror(-rc));
551 rc = llapi_hsm_request(testfile, hur);
552 ASSERTF(rc == 0, "llapi_hsm_request failed: %s", strerror(-rc));
556 /* Read the request */
557 rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
558 ASSERTF(rc == 0, "llapi_hsm_copytool_recv failed: %s", strerror(-rc));
559 ASSERTF(hal->hal_count == 1, "hal_count=%d", hal->hal_count);
561 hai = hai_first(hal);
562 ASSERTF(hai != NULL, "hai_first returned NULL");
563 ASSERTF(hai->hai_action == HSMA_ARCHIVE,
564 "hai_action=%d", hai->hai_action);
566 /* "Begin" archiving */
568 rc = llapi_hsm_action_begin(&hcp, ctdata, hai, -1, 0, false);
569 ASSERTF(rc == 0, "llapi_hsm_action_begin failed: %s", strerror(-rc));
570 ASSERTF(hcp != NULL, "hcp is NULL");
573 progress(hcp, length);
576 rc = llapi_hsm_action_end(&hcp, &hai->hai_extent, 0, 0);
577 ASSERTF(rc == 0, "llapi_hsm_action_end failed: %s", strerror(-rc));
578 ASSERTF(hcp == NULL, "hcp is NULL");
580 /* Close HSM client */
581 rc = llapi_hsm_copytool_unregister(&ctdata);
582 ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s",
586 rc = llapi_hsm_state_get(testfile, &hus);
587 ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc));
588 ASSERTF(hus.hus_states == (HS_EXISTS | HS_ARCHIVED),
589 "state=%u", hus.hus_states);
592 /* Simple archive. No progress. */
595 const size_t length = 100;
597 helper_archiving(NULL, length);
600 /* Archive, with a report every byte. */
601 static void test101_progress(struct hsm_copyaction_private *hcp, size_t length)
605 struct hsm_extent he;
606 struct hsm_current_action hca;
608 /* Report progress. 1 byte at a time :) */
609 for (i = 0; i < length; i++) {
612 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
613 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
617 rc = llapi_hsm_current_action(testfile, &hca);
618 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
620 ASSERTF(hca.hca_state == HPS_RUNNING,
621 "hca_state=%u", hca.hca_state);
622 ASSERTF(hca.hca_action == HUA_ARCHIVE,
623 "hca_state=%u", hca.hca_action);
624 ASSERTF(hca.hca_location.length == length,
625 "length=%llu", (unsigned long long)hca.hca_location.length);
630 const size_t length = 1000;
632 helper_archiving(test101_progress, length);
635 /* Archive, with a report every byte, backwards. */
636 static void test102_progress(struct hsm_copyaction_private *hcp, size_t length)
640 struct hsm_extent he;
641 struct hsm_current_action hca;
643 /* Report progress. 1 byte at a time :) */
644 for (i = length-1; i >= 0; i--) {
647 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
648 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
652 rc = llapi_hsm_current_action(testfile, &hca);
653 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
655 ASSERTF(hca.hca_state == HPS_RUNNING,
656 "hca_state=%u", hca.hca_state);
657 ASSERTF(hca.hca_action == HUA_ARCHIVE,
658 "hca_state=%u", hca.hca_action);
659 ASSERTF(hca.hca_location.length == length,
660 "length=%llu", (unsigned long long)hca.hca_location.length);
665 const size_t length = 1000;
667 helper_archiving(test102_progress, length);
670 /* Archive, with a single report. */
671 static void test103_progress(struct hsm_copyaction_private *hcp, size_t length)
674 struct hsm_extent he;
675 struct hsm_current_action hca;
679 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
680 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
683 rc = llapi_hsm_current_action(testfile, &hca);
684 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
686 ASSERTF(hca.hca_state == HPS_RUNNING,
687 "hca_state=%u", hca.hca_state);
688 ASSERTF(hca.hca_action == HUA_ARCHIVE,
689 "hca_state=%u", hca.hca_action);
690 ASSERTF(hca.hca_location.length == length,
691 "length=%llu", (unsigned long long)hca.hca_location.length);
696 const size_t length = 1000;
698 helper_archiving(test103_progress, length);
701 /* Archive, with 2 reports. */
702 static void test104_progress(struct hsm_copyaction_private *hcp, size_t length)
705 struct hsm_extent he;
706 struct hsm_current_action hca;
709 he.length = length/2;
710 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
711 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
714 he.offset = length/2;
715 he.length = length/2;
716 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
717 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
720 rc = llapi_hsm_current_action(testfile, &hca);
721 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
723 ASSERTF(hca.hca_state == HPS_RUNNING,
724 "hca_state=%u", hca.hca_state);
725 ASSERTF(hca.hca_action == HUA_ARCHIVE,
726 "hca_state=%u", hca.hca_action);
727 ASSERTF(hca.hca_location.length == length,
728 "length=%llu", (unsigned long long)hca.hca_location.length);
733 const size_t length = 1000;
735 helper_archiving(test104_progress, length);
738 /* Archive, with 1 bogus report. */
739 static void test105_progress(struct hsm_copyaction_private *hcp, size_t length)
742 struct hsm_extent he;
743 struct hsm_current_action hca;
745 he.offset = 2*length;
746 he.length = 10*length;
747 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
748 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
751 rc = llapi_hsm_current_action(testfile, &hca);
752 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
754 ASSERTF(hca.hca_state == HPS_RUNNING,
755 "hca_state=%u", hca.hca_state);
756 ASSERTF(hca.hca_action == HUA_ARCHIVE,
757 "hca_state=%u", hca.hca_action);
759 /* BUG - offset should be 2*length, or length should
761 ASSERTF(hca.hca_location.length == 10*length,
762 "length=%llu", (unsigned long long)hca.hca_location.length);
767 const size_t length = 1000;
769 helper_archiving(test105_progress, length);
772 /* Archive, with 1 empty report. */
773 static void test106_progress(struct hsm_copyaction_private *hcp, size_t length)
776 struct hsm_extent he;
777 struct hsm_current_action hca;
781 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
782 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
785 rc = llapi_hsm_current_action(testfile, &hca);
786 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
788 ASSERTF(hca.hca_state == HPS_RUNNING,
789 "hca_state=%u", hca.hca_state);
790 ASSERTF(hca.hca_action == HUA_ARCHIVE,
791 "hca_state=%u", hca.hca_action);
792 ASSERTF(hca.hca_location.length == 0,
793 "length=%llu", (unsigned long long)hca.hca_location.length);
798 const size_t length = 1000;
800 helper_archiving(test106_progress, length);
803 /* Archive, with 1 bogus report. */
804 static void test107_progress(struct hsm_copyaction_private *hcp, size_t length)
807 struct hsm_extent he;
808 struct hsm_current_action hca;
812 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
813 ASSERTF(rc == -EINVAL, "llapi_hsm_action_progress error: %s",
816 rc = llapi_hsm_current_action(testfile, &hca);
817 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
819 ASSERTF(hca.hca_state == HPS_RUNNING,
820 "hca_state=%u", hca.hca_state);
821 ASSERTF(hca.hca_action == HUA_ARCHIVE,
822 "hca_state=%u", hca.hca_action);
823 ASSERTF(hca.hca_location.length == 0,
824 "length=%llu", (unsigned long long)hca.hca_location.length);
829 const size_t length = 1000;
831 helper_archiving(test107_progress, length);
834 /* Archive, with same report, many times. */
835 static void test108_progress(struct hsm_copyaction_private *hcp, size_t length)
838 struct hsm_extent he;
840 struct hsm_current_action hca;
842 for (i = 0; i < 1000; i++) {
845 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
846 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 == length,
858 "length=%llu", (unsigned long long)hca.hca_location.length);
863 const size_t length = 1000;
865 helper_archiving(test108_progress, length);
868 /* Archive, 1 report, with large number. */
869 static void test109_progress(struct hsm_copyaction_private *hcp, size_t length)
872 struct hsm_extent he;
873 struct hsm_current_action hca;
876 he.length = 0xffffffffffffffffULL;
877 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
878 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
881 rc = llapi_hsm_current_action(testfile, &hca);
882 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
884 ASSERTF(hca.hca_state == HPS_RUNNING,
885 "hca_state=%u", hca.hca_state);
886 ASSERTF(hca.hca_action == HUA_ARCHIVE,
887 "hca_state=%u", hca.hca_action);
888 ASSERTF(hca.hca_location.length == 0xffffffffffffffffULL,
889 "length=%llu", (unsigned long long)hca.hca_location.length);
894 const size_t length = 1000;
896 helper_archiving(test109_progress, length);
899 /* Archive, with 10 reports, checking progress. */
900 static void test110_progress(struct hsm_copyaction_private *hcp, size_t length)
904 struct hsm_extent he;
905 struct hsm_current_action hca;
907 for (i = 0; i < 10; i++) {
908 he.offset = i*length/10;
909 he.length = length/10;
910 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
911 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
914 rc = llapi_hsm_current_action(testfile, &hca);
915 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
917 ASSERTF(hca.hca_state == HPS_RUNNING,
918 "hca_state=%u", hca.hca_state);
919 ASSERTF(hca.hca_action == HUA_ARCHIVE,
920 "hca_state=%u", hca.hca_action);
921 ASSERTF(hca.hca_location.length == (i+1)*length/10,
923 i, (unsigned long long)hca.hca_location.length);
929 const size_t length = 1000;
931 helper_archiving(test110_progress, length);
934 /* Archive, with 10 reports in reverse order, checking progress. */
935 static void test111_progress(struct hsm_copyaction_private *hcp, size_t length)
939 struct hsm_extent he;
940 struct hsm_current_action hca;
942 for (i = 0; i < 10; i++) {
943 he.offset = (9-i)*length/10;
944 he.length = length/10;
945 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
946 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
949 rc = llapi_hsm_current_action(testfile, &hca);
950 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
952 ASSERTF(hca.hca_state == HPS_RUNNING,
953 "hca_state=%u", hca.hca_state);
954 ASSERTF(hca.hca_action == HUA_ARCHIVE,
955 "hca_state=%u", hca.hca_action);
956 ASSERTF(hca.hca_location.length == (i+1)*length/10,
958 i, (unsigned long long)hca.hca_location.length);
964 const size_t length = 1000;
966 helper_archiving(test111_progress, length);
969 /* Archive, with 10 reports, and duplicating them, checking
971 static void test112_progress(struct hsm_copyaction_private *hcp, size_t length)
975 struct hsm_extent he;
976 struct hsm_current_action hca;
978 for (i = 0; i < 10; i++) {
979 he.offset = i*length/10;
980 he.length = length/10;
981 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
982 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
985 rc = llapi_hsm_current_action(testfile, &hca);
986 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
988 ASSERTF(hca.hca_state == HPS_RUNNING,
989 "hca_state=%u", hca.hca_state);
990 ASSERTF(hca.hca_action == HUA_ARCHIVE,
991 "hca_state=%u", hca.hca_action);
992 ASSERTF(hca.hca_location.length == (i+1)*length/10,
994 i, (unsigned long long)hca.hca_location.length);
997 for (i = 0; i < 10; i++) {
998 he.offset = i*length/10;
999 he.length = length/10;
1000 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
1001 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
1004 rc = llapi_hsm_current_action(testfile, &hca);
1005 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
1007 ASSERTF(hca.hca_state == HPS_RUNNING,
1008 "hca_state=%u", hca.hca_state);
1009 ASSERTF(hca.hca_action == HUA_ARCHIVE,
1010 "hca_state=%u", hca.hca_action);
1011 ASSERTF(hca.hca_location.length == length,
1012 "i=%d, length=%llu",
1013 i, (unsigned long long)hca.hca_location.length);
1019 const size_t length = 1000;
1021 helper_archiving(test112_progress, length);
1024 /* Archive, with 9 reports, each covering 20%, so many overlap. */
1025 static void test113_progress(struct hsm_copyaction_private *hcp, size_t length)
1029 struct hsm_extent he;
1030 struct hsm_current_action hca;
1032 for (i = 0; i < 9; i++) {
1033 he.offset = i*length/10;
1034 he.length = 2*length/10;
1035 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
1036 ASSERTF(rc == 0, "llapi_hsm_action_progress failed: %s",
1039 rc = llapi_hsm_current_action(testfile, &hca);
1040 ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s",
1042 ASSERTF(hca.hca_state == HPS_RUNNING,
1043 "hca_state=%u", hca.hca_state);
1044 ASSERTF(hca.hca_action == HUA_ARCHIVE,
1045 "hca_state=%u", hca.hca_action);
1046 ASSERTF(hca.hca_location.length == (i+2)*length/10,
1047 "i=%d, length=%llu",
1048 i, (unsigned long long)hca.hca_location.length);
1054 const size_t length = 1000;
1056 helper_archiving(test113_progress, length);
1059 static void usage(char *prog)
1061 fprintf(stderr, "Usage: %s [-d lustre_dir]\n", prog);
1065 static void process_args(int argc, char *argv[])
1069 while ((c = getopt(argc, argv, "bd:")) != -1) {
1072 lustre_dir = optarg;
1079 fprintf(stderr, "Unknown option '%c'\n", optopt);
1086 int main(int argc, char *argv[])
1091 process_args(argc, argv);
1092 if (lustre_dir == NULL)
1093 lustre_dir = "/mnt/lustre";
1095 rc = llapi_search_mounts(lustre_dir, 0, fsmountdir, fsname);
1097 fprintf(stderr, "Error: %s: not a Lustre filesystem\n",
1099 return EXIT_FAILURE;
1102 /* Play nice with Lustre test scripts. Non-line buffered output
1103 * stream under I/O redirection may appear incorrectly. */
1104 setvbuf(stdout, NULL, _IOLBF, 0);
1131 return EXIT_SUCCESS;