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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * Author: Nathan Rutman <nathan.rutman@sun.com>
38 /* HSM copytool example program.
39 * The copytool acts on action requests from Lustre to copy files to and from
40 * an HSM archive system.
42 * Note: under Linux, until llapi_copytool_fini is called (or the program is
43 * killed), the libcfs module will be referenced and unremovable,
44 * even after Lustre services stop.
50 #include <libcfs/libcfs.h>
51 #include <lustre/lustre_user.h>
52 #include <lustre/liblustreapi.h>
56 void handler(int signal ) {
57 psignal(signal, "exiting");
58 /* If we don't clean up upon interrupt, umount thinks there's a ref
59 * and doesn't remove us from mtab (EINPROGRESS). The lustre client
60 * does successfully unmount and the mount is actually gone, but the
61 * mtab entry remains. So this just makes mtab happier. */
62 llapi_copytool_fini(&ctdata);
66 int main(int argc, char **argv) {
68 struct option long_opts[] = {
69 {"test", no_argument, 0, 't'},
72 int archives[] = {1}; /* which archives we care about */
76 while ((c = getopt_long(argc, argv, "t", long_opts, NULL)) != -1) {
82 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
83 argv[0], argv[optind - 1]);
88 if (optind != argc - 1) {
89 fprintf(stderr, "Usage: %s <fsname>\n", argv[0]);
93 rc = llapi_copytool_start(&ctdata, argv[optind], 0,
94 ARRAY_SIZE(archives), archives);
96 fprintf(stderr, "Can't start copytool interface: %s\n",
102 return -llapi_copytool_fini(&ctdata);
104 printf("Waiting for message from kernel (pid=%d)\n", getpid());
106 signal(SIGINT, handler);
109 struct hsm_action_list *hal;
110 struct hsm_action_item *hai;
113 rc = llapi_copytool_recv(ctdata, &hal, &msgsize);
114 if (rc == -ESHUTDOWN) {
115 fprintf(stderr, "shutting down");
119 fprintf(stderr, "Message receive: %s", strerror(-rc));
123 continue; /* msg not for us */
125 printf("Copytool fs=%s archive#=%d item_count=%d\n",
126 hal->hal_fsname, hal->hal_archive_num, hal->hal_count);
129 while (++i <= hal->hal_count) {
130 printf("Item %d: action %d reclen %d\n", i,
131 hai->hai_action, hai->hai_len);
132 printf(" "DFID" gid="LPU64" cookie="LPU64"\n",
133 PFID(&hai->hai_fid), hai->hai_gid,
138 llapi_copytool_free(&hal);
141 llapi_copytool_fini(&ctdata);