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_hsm_copytool_fini is called (or the program is
43 * killed), the libcfs module will be referenced and unremovable,
44 * even after Lustre services stop.
52 #include <sys/types.h>
55 #include <libcfs/libcfs.h>
56 #include <lustre/lustreapi.h>
58 struct hsm_copytool_private *ctdata;
60 void handler(int signal ) {
61 psignal(signal, "exiting");
62 /* If we don't clean up upon interrupt, umount thinks there's a ref
63 * and doesn't remove us from mtab (EINPROGRESS). The lustre client
64 * does successfully unmount and the mount is actually gone, but the
65 * mtab entry remains. So this just makes mtab happier. */
66 llapi_hsm_copytool_fini(&ctdata);
70 int main(int argc, char **argv) {
72 struct option long_opts[] = {
73 {"test", no_argument, 0, 't'},
76 int archives[] = {1}; /* which archives we care about */
80 while ((c = getopt_long(argc, argv, "t", long_opts, NULL)) != -1) {
86 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
87 argv[0], argv[optind - 1]);
92 if (optind != argc - 1) {
93 fprintf(stderr, "Usage: %s <fsname>\n", argv[0]);
97 rc = llapi_hsm_copytool_start(&ctdata, argv[optind], 0,
98 ARRAY_SIZE(archives), archives);
100 fprintf(stderr, "Can't start copytool interface: %s\n",
106 return -llapi_hsm_copytool_fini(&ctdata);
108 printf("Waiting for message from kernel (pid=%d)\n", getpid());
110 signal(SIGINT, handler);
113 struct hsm_action_list *hal;
114 struct hsm_action_item *hai;
117 rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
118 if (rc == -ESHUTDOWN) {
119 fprintf(stderr, "shutting down");
123 fprintf(stderr, "Message receive: %s", strerror(-rc));
127 continue; /* msg not for us */
129 printf("Copytool fs=%s archive#=%d item_count=%d\n",
130 hal->hal_fsname, hal->hal_archive_id, hal->hal_count);
133 while (++i <= hal->hal_count) {
134 printf("Item %d: action %d reclen %d\n", i,
135 hai->hai_action, hai->hai_len);
136 printf(" "DFID" gid="LPU64" cookie="LPU64"\n",
137 PFID(&hai->hai_fid), hai->hai_gid,
142 llapi_hsm_copytool_free(&hal);
145 llapi_hsm_copytool_fini(&ctdata);